Skip to content

Commit

Permalink
[yugabyte#14958] YSQL: Simplify PgLibPqTest::DBCatalogVersion unit test
Browse files Browse the repository at this point in the history
Summary: Simplify PgLibPqTest::DBCatalogVersion unit test

Test Plan:
```
./yb_build.sh --gtest_filter PgLibPqTest.DBCatalogVersion
```

Reviewers: jason, myang

Reviewed By: myang

Subscribers: yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D21029
  • Loading branch information
d-uspenskiy committed Nov 11, 2022
1 parent 0ba7e8f commit 9d900b3
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 233 deletions.
10 changes: 6 additions & 4 deletions src/yb/tserver/tablet_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,10 @@ void TabletServer::SetYsqlDBCatalogVersions(
existing_entry.last_breaking_version = new_breaking_version;
row_updated = true;
shm_index = existing_entry.shm_index;
CHECK(shm_index >= 0 && shm_index < TServerSharedData::kMaxNumDbCatalogVersions)
<< "Invalid shm_index: " << shm_index;
CHECK(
shm_index >= 0 &&
shm_index < static_cast<int>(TServerSharedData::kMaxNumDbCatalogVersions))
<< "Invalid shm_index: " << shm_index;
} else if (new_version < existing_entry.current_version) {
LOG(DFATAL) << "Ignoring ysql db " << db_oid
<< " catalog version update: new version too old. "
Expand All @@ -691,7 +693,7 @@ void TabletServer::SetYsqlDBCatalogVersions(
} else {
auto& inserted_entry = it.first->second;
// Allocate a new free slot in shared memory array db_catalog_versions_ for db_oid.
int count = 0;
uint32_t count = 0;
while (count < TServerSharedData::kMaxNumDbCatalogVersions) {
if (!(*ysql_db_catalog_version_index_used_)[search_starting_index_]) {
// Found a free slot, remember it.
Expand Down Expand Up @@ -738,7 +740,7 @@ void TabletServer::SetYsqlDBCatalogVersions(
if (db_oid_set.count(db_oid) == 0) {
auto shm_index = it->second.shm_index;
CHECK(shm_index >= 0 &&
shm_index < TServerSharedData::kMaxNumDbCatalogVersions) << shm_index;
shm_index < static_cast<int>(TServerSharedData::kMaxNumDbCatalogVersions)) << shm_index;
// Mark the corresponding shared memory array db_catalog_versions_ slot as free.
(*ysql_db_catalog_version_index_used_)[shm_index] = false;
it = ysql_db_catalog_version_map_.erase(it);
Expand Down
2 changes: 1 addition & 1 deletion src/yb/tserver/tserver_shared_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TServerSharedData {
public:
// In per-db catalog version mode, this puts a limit on the maximum number of databases
// that can exist in a cluster.
static constexpr int32 kMaxNumDbCatalogVersions = 10000;
static constexpr uint32_t kMaxNumDbCatalogVersions = 10000;

TServerSharedData() {
// All atomics stored in shared memory must be lock-free. Non-robust locks
Expand Down
7 changes: 7 additions & 0 deletions src/yb/yql/pgwrapper/libpq_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,12 @@ Result<PGConn> PGConnBuilder::Connect(bool simple_query_protocol) const {
return PGConn::Connect(conn_str_, simple_query_protocol, conn_str_for_log_);
}

Result<PGConn> Execute(Result<PGConn> connection, const std::string& query) {
if (connection.ok()) {
RETURN_NOT_OK((*connection).Execute(query));
}
return connection;
}

} // namespace pgwrapper
} // namespace yb
2 changes: 2 additions & 0 deletions src/yb/yql/pgwrapper/libpq_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,7 @@ class PGConnBuilder {

bool HasTryAgain(const Status& status);

Result<PGConn> Execute(Result<PGConn> connection, const std::string& query);

} // namespace pgwrapper
} // namespace yb
Loading

0 comments on commit 9d900b3

Please sign in to comment.