Skip to content

Commit

Permalink
one more try
Browse files Browse the repository at this point in the history
  • Loading branch information
just-now committed Feb 29, 2024
1 parent 62a7ae8 commit 1de0d95
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
10 changes: 10 additions & 0 deletions include/dqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ DQLITE_API int dqlite_node_set_target_voters(dqlite_node *n, int voters);
*/
DQLITE_API int dqlite_node_set_target_standbys(dqlite_node *n, int standbys);


/**
* Set the target number of threads in the thread pool processing sqlite3 disk
* operations.
*
* The default pool thread count is 4.
*/
DQLITE_API int dqlite_node_set_pool_thread_count(dqlite_node *n,
unsigned thread_count);

/**
* Enable or disable auto-recovery for corrupted disk files.
*
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int config__init(struct config *c,
c->disk = false;
c->voters = 3;
c->standbys = 0;
c->pool_thread_count = 4;
serial++;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct config
bool disk; /* Disk-mode or not */
int voters; /* Target number of voters */
int standbys; /* Target number of standbys */
unsigned pool_thread_count; /* Number of threads in thread pool */
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/lib/threadpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ static void pool_cleanup(pool_t *pool)
return;
}

uv_mutex_lock(&pi->mutex);
pi->exiting = true;
uv_mutex_unlock(&pi->mutex);
uv_cond_signal(&pi->planner_cond);

if (uv_thread_join(&pi->planner_thread)) {
Expand Down Expand Up @@ -458,6 +460,7 @@ static void pool_work_submit(pool_t *pool, pool_work_t *w)
}

uv_mutex_lock(&pi->mutex);
POST(!pi->exiting);
push(w->type == WT_UNORD ? u : o, &w->link);
uv_cond_signal(&pi->planner_cond);
uv_mutex_unlock(&pi->mutex);
Expand Down
15 changes: 10 additions & 5 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ int dqlite__init(struct dqlite_node *d,
rv = DQLITE_ERROR;
goto err_after_vfs_init;
}
rv = pool_init(&d->pool, &d->loop, 4, POOL_QOS_PRIO_FAIR);
rv = pool_init(&d->pool, &d->loop, d->config.pool_thread_count,
POOL_QOS_PRIO_FAIR);
if (rv != 0) {
snprintf(d->errmsg, DQLITE_ERRMSG_BUF_SIZE, "pool_init(): %s",
uv_strerror(rv));
Expand Down Expand Up @@ -212,7 +213,7 @@ void dqlite__close(struct dqlite_node *d)
// the TODO above referencing the cleanup logic without running the
// node. See https://github.com/canonical/dqlite/issues/504.

//ZZZ pool_fini(&d->pool);
pool_fini(&d->pool);
uv_loop_close(&d->loop);
raftProxyClose(&d->raft_transport);
registry__close(&d->registry);
Expand Down Expand Up @@ -547,7 +548,7 @@ static void stopCb(uv_async_t *stop)
tracef("not running or already stopped");
return;
}
//ZZZ pool_close(&d->pool);
pool_close(&d->pool);
if (d->role_management) {
rv = uv_timer_stop(&d->timer);
assert(rv == 0);
Expand Down Expand Up @@ -771,6 +772,12 @@ int dqlite_node_set_auto_recovery(dqlite_node *n, bool enabled)
return 0;
}

int dqlite_node_set_pool_thread_count(dqlite_node *n, unsigned thread_count)
{
n->config.pool_thread_count = thread_count;
return 0;
}

const char *dqlite_node_errmsg(dqlite_node *n)
{
if (n != NULL) {
Expand Down Expand Up @@ -894,8 +901,6 @@ int dqlite_node_stop(dqlite_node *d)

/* NOTE: trying to find a proper place to wait on CI */
//ZZZ sleep(3);
pool_close(&d->pool);
pool_fini(&d->pool);

rv = uv_async_send(&d->stop);
assert(rv == 0);
Expand Down

0 comments on commit 1de0d95

Please sign in to comment.