return p;
}
-
-/*
- update a max latency number
- */
-void ctdb_latency(struct ctdb_db_context *ctdb_db, const char *name, double *latency, struct timeval t)
-{
- double l = timeval_elapsed(&t);
- if (l > *latency) {
- *latency = l;
- }
-
- if (ctdb_db->ctdb->tunable.log_latency_ms !=0) {
- if (l*1000 > ctdb_db->ctdb->tunable.log_latency_ms) {
- DEBUG(DEBUG_WARNING, ("High latency %.6fs for operation %s on database %s\n", l, name, ctdb_db->db_name));
- }
- }
-}
-
-/*
- update a reclock latency number
- */
-void ctdb_reclock_latency(struct ctdb_context *ctdb, const char *name, double *latency, double l)
-{
- if (l > *latency) {
- *latency = l;
- }
-
- if (ctdb->tunable.reclock_latency_ms !=0) {
- if (l*1000 > ctdb->tunable.reclock_latency_ms) {
- DEBUG(DEBUG_ERR, ("High RECLOCK latency %fs for operation %s\n", l, name));
- }
- }
-}
-
uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state)
{
int id = idr_get_new_above(ctdb->idr, state, ctdb->lastid+1, INT_MAX);
struct ctdb_queue *queue;
};
+
+#define CTDB_UPDATE_STAT(ctdb, counter, value) \
+ { \
+ if (value > ctdb->statistics.counter) { \
+ ctdb->statistics.counter = c->hopcount; \
+ } \
+ }
+
+#define CTDB_INCREMENT_STAT(ctdb, counter) \
+ { \
+ ctdb->statistics.counter++; \
+ }
+
+#define CTDB_DECREMENT_STAT(ctdb, counter) \
+ { \
+ if (ctdb->statistics.counter > 0) \
+ ctdb->statistics.counter--; \
+ }
+
+#define CTDB_UPDATE_RECLOCK_LATENCY(ctdb, name, counter, value) \
+ { \
+ if (value > ctdb->statistics.counter) { \
+ ctdb->statistics.counter = value; \
+ } \
+ \
+ if (ctdb->tunable.reclock_latency_ms != 0) { \
+ if (value*1000 > ctdb->tunable.reclock_latency_ms) { \
+ DEBUG(DEBUG_ERR, ("High RECLOCK latency %fs for operation %s\n", value, name)); \
+ } \
+ } \
+ }
+
+
+#define CTDB_UPDATE_LATENCY(ctdb, db, operation, counter, t) \
+ { \
+ double l = timeval_elapsed(&t); \
+ if (l > ctdb->statistics.counter) { \
+ ctdb->statistics.counter = l; \
+ } \
+ \
+ if (ctdb->tunable.log_latency_ms !=0) { \
+ if (l*1000 > ctdb->tunable.log_latency_ms) { \
+ DEBUG(DEBUG_WARNING, ("High latency %.6fs for operation %s on database %s\n", l, operation, db->db_name));\
+ } \
+ } \
+ }
+
+
+
+
/*
- ctdb status information
+ ctdb statistics information
*/
struct ctdb_statistics {
uint32_t num_clients;
int ctdb_socket_connect(struct ctdb_context *ctdb);
-void ctdb_latency(struct ctdb_db_context *ctdb_db, const char *name, double *latency, struct timeval t);
-void ctdb_reclock_latency(struct ctdb_context *ctdb, const char *name, double *latency, double l);
-
#define CTDB_BAD_REQID ((uint32_t)-1)
uint32_t ctdb_reqid_new(struct ctdb_context *ctdb, void *state);
void *_ctdb_reqid_find(struct ctdb_context *ctdb, uint32_t reqid, const char *type, const char *location);
int ctdb_init_tevent_logging(struct ctdb_context *ctdb);
+int ctdb_update_stat_counter(struct ctdb_context *ctdb, uint32_t *counter, uint32_t value);
+
#endif
return;
}
- if (c->hopcount > ctdb->statistics.max_hop_count) {
- ctdb->statistics.max_hop_count = c->hopcount;
- }
+ CTDB_UPDATE_STAT(ctdb, max_hop_count, c->hopcount);
/* if this nodes has done enough consecutive calls on the same record
then give them the record
r->hdr.destnode = destnode;
r->hdr.reqid = 0;
- ctdb->statistics.keepalive_packets_sent++;
+ CTDB_INCREMENT_STAT(ctdb, keepalive_packets_sent);
ctdb_queue_packet(ctdb, &r->hdr);
case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
CHECK_CONTROL_DATA_SIZE(sizeof(double));
- ctdb_reclock_latency(ctdb, "recd reclock", &ctdb->statistics.reclock.recd, *((double *)indata.dptr));
+ CTDB_UPDATE_RECLOCK_LATENCY(ctdb, "recd reclock", reclock.recd, *((double *)indata.dptr));
return 0;
case CTDB_CONTROL_GET_RECLOCK_FILE:
CHECK_CONTROL_DATA_SIZE(0);
struct ctdb_control_state *state = talloc_get_type(private_data, struct ctdb_control_state);
TALLOC_CTX *tmp_ctx = talloc_new(ev);
- state->ctdb->statistics.timeouts.control++;
+ CTDB_INCREMENT_STAT(state->ctdb, timeouts.control);
talloc_steal(tmp_ctx, state);
*/
static int daemon_queue_send(struct ctdb_client *client, struct ctdb_req_header *hdr)
{
- client->ctdb->statistics.client_packets_sent++;
+ CTDB_INCREMENT_STAT(client->ctdb, client_packets_sent);
if (hdr->operation == CTDB_REQ_MESSAGE) {
if (ctdb_queue_length(client->queue) > client->ctdb->tunable.max_queue_depth_drop_msg) {
DEBUG(DEBUG_ERR,("CTDB_REQ_MESSAGE queue full - killing client connection.\n"));
ctdb_takeover_client_destructor_hook(client);
ctdb_reqid_remove(client->ctdb, client->client_id);
- if (client->ctdb->statistics.num_clients) {
- client->ctdb->statistics.num_clients--;
- }
+ CTDB_DECREMENT_STAT(client->ctdb, 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));
res = ctdb_daemon_call_recv(state, dstate->call);
if (res != 0) {
DEBUG(DEBUG_ERR, (__location__ " ctdbd_call_recv() returned error\n"));
- 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);
+ CTDB_DECREMENT_STAT(client->ctdb, pending_calls);
+
+ CTDB_UPDATE_LATENCY(client->ctdb, ctdb_db, "call_from_client_cb 1", 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"));
- 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);
+ CTDB_DECREMENT_STAT(client->ctdb, pending_calls);
+ CTDB_UPDATE_LATENCY(client->ctdb, ctdb_db, "call_from_client_cb 2", max_call_latency, dstate->start_time);
return;
}
r->hdr.reqid = dstate->reqid;
if (res != 0) {
DEBUG(DEBUG_ERR, (__location__ " Failed to queue packet from daemon to client\n"));
}
- ctdb_latency(ctdb_db, "call_from_client_cb 3", &client->ctdb->statistics.max_call_latency, dstate->start_time);
+ CTDB_UPDATE_LATENCY(client->ctdb, ctdb_db, "call_from_client_cb 3", max_call_latency, dstate->start_time);
+ CTDB_DECREMENT_STAT(client->ctdb, pending_calls);
talloc_free(dstate);
- if (client->ctdb->statistics.pending_calls > 0) {
- client->ctdb->statistics.pending_calls--;
- }
}
struct ctdb_daemon_packet_wrap {
struct ctdb_context *ctdb = client->ctdb;
struct ctdb_daemon_packet_wrap *w;
- ctdb->statistics.total_calls++;
- if (client->ctdb->statistics.pending_calls > 0) {
- ctdb->statistics.pending_calls++;
- }
+ CTDB_INCREMENT_STAT(ctdb, total_calls);
+ CTDB_DECREMENT_STAT(ctdb, 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));
- if (client->ctdb->statistics.pending_calls > 0) {
- ctdb->statistics.pending_calls--;
- }
+ CTDB_DECREMENT_STAT(ctdb, pending_calls);
return;
}
daemon_incoming_packet_wrap, w, True);
if (ret == -2) {
/* will retry later */
- if (client->ctdb->statistics.pending_calls > 0) {
- ctdb->statistics.pending_calls--;
- }
+ CTDB_DECREMENT_STAT(ctdb, pending_calls);
return;
}
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Unable to fetch record\n"));
- if (client->ctdb->statistics.pending_calls > 0) {
- ctdb->statistics.pending_calls--;
- }
+ CTDB_DECREMENT_STAT(ctdb, pending_calls);
return;
}
}
DEBUG(DEBUG_ERR,(__location__ " Unable to allocate dstate\n"));
- if (client->ctdb->statistics.pending_calls > 0) {
- ctdb->statistics.pending_calls--;
- }
+ CTDB_DECREMENT_STAT(ctdb, pending_calls);
return;
}
dstate->start_time = timeval_current();
}
DEBUG(DEBUG_ERR,(__location__ " Unable to allocate call\n"));
- 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);
+ CTDB_DECREMENT_STAT(ctdb, pending_calls);
+ CTDB_UPDATE_LATENCY(ctdb, ctdb_db, "call_from_client 1", max_call_latency, dstate->start_time);
return;
}
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Unable to setup call send\n"));
- 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);
+ CTDB_DECREMENT_STAT(ctdb, pending_calls);
+ CTDB_UPDATE_LATENCY(ctdb, ctdb_db, "call_from_client 2", max_call_latency, dstate->start_time);
return;
}
talloc_steal(state, dstate);
switch (hdr->operation) {
case CTDB_REQ_CALL:
- ctdb->statistics.client.req_call++;
+ CTDB_INCREMENT_STAT(ctdb, client.req_call);
daemon_request_call_from_client(client, (struct ctdb_req_call *)hdr);
break;
case CTDB_REQ_MESSAGE:
- ctdb->statistics.client.req_message++;
+ CTDB_INCREMENT_STAT(ctdb, client.req_message);
daemon_request_message_from_client(client, (struct ctdb_req_message *)hdr);
break;
case CTDB_REQ_CONTROL:
- ctdb->statistics.client.req_control++;
+ CTDB_INCREMENT_STAT(ctdb, client.req_control);
daemon_request_control_from_client(client, (struct ctdb_req_control *)hdr);
break;
return;
}
- client->ctdb->statistics.client_packets_recv++;
+ CTDB_INCREMENT_STAT(client->ctdb, client_packets_recv);
if (cnt < sizeof(*hdr)) {
ctdb_set_error(client->ctdb, "Bad packet length %u in daemon\n",
talloc_set_destructor(client, ctdb_client_destructor);
talloc_set_destructor(client_pid, ctdb_clientpid_destructor);
- ctdb->statistics.num_clients++;
+ CTDB_INCREMENT_STAT(ctdb, num_clients);
}
key.dptr = talloc_memdup(tmp_ctx, key.dptr, key.dsize);
talloc_set_destructor(h, NULL);
- ctdb_latency(h->ctdb_db, "lockwait", &h->ctdb->statistics.max_lockwait_latency, h->start_time);
- h->ctdb->statistics.pending_lockwait_calls--;
+ CTDB_UPDATE_LATENCY(h->ctdb, h->ctdb_db, "lockwait", max_lockwait_latency, h->start_time);
+ CTDB_DECREMENT_STAT(h->ctdb, pending_lockwait_calls);
/* the handle needs to go away when the context is gone - when
the handle goes away this implicitly closes the pipe, which
static int lockwait_destructor(struct lockwait_handle *h)
{
- h->ctdb->statistics.pending_lockwait_calls--;
+ CTDB_DECREMENT_STAT(h->ctdb, pending_lockwait_calls);
kill(h->child, SIGKILL);
return 0;
}
int ret;
pid_t parent = getpid();
- ctdb_db->ctdb->statistics.lockwait_calls++;
- ctdb_db->ctdb->statistics.pending_lockwait_calls++;
+ CTDB_INCREMENT_STAT(ctdb_db->ctdb, lockwait_calls);
+ CTDB_INCREMENT_STAT(ctdb_db->ctdb, pending_lockwait_calls);
if (!(result = talloc_zero(private_data, struct lockwait_handle))) {
- ctdb_db->ctdb->statistics.pending_lockwait_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_lockwait_calls);
return NULL;
}
if (ret != 0) {
talloc_free(result);
- ctdb_db->ctdb->statistics.pending_lockwait_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_lockwait_calls);
return NULL;
}
close(result->fd[0]);
close(result->fd[1]);
talloc_free(result);
- ctdb_db->ctdb->statistics.pending_lockwait_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_lockwait_calls);
return NULL;
}
(void *)result);
if (result->fde == NULL) {
talloc_free(result);
- ctdb_db->ctdb->statistics.pending_lockwait_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_lockwait_calls);
return NULL;
}
tevent_fd_set_auto_close(result->fde);
static int childwrite_destructor(struct childwrite_handle *h)
{
- h->ctdb->statistics.pending_childwrite_calls--;
+ CTDB_DECREMENT_STAT(h->ctdb, pending_childwrite_calls);
kill(h->child, SIGKILL);
return 0;
}
int ret;
char c;
- ctdb_latency(h->ctdb_db, "persistent", &h->ctdb->statistics.max_childwrite_latency, h->start_time);
- h->ctdb->statistics.pending_childwrite_calls--;
+ CTDB_UPDATE_LATENCY(h->ctdb, h->ctdb_db, "persistent", max_childwrite_latency, h->start_time);
+ CTDB_DECREMENT_STAT(h->ctdb, pending_childwrite_calls);
/* the handle needs to go away when the context is gone - when
the handle goes away this implicitly closes the pipe, which
int ret;
pid_t parent = getpid();
- ctdb_db->ctdb->statistics.childwrite_calls++;
- ctdb_db->ctdb->statistics.pending_childwrite_calls++;
+ CTDB_INCREMENT_STAT(ctdb_db->ctdb, childwrite_calls);
+ CTDB_INCREMENT_STAT(ctdb_db->ctdb, pending_childwrite_calls);
if (!(result = talloc_zero(state, struct childwrite_handle))) {
- ctdb_db->ctdb->statistics.pending_childwrite_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_childwrite_calls);
return NULL;
}
if (ret != 0) {
talloc_free(result);
- ctdb_db->ctdb->statistics.pending_childwrite_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_childwrite_calls);
return NULL;
}
close(result->fd[0]);
close(result->fd[1]);
talloc_free(result);
- ctdb_db->ctdb->statistics.pending_childwrite_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_childwrite_calls);
return NULL;
}
(void *)result);
if (result->fde == NULL) {
talloc_free(result);
- ctdb_db->ctdb->statistics.pending_childwrite_calls--;
+ CTDB_DECREMENT_STAT(ctdb_db->ctdb, pending_childwrite_calls);
return NULL;
}
tevent_fd_set_auto_close(result->fde);
{
double l = timeval_elapsed(&state->start_time);
- ctdb_reclock_latency(state->ctdb, "daemon reclock", &state->ctdb->statistics.reclock.ctdbd, l);
+ CTDB_UPDATE_RECLOCK_LATENCY(state->ctdb, "daemon reclock", reclock.ctdbd, l);
if (state->fd[0] != -1) {
state->fd[0] = -1;
struct recovery_callback_state *state = talloc_get_type(p, struct recovery_callback_state);
ctdb_enable_monitoring(ctdb);
- ctdb->statistics.num_recoveries++;
+ CTDB_INCREMENT_STAT(ctdb, num_recoveries);
if (status != 0) {
DEBUG(DEBUG_ERR,(__location__ " recovered event script failed (status %d)\n", status));
switch (hdr->operation) {
case CTDB_REQ_CALL:
- ctdb->statistics.node.req_call++;
+ CTDB_INCREMENT_STAT(ctdb, node.req_call);
ctdb_request_call(ctdb, hdr);
break;
case CTDB_REPLY_CALL:
- ctdb->statistics.node.reply_call++;
+ CTDB_INCREMENT_STAT(ctdb, node.reply_call);
ctdb_reply_call(ctdb, hdr);
break;
case CTDB_REPLY_ERROR:
- ctdb->statistics.node.reply_error++;
+ CTDB_INCREMENT_STAT(ctdb, node.reply_error);
ctdb_reply_error(ctdb, hdr);
break;
case CTDB_REQ_DMASTER:
- ctdb->statistics.node.req_dmaster++;
+ CTDB_INCREMENT_STAT(ctdb, node.req_dmaster);
ctdb_request_dmaster(ctdb, hdr);
break;
case CTDB_REPLY_DMASTER:
- ctdb->statistics.node.reply_dmaster++;
+ CTDB_INCREMENT_STAT(ctdb, node.reply_dmaster);
ctdb_reply_dmaster(ctdb, hdr);
break;
case CTDB_REQ_MESSAGE:
- ctdb->statistics.node.req_message++;
+ CTDB_INCREMENT_STAT(ctdb, node.req_message);
ctdb_request_message(ctdb, hdr);
break;
case CTDB_REQ_CONTROL:
- ctdb->statistics.node.req_control++;
+ CTDB_INCREMENT_STAT(ctdb, node.req_control);
ctdb_request_control(ctdb, hdr);
break;
case CTDB_REPLY_CONTROL:
- ctdb->statistics.node.reply_control++;
+ CTDB_INCREMENT_STAT(ctdb, node.reply_control);
ctdb_reply_control(ctdb, hdr);
break;
case CTDB_REQ_KEEPALIVE:
- ctdb->statistics.keepalive_packets_recv++;
+ CTDB_INCREMENT_STAT(ctdb, keepalive_packets_recv);
break;
default:
return;
}
- ctdb->statistics.node_packets_sent++;
+ CTDB_INCREMENT_STAT(ctdb, node_packets_sent);
if (!ctdb_validate_pnn(ctdb, hdr->destnode)) {
DEBUG(DEBUG_CRIT,(__location__ " cant send to node %u that does not exist\n",
struct ctdb_traverse_all_handle *state = talloc_get_type(private_data, struct ctdb_traverse_all_handle);
DEBUG(DEBUG_ERR,(__location__ " Traverse all timeout on database:%s\n", state->ctdb_db->db_name));
- state->ctdb->statistics.timeouts.traverse++;
+ CTDB_INCREMENT_STAT(state->ctdb, timeouts.traverse);
state->callback(state->private_data, tdb_null, tdb_null);
}
{
struct ctdb_req_header *hdr = (struct ctdb_req_header *)data;
- ctdb->statistics.node_packets_recv++;
+ CTDB_INCREMENT_STAT(ctdb, node_packets_recv);
/* up the counter for this source node, so we know its alive */
if (ctdb_validate_pnn(ctdb, hdr->srcnode)) {