Skip to content

Commit 02c52b5

Browse files
committed
Count physrep metadb requests
Signed-off-by: Mark Hannum <mhannum@bloomberg.net>
1 parent 036f22c commit 02c52b5

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

db/db_metrics.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct comdb2_metrics_store {
114114
int64_t not_durable_commits;
115115
int64_t incoherent_slow_skips;
116116
int64_t inmem_repdb_memory;
117+
int64_t physrep_metadb_sql_count;
117118

118119
int64_t page_reads;
119120
int64_t page_writes;
@@ -321,6 +322,8 @@ comdb2_metric gbl_metrics[] = {
321322
STATISTIC_COLLECTION_TYPE_CUMULATIVE, &stats.incoherent_slow_skips, NULL},
322323
{"inmem_repdb_memory", "Memory utilized by in-memory repdb", STATISTIC_INTEGER, STATISTIC_COLLECTION_TYPE_LATEST,
323324
&stats.inmem_repdb_memory, NULL},
325+
{"physrep_metadb_sql_count", "Count of SQL statements executed against physrep metadb", STATISTIC_INTEGER,
326+
STATISTIC_COLLECTION_TYPE_CUMULATIVE, &stats.physrep_metadb_sql_count, NULL},
324327
{"page_reads", "Total page reads", STATISTIC_INTEGER, STATISTIC_COLLECTION_TYPE_CUMULATIVE, &stats.page_reads,
325328
NULL},
326329
{"page_writes", "Total page writes", STATISTIC_INTEGER, STATISTIC_COLLECTION_TYPE_CUMULATIVE, &stats.page_writes,
@@ -446,6 +449,7 @@ extern int64_t gbl_distributed_commit_count;
446449
extern int64_t gbl_not_durable_commit_count;
447450
extern int64_t gbl_incoherent_slow_skips;
448451
extern int64_t gbl_inmem_repdb_memory;
452+
extern int64_t gbl_physrep_metadb_sql_count;
449453

450454
static void update_sqllogfill_metrics()
451455
{
@@ -656,6 +660,7 @@ int refresh_metrics(void)
656660
stats.not_durable_commits = gbl_not_durable_commit_count;
657661
stats.incoherent_slow_skips = gbl_incoherent_slow_skips;
658662
stats.inmem_repdb_memory = gbl_inmem_repdb_memory;
663+
stats.physrep_metadb_sql_count = gbl_physrep_metadb_sql_count;
659664
struct global_stats gstats = {0};
660665

661666
global_request_stats(&gstats);

db/phys_rep.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include <parse_lsn.h>
4242
#include <logmsg.h>
43+
#include <comdb2_atomic.h>
4344

4445
/* internal implementation */
4546
typedef struct DB_Connection {
@@ -61,6 +62,7 @@ int gbl_physrep_debug = 0;
6162
int gbl_physrep_reconnect_interval = 3600; // force re-registration every hour
6263
int gbl_physrep_reconnect_penalty = 0;
6364
int gbl_blocking_physrep = 1;
65+
int64_t gbl_physrep_metadb_sql_count = 0;
6466
int gbl_physrep_fanout = 8;
6567
int gbl_physrep_max_candidates = 6;
6668
int gbl_physrep_max_pending_replicants = 10;
@@ -535,6 +537,7 @@ static int update_registry(cdb2_hndl_tp *repl_metadb, const char *remote_dbname,
535537
physrep_logmsg(LOGMSG_USER, "%s:%d Executing: %s\n", __func__, __LINE__, cmd);
536538
}
537539

540+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
538541
if ((rc = cdb2_run_statement(repl_metadb, cmd)) == CDB2_OK) {
539542
while ((rc = cdb2_next_record(repl_metadb)) == CDB2_OK)
540543
;
@@ -600,6 +603,7 @@ static int send_reset_nodes_int(cdb2_hndl_tp *hndl, const char *state)
600603
physrep_logmsg(LOGMSG_USER, "%s:%d Executing: %s\n", __func__, __LINE__, cmd);
601604
}
602605

606+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
603607
if ((rc = cdb2_run_statement(hndl, cmd)) == CDB2_OK) {
604608
while ((rc = cdb2_next_record(hndl)) == CDB2_OK)
605609
;
@@ -924,6 +928,7 @@ static int register_self(cdb2_hndl_tp *repl_metadb)
924928
}
925929

926930
int candidate_leaders_count = 0;
931+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
927932
if ((rc = cdb2_run_statement(repl_metadb, cmd)) == CDB2_OK) {
928933
while ((rc = cdb2_next_record(repl_metadb)) == CDB2_OK) {
929934
char *dbname = (char *)cdb2_column_value(repl_metadb, 1);
@@ -1111,6 +1116,7 @@ static int send_keepalive_int(cdb2_hndl_tp *metadb)
11111116
rc = snprintf(
11121117
cmd, sizeof(cmd),
11131118
"select count(*) from comdb2_columns where tablename='comdb2_physreps' and columnname='firstfile'");
1119+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
11141120
rc = cdb2_run_statement(metadb, cmd);
11151121
if (rc != CDB2_OK) {
11161122
physrep_logmsg(LOGMSG_ERROR, "%s:%d Failed to execute cmd %s (rc: %d)\n", __func__, __LINE__, cmd, rc);
@@ -1140,6 +1146,7 @@ static int send_keepalive_int(cdb2_hndl_tp *metadb)
11401146
if (gbl_physrep_debug)
11411147
physrep_logmsg(LOGMSG_USER, "%s:%d: Executing: %s\n", __func__, __LINE__, cmd);
11421148

1149+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
11431150
rc = cdb2_run_statement(metadb, cmd);
11441151
if (rc == CDB2_OK) {
11451152
while (cdb2_next_record(metadb) == CDB2_OK) {
@@ -1200,6 +1207,7 @@ static int check_for_reverse_conn(cdb2_hndl_tp *hndl) {
12001207
if (gbl_physrep_debug)
12011208
physrep_logmsg(LOGMSG_USER, "%s:%d Executing: %s\n", __func__, __LINE__, cmd);
12021209

1210+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
12031211
if ((rc = cdb2_run_statement(hndl, cmd)) == CDB2_OK) {
12041212
while ((rc = cdb2_next_record(hndl)) == CDB2_OK) {
12051213
int64_t val = *(int64_t *)cdb2_column_value(hndl, 0);
@@ -1261,6 +1269,7 @@ static int slow_replicants_count_int(cdb2_hndl_tp *metadb, unsigned int *count)
12611269
"AND now() - last_keepalive >= %d",
12621270
gbl_dbname, gbl_physrep_hung_replicant_threshold);
12631271

1272+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
12641273
rc = cdb2_run_statement(metadb, query);
12651274
if (rc == CDB2_OK) {
12661275
while ((rc = cdb2_next_record(metadb)) == CDB2_OK) {
@@ -1355,6 +1364,7 @@ static int update_min_logfile_int(cdb2_hndl_tp *metadb)
13551364
physrep_logmsg(LOGMSG_USER, "%s:%d Executing: %s\n", __func__, __LINE__, cmd);
13561365
}
13571366

1367+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
13581368
rc = cdb2_run_statement(metadb, cmd);
13591369
if (rc == CDB2_OK) {
13601370
while ((rc = cdb2_next_record(metadb)) == CDB2_OK) {
@@ -1926,6 +1936,7 @@ static void am_i_hung(time_t cur_time) {
19261936
return;
19271937
}
19281938

1939+
ATOMIC_ADD64(gbl_physrep_metadb_sql_count, 1);
19291940
rc = cdb2_run_statement(repl_metadb, query);
19301941
if (rc == CDB2_OK) {
19311942
while ((rc = cdb2_next_record(repl_metadb)) == CDB2_OK) {

tests/phys_rep_tiered.test/runit

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,89 @@ function physrep_revconn_populate_retry_with_debug
26202620
$CDB2SQL_EXE $CDB2_OPTIONS $REPL_META_DBNAME --host $REPL_META_HOST "delete from comdb2_physrep_sources where dbname = '$bogusname'"
26212621
}
26222622

2623+
# Collects and sums the physrep_metadb_sql_count metric from all databases/physreps
2624+
function physrep_metadb_sql_count_test
2625+
{
2626+
echo "== Collecting physrep_metadb_sql_count from all databases =="
2627+
local total_count=0
2628+
local count=0
2629+
local dbname=""
2630+
local host=""
2631+
2632+
# Source database
2633+
echo "Collecting from source database: $DBNAME"
2634+
if [[ -z "$CLUSTER" ]]; then
2635+
host=$(hostname)
2636+
else
2637+
host="$firstNode"
2638+
fi
2639+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${DBNAME} --host ${host} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2640+
[[ -n "$count" ]] && total_count=$((total_count + count))
2641+
echo " ${DBNAME}@${host}: $count"
2642+
2643+
# Main metadb
2644+
echo "Collecting from main metadb: $REPL_META_DBNAME"
2645+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${REPL_META_DBNAME} --host ${REPL_META_HOST} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2646+
[[ -n "$count" ]] && total_count=$((total_count + count))
2647+
echo " ${REPL_META_DBNAME}@${REPL_META_HOST}: $count"
2648+
2649+
# Alternate metadb
2650+
echo "Collecting from alternate metadb: $REPL_ALTMETA_DBNAME"
2651+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${REPL_ALTMETA_DBNAME} --host ${REPL_ALTMETA_HOST} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2652+
[[ -n "$count" ]] && total_count=$((total_count + count))
2653+
echo " ${REPL_ALTMETA_DBNAME}@${REPL_ALTMETA_HOST}: $count"
2654+
2655+
# Alternate metadb 2
2656+
echo "Collecting from alternate metadb2: $REPL_ALTMETA_DBNAME2"
2657+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${REPL_ALTMETA_DBNAME2} --host ${REPL_ALTMETA_HOST2} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2658+
[[ -n "$count" ]] && total_count=$((total_count + count))
2659+
echo " ${REPL_ALTMETA_DBNAME2}@${REPL_ALTMETA_HOST2}: $count"
2660+
2661+
# Replication cluster
2662+
echo "Collecting from replication cluster: $REPL_CLUS_DBNAME"
2663+
if [[ -z "$CLUSTER" ]]; then
2664+
host=$(hostname)
2665+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${REPL_CLUS_DBNAME} --host ${host} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2666+
[[ -n "$count" ]] && total_count=$((total_count + count))
2667+
echo " ${REPL_CLUS_DBNAME}@${host}: $count"
2668+
else
2669+
for node in $CLUSTER; do
2670+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${REPL_CLUS_DBNAME} --host ${node} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2671+
[[ -n "$count" ]] && total_count=$((total_count + count))
2672+
echo " ${REPL_CLUS_DBNAME}@${node}: $count"
2673+
done
2674+
fi
2675+
2676+
# Standalone physreps
2677+
echo "Collecting from standalone physreps"
2678+
if [[ -z "$CLUSTER" ]]; then
2679+
node=$(hostname)
2680+
dbname="${REPL_DBNAME_PREFIX}_${node}"
2681+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${dbname} --host ${node} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2682+
[[ -n "$count" ]] && total_count=$((total_count + count))
2683+
echo " ${dbname}@${node}: $count"
2684+
else
2685+
for node in $CLUSTER; do
2686+
dbname="${REPL_DBNAME_PREFIX}_${node}"
2687+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${dbname} --host ${node} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2688+
[[ -n "$count" ]] && total_count=$((total_count + count))
2689+
echo " ${dbname}@${node}: $count"
2690+
done
2691+
fi
2692+
2693+
# Alternate replicant
2694+
echo "Collecting from alternate replicant: $REPL_ALT_DBNAME"
2695+
count=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${REPL_ALT_DBNAME} --host ${REPL_ALT_HOST} "select value from comdb2_metrics where name='physrep_metadb_sql_count'" 2>/dev/null)
2696+
[[ -n "$count" ]] && total_count=$((total_count + count))
2697+
echo " ${REPL_ALT_DBNAME}@${REPL_ALT_HOST}: $count"
2698+
2699+
echo ""
2700+
echo "========================================="
2701+
echo "TOTAL physrep_metadb_sql_count: $total_count"
2702+
echo "========================================="
2703+
echo ""
2704+
}
2705+
26232706
function announce
26242707
{
26252708
typeset text=$1
@@ -2813,12 +2896,16 @@ function run_tests
28132896
testcase_preamble $testcase
28142897
physrep_revconn_populate_retry_with_debug
28152898
testcase_finish $testcase
2899+
2900+
testcase="physrep_metadb_sql_count"
2901+
testcase_preamble $testcase
2902+
physrep_metadb_sql_count_test
2903+
testcase_finish $testcase
28162904
}
28172905

28182906
function run_one_test
28192907
{
2820-
physrep_revconn_populate_error
2821-
physrep_revconn_populate_retry_with_debug
2908+
physrep_metadb_sql_count_test
28222909
}
28232910

28242911
run_tests

0 commit comments

Comments
 (0)