YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/client/yb_table_name.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/client/yb_table_name.h"
15
16
#include <boost/functional/hash.hpp>
17
18
#include <glog/logging.h>
19
20
#include "yb/common/redis_constants_common.h"
21
22
#include "yb/master/master_util.h"
23
#include "yb/util/flag_tags.h"
24
25
namespace yb {
26
namespace client {
27
28
DEFINE_bool(yb_system_namespace_readonly, true, "Set system keyspace read-only.");
29
TAG_FLAG(yb_system_namespace_readonly, runtime);
30
31
using std::string;
32
33
54.1k
void YBTableName::SetIntoTableIdentifierPB(master::TableIdentifierPB* id) const {
34
54.1k
  SetIntoNamespaceIdentifierPB(id->mutable_namespace_());
35
54.1k
  id->set_table_name(table_name());
36
54.1k
  if (!table_id_.empty()) {
37
1.16k
    id->set_table_id(table_id_);
38
52.9k
  } else {
39
52.9k
    id->clear_table_id();
40
52.9k
  }
41
54.1k
}
42
43
333k
void YBTableName::GetFromTableIdentifierPB(const master::TableIdentifierPB& id) {
44
333k
  GetFromNamespaceIdentifierPB(id.namespace_());
45
333k
  table_name_ = id.table_name();
46
333k
  if (id.has_table_id()) {
47
333k
    table_id_ = id.table_id();
48
333k
  } else {
49
243
    table_id_.clear();
50
243
  }
51
333k
}
52
53
61.0k
void YBTableName::SetIntoNamespaceIdentifierPB(master::NamespaceIdentifierPB* id) const {
54
61.0k
  if (namespace_type_ != YQL_DATABASE_UNKNOWN) {
55
60.0k
    id->set_database_type(namespace_type_);
56
60.0k
  }
57
61.0k
  if (!namespace_id_.empty()) {
58
5.64k
    id->set_id(namespace_id_);
59
5.64k
    if (!has_namespace()) {
60
0
      return;
61
0
    }
62
55.3k
  } else {
63
55.3k
    id->clear_id();
64
55.3k
  }
65
61.0k
  id->set_name(resolved_namespace_name());
66
61.0k
}
67
68
333k
void YBTableName::GetFromNamespaceIdentifierPB(const master::NamespaceIdentifierPB& id) {
69
333k
  namespace_type_ = id.has_database_type() ? 
id.database_type()8
:
YQL_DATABASE_UNKNOWN333k
;
70
333k
  namespace_name_ = id.name();
71
333k
  if (id.has_id()) {
72
332k
    namespace_id_ = id.id();
73
332k
  } else {
74
1.55k
    namespace_id_.clear();
75
1.55k
  }
76
333k
  check_db_type();
77
333k
}
78
79
9.88M
bool YBTableName::is_system() const {
80
9.88M
  return master::IsSystemNamespace(resolved_namespace_name());
81
9.88M
}
82
83
1.75M
void YBTableName::check_db_type() {
84
1.75M
  if (namespace_name_ == common::kRedisKeyspaceName) {
85
417k
    namespace_type_ = YQL_DATABASE_REDIS;
86
417k
  }
87
1.75M
}
88
89
0
bool YBTableName::is_redis_table() const {
90
0
  return is_redis_namespace() && (table_name_.find(common::kRedisTableName) == 0);
91
0
}
92
93
1.13M
size_t hash_value(const YBTableName& table_name) {
94
1.13M
  size_t seed = 0;
95
96
1.13M
  boost::hash_combine(seed, table_name.namespace_name());
97
1.13M
  boost::hash_combine(seed, table_name.table_name());
98
99
1.13M
  return seed;
100
1.13M
}
101
102
9.94M
const std::string& YBTableName::resolved_namespace_name() const {
103
9.94M
  DCHECK(has_namespace()); // At the moment the namespace name must NEVER be empty.
104
                           // It must be set by set_namespace_name() before this call.
105
                           // If the check fails - you forgot to call set_namespace_name().
106
9.94M
  return namespace_name_;
107
9.94M
}
108
109
32.9k
void YBTableName::set_namespace_id(const std::string& namespace_id) {
110
32.9k
  DCHECK(!namespace_id.empty());
111
32.9k
  namespace_id_ = namespace_id;
112
32.9k
}
113
114
1.41M
void YBTableName::set_namespace_name(const std::string& namespace_name) {
115
1.41M
  DCHECK(!namespace_name.empty());
116
1.41M
  namespace_name_ = namespace_name;
117
1.41M
  check_db_type();
118
1.41M
}
119
120
1.40M
void YBTableName::set_table_name(const std::string& table_name) {
121
1.40M
  DCHECK(!table_name.empty());
122
1.40M
  table_name_ = table_name;
123
1.40M
}
124
125
27.7k
void YBTableName::set_table_id(const std::string& table_id) {
126
27.7k
  DCHECK(!table_id.empty());
127
27.7k
  table_id_ = table_id;
128
27.7k
}
129
130
27.7k
void YBTableName::set_pgschema_name(const std::string& pgschema_name) {
131
27.7k
  pgschema_name_ = pgschema_name;
132
27.7k
}
133
134
} // namespace client
135
} // namespace yb