hdb: Test LMDB and SQLite3 HDB concurrency

Test that we can dump an HDB w/o blocking write transactions.

This currently works for different processes (both backends), but not
for threads (for either backend), and it's not yet clear why.
This commit is contained in:
Nicolas Williams
2020-10-06 12:08:18 -05:00
parent 8c7900c40b
commit f87ba4f23b
3 changed files with 472 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ typedef struct hdb_sqlite_db {
sqlite3 *db;
char *db_file;
sqlite3_stmt *connect;
sqlite3_stmt *get_version;
sqlite3_stmt *fetch;
sqlite3_stmt *get_ids;
@@ -82,6 +83,9 @@ typedef struct hdb_sqlite_db {
" DELETE FROM Principal" \
" WHERE entry = OLD.id;" \
" END"
#define HDBSQLITE_CONNECT \
" PRAGMA read_uncommitted = false;" \
" PRAGMA journal_mode = WAL"
#define HDBSQLITE_GET_VERSION \
" SELECT number FROM Version"
#define HDBSQLITE_FETCH \
@@ -155,6 +159,11 @@ prep_stmts(krb5_context context, hdb_sqlite_db *hsdb)
{
int ret;
ret = hdb_sqlite_prepare_stmt(context, hsdb->db,
&hsdb->connect,
HDBSQLITE_CONNECT);
if (ret)
return ret;
ret = hdb_sqlite_prepare_stmt(context, hsdb->db,
&hsdb->get_version,
HDBSQLITE_GET_VERSION);
@@ -209,6 +218,10 @@ prep_stmts(krb5_context context, hdb_sqlite_db *hsdb)
static void
finalize_stmts(krb5_context context, hdb_sqlite_db *hsdb)
{
if (hsdb->connect != NULL)
sqlite3_finalize(hsdb->connect);
hsdb->connect = NULL;
if (hsdb->get_version != NULL)
sqlite3_finalize(hsdb->get_version);
hsdb->get_version = NULL;
@@ -316,6 +329,8 @@ bind_principal(krb5_context context, krb5_const_principal principal, sqlite3_stm
return 0;
}
static int hdb_sqlite_step(krb5_context, sqlite3 *, sqlite3_stmt *);
/**
* Opens an sqlite3 database handle to a file, may create the
* database file depending on flags.
@@ -347,6 +362,8 @@ hdb_sqlite_open_database(krb5_context context, HDB *db, int flags)
return ret;
}
(void) hdb_sqlite_step(context, hsdb->db, hsdb->connect);
sqlite3_reset(hsdb->connect);
return 0;
}