Skip to content

Commit 8e2528a

Browse files
committed
[#27387] YSQL: Improve logging for incremental catalog cache refresh
Summary: This diff makes some changes to improve logging incremental catalog cache refresh to debugging a few cases found in QA stress test when full catalog refreshes were performed unexpectedly. Jira: DB-16921 Test Plan: (1) ./yb_build.sh release --cxx-test pg_catalog_version-test (2) start a RF-3 local cluster on my own dev vm, look at tserver logs to ensure that there are no log flooding caused by this change when there is no DDL statement executed. Reviewers: kfranz, sanketh, mihnea Reviewed By: kfranz Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D44459
1 parent d7df702 commit 8e2528a

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

src/yb/tserver/tablet_server.cc

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,15 @@ Status TabletServer::SetTserverCatalogMessageList(
11381138

11391139
int shm_index = -1;
11401140
InvalidationMessagesQueue *db_message_lists = nullptr;
1141-
auto scope_exit = ScopeExit([this, &shm_index, &db_message_lists, db_oid, new_catalog_version] {
1141+
auto scope_exit = ScopeExit([this, &shm_index, &db_message_lists, db_oid, is_breaking_change,
1142+
new_catalog_version] {
11421143
if (shm_index >= 0) {
11431144
shared_object()->SetYsqlDbCatalogVersion(static_cast<size_t>(shm_index), new_catalog_version);
1145+
if (FLAGS_log_ysql_catalog_versions) {
1146+
LOG_WITH_FUNC(INFO) << "set db " << db_oid
1147+
<< " catalog version: " << new_catalog_version
1148+
<< " is_breaking_change: " << is_breaking_change;
1149+
}
11441150
InvalidatePgTableCache({{db_oid, new_catalog_version}} /* db_oids_updated */,
11451151
{} /* db_oids_deleted */);
11461152
}
@@ -1461,6 +1467,9 @@ void TabletServer::SetYsqlDBCatalogVersionsUnlocked(
14611467
// debugging the shared memory array db_catalog_versions_ (e.g., when we can dump
14621468
// the shared memory file to examine its contents).
14631469
shared_object()->SetYsqlDbCatalogVersion(static_cast<size_t>(shm_index), 0);
1470+
if (FLAGS_log_ysql_catalog_versions) {
1471+
LOG_WITH_FUNC(INFO) << "reset deleted db " << db_oid << " catalog version to 0";
1472+
}
14641473
} else {
14651474
++it;
14661475
}
@@ -1512,6 +1521,7 @@ void TabletServer::SetYsqlDBCatalogVersionsWithInvalMessages(
15121521
void TabletServer::SetYsqlDBCatalogInvalMessagesUnlocked(
15131522
const master::DBCatalogInvalMessagesDataPB& db_catalog_inval_messages_data) {
15141523
if (db_catalog_inval_messages_data.db_catalog_inval_messages_size() == 0) {
1524+
LOG(INFO) << "empty db_catalog_inval_messages";
15151525
return;
15161526
}
15171527
uint32_t current_db_oid = 0;
@@ -1604,12 +1614,14 @@ void TabletServer::MergeInvalMessagesIntoQueueUnlocked(
16041614
// We do need to perform a merge, because both the queue and the incoming messages are sorted by
16051615
// version, it is similar to a merge sort strategy.
16061616
DoMergeInvalMessagesIntoQueueUnlocked(
1607-
db_catalog_inval_messages_data, start_index, end_index, &it->second.queue);
1617+
db_oid, db_catalog_inval_messages_data, start_index, end_index, &it->second.queue);
16081618
}
16091619

16101620
void TabletServer::DoMergeInvalMessagesIntoQueueUnlocked(
1621+
uint32_t db_oid,
16111622
const master::DBCatalogInvalMessagesDataPB& db_catalog_inval_messages_data,
16121623
int start_index, int end_index, InvalidationMessagesQueue *db_message_lists) {
1624+
bool changed = false;
16131625
auto it = db_message_lists->begin();
16141626
// Scan through each incoming pair, and insert it into the queue in the right position if
16151627
// it does not already exist in the queue.
@@ -1637,16 +1649,22 @@ void TabletServer::DoMergeInvalMessagesIntoQueueUnlocked(
16371649
++it;
16381650
++start_index;
16391651
} else if (incoming_version < existing_version) {
1640-
// The incoming version is lower, insert it before it.
1641-
VLOG(2) << "inserting version " << incoming_version;
1652+
std::string msg_info =
1653+
incoming_message_list.has_value() ? std::to_string(incoming_message_list.value().size())
1654+
: "nullopt";
1655+
// The incoming version is lower, insert before the iterator.
1656+
LOG(INFO) << "inserting version " << incoming_version << ", incoming_message_list: "
1657+
<< msg_info << " before existing version " << existing_version
1658+
<< ", db " << db_oid;
16421659
it = db_message_lists->insert(it, std::make_pair(incoming_version, incoming_message_list));
1660+
changed = true;
16431661
// After insertion, it points to the newly inserted incoming version, advance it to the
16441662
// original existing version.
16451663
++it;
16461664
++start_index;
16471665
DCHECK_EQ(it->first, existing_version);
16481666
} else {
1649-
// The incoming version is higher, move it to the next existing slot in the queue.
1667+
// The incoming version is higher, move iterator to the next existing slot in the queue.
16501668
// Keep start_index unchanged so that it can be compared with the next slot in the queue.
16511669
VLOG(2) << "existing version: " << existing_version
16521670
<< ", higher incoming version: " << incoming_version;
@@ -1660,13 +1678,19 @@ void TabletServer::DoMergeInvalMessagesIntoQueueUnlocked(
16601678
const uint64_t current_version = db_inval_messages.current_version();
16611679
const std::optional<std::string>& message_list = db_inval_messages.has_message_list() ?
16621680
std::optional<std::string>(db_inval_messages.message_list()) : std::nullopt;
1663-
VLOG(2) << "appending version " << current_version;
1681+
std::string msg_info = message_list.has_value() ? std::to_string(message_list.value().size())
1682+
: "nullopt";
1683+
LOG(INFO) << "appending version " << current_version << ", message_list: " << msg_info
1684+
<< ", db " << db_oid;
16641685
db_message_lists->emplace_back(std::make_pair(current_version, message_list));
1686+
changed = true;
16651687
}
1666-
VLOG(2) << "queue size: " << db_message_lists->size();
1667-
// We may have added more messages to the queue that exceeded the max size.
1668-
while (db_message_lists->size() > FLAGS_ysql_max_invalidation_message_queue_size) {
1669-
db_message_lists->pop_front();
1688+
if (changed) {
1689+
LOG(INFO) << "queue size: " << db_message_lists->size();
1690+
// We may have added more messages to the queue that exceeded the max size.
1691+
while (db_message_lists->size() > FLAGS_ysql_max_invalidation_message_queue_size) {
1692+
db_message_lists->pop_front();
1693+
}
16701694
}
16711695
}
16721696

src/yb/tserver/tablet_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ class TabletServer : public DbServerBase, public TabletServerIf {
616616
int start_index,
617617
int end_index) REQUIRES(lock_);
618618
void DoMergeInvalMessagesIntoQueueUnlocked(
619+
uint32_t db_oid,
619620
const master::DBCatalogInvalMessagesDataPB& db_catalog_inval_messages_data,
620621
int start_index,
621622
int end_index,

0 commit comments

Comments
 (0)