Otherwise there is the chance that we will reset the statistics after the counter has been incremented (client connects) to zero and when the client disconnects we decrement it to a negative number.
this is a pure cosmetic patch with no operational impact to ctdb
{
ctdb_takeover_client_destructor_hook(client);
ctdb_reqid_remove(client->ctdb, client->client_id);
{
ctdb_takeover_client_destructor_hook(client);
ctdb_reqid_remove(client->ctdb, client->client_id);
- client->ctdb->statistics.num_clients--;
+ if (client->ctdb->statistics.num_clients) {
+ client->ctdb->statistics.num_clients--;
+ }
if (client->num_persistent_updates != 0) {
DEBUG(DEBUG_ERR,(__location__ " Client disconnecting with %u persistent updates in flight. Starting recovery\n", client->num_persistent_updates));
if (client->num_persistent_updates != 0) {
DEBUG(DEBUG_ERR,(__location__ " Client disconnecting with %u persistent updates in flight. Starting recovery\n", client->num_persistent_updates));
res = ctdb_daemon_call_recv(state, dstate->call);
if (res != 0) {
DEBUG(DEBUG_ERR, (__location__ " ctdbd_call_recv() returned error\n"));
res = ctdb_daemon_call_recv(state, dstate->call);
if (res != 0) {
DEBUG(DEBUG_ERR, (__location__ " ctdbd_call_recv() returned error\n"));
- client->ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ client->ctdb->statistics.pending_calls--;
+ }
ctdb_latency(ctdb_db, "call_from_client_cb 1", &client->ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
ctdb_latency(ctdb_db, "call_from_client_cb 1", &client->ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
length, struct ctdb_reply_call);
if (r == NULL) {
DEBUG(DEBUG_ERR, (__location__ " Failed to allocate reply_call in ctdb daemon\n"));
length, struct ctdb_reply_call);
if (r == NULL) {
DEBUG(DEBUG_ERR, (__location__ " Failed to allocate reply_call in ctdb daemon\n"));
- client->ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ client->ctdb->statistics.pending_calls--;
+ }
ctdb_latency(ctdb_db, "call_from_client_cb 2", &client->ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
ctdb_latency(ctdb_db, "call_from_client_cb 2", &client->ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
}
ctdb_latency(ctdb_db, "call_from_client_cb 3", &client->ctdb->statistics.max_call_latency, dstate->start_time);
talloc_free(dstate);
}
ctdb_latency(ctdb_db, "call_from_client_cb 3", &client->ctdb->statistics.max_call_latency, dstate->start_time);
talloc_free(dstate);
- client->ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ client->ctdb->statistics.pending_calls--;
+ }
}
struct ctdb_daemon_packet_wrap {
}
struct ctdb_daemon_packet_wrap {
struct ctdb_daemon_packet_wrap *w;
ctdb->statistics.total_calls++;
struct ctdb_daemon_packet_wrap *w;
ctdb->statistics.total_calls++;
- ctdb->statistics.pending_calls++;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls++;
+ }
ctdb_db = find_ctdb_db(client->ctdb, c->db_id);
if (!ctdb_db) {
DEBUG(DEBUG_ERR, (__location__ " Unknown database in request. db_id==0x%08x",
c->db_id));
ctdb_db = find_ctdb_db(client->ctdb, c->db_id);
if (!ctdb_db) {
DEBUG(DEBUG_ERR, (__location__ " Unknown database in request. db_id==0x%08x",
c->db_id));
- ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls--;
+ }
daemon_incoming_packet_wrap, w, True);
if (ret == -2) {
/* will retry later */
daemon_incoming_packet_wrap, w, True);
if (ret == -2) {
/* will retry later */
- ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls--;
+ }
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Unable to fetch record\n"));
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Unable to fetch record\n"));
- ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls--;
+ }
if (dstate == NULL) {
ctdb_ltdb_unlock(ctdb_db, key);
DEBUG(DEBUG_ERR,(__location__ " Unable to allocate dstate\n"));
if (dstate == NULL) {
ctdb_ltdb_unlock(ctdb_db, key);
DEBUG(DEBUG_ERR,(__location__ " Unable to allocate dstate\n"));
- ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls--;
+ }
return;
}
dstate->start_time = timeval_current();
return;
}
dstate->start_time = timeval_current();
if (call == NULL) {
ctdb_ltdb_unlock(ctdb_db, key);
DEBUG(DEBUG_ERR,(__location__ " Unable to allocate call\n"));
if (call == NULL) {
ctdb_ltdb_unlock(ctdb_db, key);
DEBUG(DEBUG_ERR,(__location__ " Unable to allocate call\n"));
- ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls--;
+ }
ctdb_latency(ctdb_db, "call_from_client 1", &ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
ctdb_latency(ctdb_db, "call_from_client 1", &ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Unable to setup call send\n"));
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Unable to setup call send\n"));
- ctdb->statistics.pending_calls--;
+ if (client->ctdb->statistics.pending_calls > 0) {
+ ctdb->statistics.pending_calls--;
+ }
ctdb_latency(ctdb_db, "call_from_client 2", &ctdb->statistics.max_call_latency, dstate->start_time);
return;
}
ctdb_latency(ctdb_db, "call_from_client 2", &ctdb->statistics.max_call_latency, dstate->start_time);
return;
}