Skip to content

Commit

Permalink
Implement server-side role management
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <cole.miller@canonical.com>
  • Loading branch information
cole-miller committed Apr 6, 2023
1 parent 1bba922 commit 02f1806
Show file tree
Hide file tree
Showing 16 changed files with 1,493 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
env:
CC: ${{ matrix.compiler }}
run: |
git clone https://github.com/canonical/raft.git --depth 1
git clone https://github.com/cole-miller/raft.git --branch transfer-clone --depth 1
cd raft
autoreconf -i
./configure --enable-debug --enable-sanitize
Expand Down
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ libdqlite_la_SOURCES = \
src/registry.c \
src/request.c \
src/response.c \
src/role_management.c \
src/server.c \
src/stmt.c \
src/tracing.c \
Expand Down Expand Up @@ -86,6 +87,7 @@ unit_test_SOURCES += \
test/unit/test_registry.c \
test/unit/test_replication.c \
test/unit/test_request.c \
test/unit/test_role_management.c \
test/unit/test_tuple.c \
test/unit/test_vfs.c \
test/unit/main.c
Expand All @@ -99,6 +101,7 @@ integration_test_SOURCES = \
test/integration/test_fsm.c \
test/integration/test_membership.c \
test/integration/test_node.c \
test/integration/test_role_management.c \
test/integration/test_vfs.c \
test/integration/main.c
integration_test_CFLAGS = $(AM_CFLAGS) -Wno-conversion
Expand Down
39 changes: 35 additions & 4 deletions include/dqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,45 @@ int dqlite_node_set_snapshot_params(dqlite_node *n, unsigned snapshot_threshold,
int dqlite_node_enable_disk_mode(dqlite_node *n);

/**
* Start a dqlite node.
* Set the target number of voting nodes for the cluster.
*
* A background thread will be spawned which will run the node's main loop. If
* this function returns successfully, the dqlite node is ready to accept new
* connections.
* If automatic role management is enabled, the cluster leader will attempt to
* promote nodes to reach the target. If automatic role management is disabled,
* this has no effect.
*
* The default target is 3 voters.
*/
int dqlite_node_set_target_voters(dqlite_node *n, int voters);

/**
* Set the target number of standby nodes for the cluster.
*
* If automatic role management is enabled, the cluster leader will attempt to
* promote nodes to reach the target. If automatic role management is disabled,
* this has no effect.
*
* The default target is 0 standbys.
*/
int dqlite_node_set_target_standbys(dqlite_node *n, int standbys);

/**
* Enable automatic role management on the server side for this node.
*
* By default, no automatic role management is performed.
*/
int dqlite_node_enable_role_management(dqlite_node *n);

/**
* Start a dqlite node.
*
* A background thread will be spawned which will run the node's main loop. If
* this function returns successfully, the dqlite node is ready to accept new
* connections.
*/
int dqlite_node_start(dqlite_node *n);

int dqlite_node_handover(dqlite_node *n);

/**
* Stop a dqlite node.
*
Expand Down
2 changes: 2 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ int config__init(struct config *c, dqlite_node_id id,
strncpy(c->dir, dir, sizeof(c->dir)-1);
c->dir[sizeof(c->dir)-1] = '\0';
c->disk = false;
c->voters = 3;
c->standbys = 0;
serial++;
return 0;
}
Expand Down
20 changes: 11 additions & 9 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
*/
struct config
{
dqlite_node_id id; /* Unique instance ID */
char *address; /* Instance address */
unsigned heartbeat_timeout; /* In milliseconds */
unsigned page_size; /* Database page size */
unsigned checkpoint_threshold; /* In outstanding WAL frames */
struct logger logger; /* Custom logger */
char name[256]; /* VFS/replication registriatio name */
dqlite_node_id id; /* Unique instance ID */
char *address; /* Instance address */
unsigned heartbeat_timeout; /* In milliseconds */
unsigned page_size; /* Database page size */
unsigned checkpoint_threshold; /* In outstanding WAL frames */
struct logger logger; /* Custom logger */
char name[256]; /* VFS/replication registriatio name */
unsigned long long failure_domain; /* User-provided failure domain */
unsigned long long int weight; /* User-provided node weight */
char dir[1024]; /* Data dir for on-disk database */
bool disk; /* Disk-mode or not */
char dir[1024]; /* Data dir for on-disk database */
bool disk; /* Disk-mode or not */
int voters; /* Target number of voters */
int standbys; /* Target number of standbys */
};

/**
Expand Down
Loading

0 comments on commit 02f1806

Please sign in to comment.