Skip to content

Commit 0b0fc23

Browse files
committed
Fix connection accounting for revcons
Changes from review - Tx Akshat Signed-off-by: Mark Hannum <mhannum@bloomberg.net>
1 parent 5f549a2 commit 0b0fc23

7 files changed

Lines changed: 50 additions & 0 deletions

File tree

db/db_tunables.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ extern int gbl_revsql_force_rte;
541541
extern int gbl_revsql_fake_connect_failure;
542542
extern int gbl_connect_remote_rte;
543543
extern int gbl_reverse_hosts_v2;
544+
extern int gbl_admin_revsql;
544545

545546
int gbl_debug_tmptbl_corrupt_mem;
546547
int gbl_group_concat_mem_limit; /* 0 implies allow upto SQLITE_MAX_LENGTH,

db/db_tunables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,8 @@ REGISTER_TUNABLE("revsql_host_refresh_freq_sec", "The frequency at which the "
19401940
"reverse connection host list will be refreshed (Default: 5secs)",
19411941
TUNABLE_INTEGER, &gbl_revsql_host_refresh_freq_sec, EXPERIMENTAL | INTERNAL,
19421942
NULL, NULL, NULL, NULL);
1943+
REGISTER_TUNABLE("admin_revsql", "Run revsql sessions as admin. (Default: Off)", TUNABLE_BOOLEAN, &gbl_admin_revsql, 0,
1944+
NULL, NULL, NULL, NULL);
19431945
REGISTER_TUNABLE("reverse_hosts_v2", "Use reverse_hosts_v2, which includes class and cluster. (Default: Off)",
19441946
TUNABLE_BOOLEAN, &gbl_reverse_hosts_v2, EXPERIMENTAL | INTERNAL, NULL, NULL, NULL, NULL);
19451947
REGISTER_TUNABLE("gbl_class_machs_refresh", "Requery-time for class-machine lookup. (Default: 300s)", TUNABLE_INTEGER,

db/reverse_conn.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ enum {
9191
};
9292

9393
int gbl_revsql_force_rte = 1;
94+
int gbl_admin_revsql = 0;
9495

9596
int send_reversesql_request(const char *dbname, const char *host, const char *command)
9697
{
9798
int rc = 0;
99+
int isadmin = gbl_admin_revsql ? 1 : 0;
98100

99101
if (gbl_revsql_debug == 1) {
100102
revconn_logmsg(LOGMSG_USER, "%s:%d Sending reversesql request to %s@%s\n", __func__, __LINE__, dbname, host);
@@ -109,6 +111,11 @@ int send_reversesql_request(const char *dbname, const char *host, const char *co
109111
int new_fd = sbuf2fileno(sb);
110112
make_server_socket(new_fd);
111113

114+
if (revcon_should_reject(isadmin)) {
115+
rc = -1;
116+
goto cleanup;
117+
}
118+
112119
if (db_is_exiting()) {
113120
if (gbl_revsql_debug == 1) {
114121
revconn_logmsg(LOGMSG_USER, "%s:%d Comdb2 is exiting\n", __func__, __LINE__);

net/net_evbuffer.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,17 @@ static int should_reject_request(uint8_t first_byte)
29302930
return check_appsock_limit(pending_connections, is_admin);
29312931
}
29322932

2933+
struct should_reject_request_arg {
2934+
int ret;
2935+
int isadmin;
2936+
};
2937+
2938+
static void invoke_should_reject_request(void *data)
2939+
{
2940+
struct should_reject_request_arg *arg = data;
2941+
arg->ret = should_reject_request(arg->isadmin ? '@' : 'n');
2942+
}
2943+
29332944
/* PMUV REQUEST/RESPONSE */
29342945
enum request { V_WHO = 1, V_NAK = 2, V_ACK = 3 };
29352946
enum response { V_NONE = 0, V_ID = 1 };
@@ -3978,6 +3989,13 @@ int get_hosts_metric(const char *netname, enum net_metric_type type)
39783989
return metric.value;
39793990
}
39803991

3992+
int revcon_should_reject(int admin)
3993+
{
3994+
struct should_reject_request_arg arg = {.isadmin = admin};
3995+
run_on_base(base, invoke_should_reject_request, &arg);
3996+
return arg.ret;
3997+
}
3998+
39813999
int add_appsock_handler(const char *key, event_callback_fn cb)
39824000
{
39834001
size_t keylen = strlen(key);

net/net_int.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ enum net_metric_type {
359359
MAX_QUEUE_SIZE = 2
360360
};
361361
int get_hosts_metric(const char *netname, enum net_metric_type type);
362+
int revcon_should_reject(int admin);
362363

363364
int dist_heartbeats(dist_hbeats_type *);
364365

tests/phys_rep_tiered.test/runit

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,21 @@ function phys_rep_nomatch
17961796
return 0
17971797
}
17981798

1799+
# rev-cons were decrementing active_appsock_conns without incrementing
1800+
# Verify that there are a sane number of 'concurrent_connections' in comdb2_metrics
1801+
function verify_connection_count
1802+
{
1803+
if [[ -z "$CLUSTER" ]]; then
1804+
num=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} $DBNAME default "select value from comdb2_metrics where name='concurrent_connections'")
1805+
[[ "$num" == -* ]] && cleanFailExit "Connection count is negative"
1806+
else
1807+
for node in ${CLUSTER} ; do
1808+
num=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} $DBNAME --host $node "select value from comdb2_metrics where name='concurrent_connections'")
1809+
[[ "$num" == -* ]] && cleanFailExit "Connection count is negative"
1810+
done
1811+
fi
1812+
}
1813+
17991814
trap - INT EXIT
18001815

18011816
# 1. Setup replication metadata cluster
@@ -2016,6 +2031,11 @@ function run_tests
20162031
testcase_preamble $testcase
20172032
check_metadb_memstat
20182033
testcase_finish $testcase
2034+
2035+
testcase="verify_connection_count"
2036+
testcase_preamble $testcase
2037+
verify_connection_count
2038+
testcase_finish $testcase
20192039
}
20202040

20212041
run_tests

tests/tunables.test/t00_all_tunables.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
(name='add_record_interval', description='Add a record every seconds while there are incoherent_wait replicants.', type='INTEGER', value='1', read_only='N')
2222
(name='additional_deferms', description='Wait-fudge to ensure that a replicant has gone incoherent.', type='INTEGER', value='0', read_only='N')
2323
(name='admin_mode', description='Fail non-admin client requests (Default: False)', type='BOOLEAN', value='OFF', read_only='N')
24+
(name='admin_revsql', description='Run revsql sessions as admin. (Default: Off)', type='BOOLEAN', value='OFF', read_only='N')
2425
(name='all_incoherent', description='Master pretends nodes are incoherent.', type='BOOLEAN', value='OFF', read_only='N')
2526
(name='allow_anon_id_for_spmux', description='Allow anonymous identities over connections routed from the secure pmux port', type='INTEGER', value='0', read_only='N')
2627
(name='allow_broken_datetimes', description='Allow broken datetimes', type='BOOLEAN', value='ON', read_only='N')

0 commit comments

Comments
 (0)