YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
24
namespace yb {
25
namespace client {
26
27
DEFINE_bool(yb_system_namespace_readonly, true, "Set system keyspace read-only.");
28
29
using std::string;
30
31
50.9k
void YBTableName::SetIntoTableIdentifierPB(master::TableIdentifierPB* id) const {
32
50.9k
  SetIntoNamespaceIdentifierPB(id->mutable_namespace_());
33
50.9k
  id->set_table_name(table_name());
34
50.9k
  if (!table_id_.empty()) {
35
445
    id->set_table_id(table_id_);
36
50.4k
  } else {
37
50.4k
    id->clear_table_id();
38
50.4k
  }
39
50.9k
}
40
41
152k
void YBTableName::GetFromTableIdentifierPB(const master::TableIdentifierPB& id) {
42
152k
  GetFromNamespaceIdentifierPB(id.namespace_());
43
152k
  table_name_ = id.table_name();
44
152k
  if (id.has_table_id()) {
45
152k
    table_id_ = id.table_id();
46
18.4E
  } else {
47
18.4E
    table_id_.clear();
48
18.4E
  }
49
152k
}
50
51
53.7k
void YBTableName::SetIntoNamespaceIdentifierPB(master::NamespaceIdentifierPB* id) const {
52
53.7k
  if (namespace_type_ != YQL_DATABASE_UNKNOWN) {
53
53.3k
    id->set_database_type(namespace_type_);
54
53.3k
  }
55
53.7k
  if (!namespace_id_.empty()) {
56
1.74k
    id->set_id(namespace_id_);
57
1.74k
    if (!has_namespace()) {
58
0
      return;
59
0
    }
60
52.0k
  } else {
61
52.0k
    id->clear_id();
62
52.0k
  }
63
53.7k
  id->set_name(resolved_namespace_name());
64
53.7k
}
65
66
152k
void YBTableName::GetFromNamespaceIdentifierPB(const master::NamespaceIdentifierPB& id) {
67
152k
  namespace_type_ = id.has_database_type() ? id.database_type() : YQL_DATABASE_UNKNOWN;
68
152k
  namespace_name_ = id.name();
69
152k
  if (id.has_id()) {
70
151k
    namespace_id_ = id.id();
71
433
  } else {
72
433
    namespace_id_.clear();
73
433
  }
74
152k
  check_db_type();
75
152k
}
76
77
5.02M
bool YBTableName::is_system() const {
78
5.02M
  return master::IsSystemNamespace(resolved_namespace_name());
79
5.02M
}
80
81
1.30M
void YBTableName::check_db_type() {
82
1.30M
  if (namespace_name_ == common::kRedisKeyspaceName) {
83
209k
    namespace_type_ = YQL_DATABASE_REDIS;
84
209k
  }
85
1.30M
}
86
87
0
bool YBTableName::is_redis_table() const {
88
0
  return is_redis_namespace() && (table_name_.find(common::kRedisTableName) == 0);
89
0
}
90
91
911k
size_t hash_value(const YBTableName& table_name) {
92
911k
  size_t seed = 0;
93
94
911k
  boost::hash_combine(seed, table_name.namespace_name());
95
911k
  boost::hash_combine(seed, table_name.table_name());
96
97
911k
  return seed;
98
911k
}
99
100
5.07M
const std::string& YBTableName::resolved_namespace_name() const {
101
5.07M
  DCHECK(has_namespace()); // At the moment the namespace name must NEVER be empty.
102
                           // It must be set by set_namespace_name() before this call.
103
                           // If the check fails - you forgot to call set_namespace_name().
104
5.07M
  return namespace_name_;
105
5.07M
}
106
107
3.98k
void YBTableName::set_namespace_id(const std::string& namespace_id) {
108
3.98k
  DCHECK(!namespace_id.empty());
109
3.98k
  namespace_id_ = namespace_id;
110
3.98k
}
111
112
1.15M
void YBTableName::set_namespace_name(const std::string& namespace_name) {
113
1.15M
  DCHECK(!namespace_name.empty());
114
1.15M
  namespace_name_ = namespace_name;
115
1.15M
  check_db_type();
116
1.15M
}
117
118
1.14M
void YBTableName::set_table_name(const std::string& table_name) {
119
1.14M
  DCHECK(!table_name.empty());
120
1.14M
  table_name_ = table_name;
121
1.14M
}
122
123
2.54k
void YBTableName::set_table_id(const std::string& table_id) {
124
2.54k
  DCHECK(!table_id.empty());
125
2.54k
  table_id_ = table_id;
126
2.54k
}
127
128
2.53k
void YBTableName::set_pgschema_name(const std::string& pgschema_name) {
129
2.53k
  pgschema_name_ = pgschema_name;
130
2.53k
}
131
132
} // namespace client
133
} // namespace yb