Skip to content

Commit

Permalink
Plumb the DB context down to the gateway
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Oct 17, 2023
1 parent 5a85583 commit 3d41a8a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ int conn__start(struct conn *c,
struct uv_stream_s *stream,
struct raft_uv_transport *uv_transport,
struct id_state seed,
conn_close_cb close_cb)
conn_close_cb close_cb,
struct db_context *db_ctx)
{
int rv;
(void)loop;
Expand All @@ -310,7 +311,7 @@ int conn__start(struct conn *c,
c->transport.data = c;
c->uv_transport = uv_transport;
c->close_cb = close_cb;
gateway__init(&c->gateway, config, registry, raft, seed);
gateway__init(&c->gateway, config, registry, raft, seed, db_ctx);
rv = buffer__init(&c->read);
if (rv != 0) {
goto err_after_transport_init;
Expand Down
3 changes: 2 additions & 1 deletion src/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ int conn__start(struct conn *c,
struct uv_stream_s *stream,
struct raft_uv_transport *uv_transport,
struct id_state seed,
conn_close_cb close_cb);
conn_close_cb close_cb,
struct db_context *db_ctx);

/**
* Force closing the connection. The close callback will be invoked when it's
Expand Down
4 changes: 3 additions & 1 deletion src/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ void gateway__init(struct gateway *g,
struct config *config,
struct registry *registry,
struct raft *raft,
struct id_state seed)
struct id_state seed,
struct db_context *db_ctx)
{
tracef("gateway init");
g->config = config;
Expand All @@ -31,6 +32,7 @@ void gateway__init(struct gateway *g,
g->protocol = DQLITE_PROTOCOL_VERSION;
g->client_id = 0;
g->random_state = seed;
g->db_ctx = db_ctx;
}

void gateway__leader_close(struct gateway *g, int reason)
Expand Down
4 changes: 3 additions & 1 deletion src/gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ struct gateway
uint64_t protocol; /* Protocol format version */
uint64_t client_id;
struct id_state random_state; /* For generating IDs */
struct db_context *db_ctx;
};

void gateway__init(struct gateway *g,
struct config *config,
struct registry *registry,
struct raft *raft,
struct id_state seed);
struct id_state seed,
struct db_context *db_ctx);

void gateway__close(struct gateway *g);

Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ static void listenCb(uv_stream_t *listener, int status)
goto err;
}
rv = conn__start(conn, &t->config, &t->loop, &t->registry, &t->raft,
stream, &t->raft_transport, seed, destroy_conn);
stream, &t->raft_transport, seed, destroy_conn, t->db_ctx);
if (rv != 0) {
goto err_after_conn_alloc;
}
Expand Down

0 comments on commit 3d41a8a

Please sign in to comment.