Browse Source

ckdb - track the number of db connections

master
kanoi 8 years ago
parent
commit
202ff78f11
  1. 9
      src/ckdb.c
  2. 6
      src/ckdb.h
  3. 9
      src/ckdb_cmd.c
  4. 6
      src/ckdb_dbio.c

9
src/ckdb.c

@ -453,6 +453,11 @@ char *by_default = "code";
char *inet_default = "127.0.0.1";
char *id_default = "42";
// Emulate a list for lock checking
K_LIST *pgdb_free;
// Count of db connections
int pgdb_count;
// NULL or poolinstance must match
const char *sys_poolinstance = NULL;
// lock for accessing all mismatch variables
@ -2281,6 +2286,9 @@ static void alloc_storage()
userinfo_store = k_new_store(userinfo_free);
userinfo_root = new_ktree(NULL, cmp_userinfo, userinfo_free);
// Emulate a list for lock checking
pgdb_free = k_lock_only_list("PGDB");
#if LOCK_CHECK
DLPRIO(seqset, 91);
@ -2343,6 +2351,7 @@ static void alloc_storage()
DLPRIO(workers, PRIO_TERMINAL);
DLPRIO(ips, PRIO_TERMINAL);
DLPRIO(replies, PRIO_TERMINAL);
DLPRIO(pgdb, PRIO_TERMINAL);
DLPCHECK();

6
src/ckdb.h

@ -58,7 +58,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "1.0.7"
#define CKDB_VERSION DB_VERSION"-2.714"
#define CKDB_VERSION DB_VERSION"-2.715"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__
@ -445,6 +445,10 @@ extern char *by_default;
extern char *inet_default;
extern char *id_default;
// Emulate a list for lock checking
extern K_LIST *pgdb_free;
extern int pgdb_count;
// Number of seconds per poolinstance message for run
#define POOLINSTANCE_MSG_EVERY 30

9
src/ckdb_cmd.c

@ -7728,6 +7728,15 @@ static char *cmd_query(__maybe_unused PGconn *conn, char *cmd, char *id,
"ESM", FLDSEP, "", FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
ok = true;
} else if (strcasecmp(request, "pg") == 0) {
K_RLOCK(pgdb_free);
snprintf(tmp, sizeof(tmp), "connections=%d%c",
pgdb_count, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
K_RUNLOCK(pgdb_free);
rows++;
ok = true;
#if 0
} else if (strcasecmp(request, "transfer") == 0) {

6
src/ckdb_dbio.c

@ -434,6 +434,9 @@ bool _CKPQConn(PGconn **conn, WHERE_FFL_ARGS)
if (*conn == NULL) {
LOGDEBUG("%s(): connecting", __func__);
*conn = dbconnect();
K_WLOCK(pgdb_free);
pgdb_count++;
K_WUNLOCK(pgdb_free);
return true;
}
return false;
@ -445,6 +448,9 @@ bool _CKPQDisco(PGconn **conn, bool conned, WHERE_FFL_ARGS)
LOGDEBUG("%s(): disco", __func__);
PQfinish(*conn);
*conn = NULL;
K_WLOCK(pgdb_free);
pgdb_count--;
K_WUNLOCK(pgdb_free);
}
return false;
}

Loading…
Cancel
Save