Skip to content

Commit

Permalink
Merge pull request #367 from freeekanayaka/remove-legacy-done-field-i…
Browse files Browse the repository at this point in the history
…n-leader-exec-struct

Remove the legacy "done" field from struct exec
  • Loading branch information
Mathieu Borderé authored Apr 26, 2022
2 parents 54d8a0b + db8b715 commit 35b5418
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/leader.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#include "tracing.h"
#include "vfs.h"

static void maybeExecDone(struct exec *req)
/* Called when a leader exec request terminates and the associated callback can
* be invoked. */
static void leaderExecDone(struct exec *req)
{
if (!req->done) {
return;
}
req->leader->exec = NULL;
if (req->cb != NULL) {
req->cb(req, req->status);
Expand Down Expand Up @@ -134,9 +133,8 @@ void leader__close(struct leader *l)
/* TODO: there shouldn't be any ongoing exec request. */
if (l->exec != NULL) {
assert(l->inflight == NULL);
l->exec->done = true;
l->exec->status = SQLITE_ERROR;
maybeExecDone(l->exec);
leaderExecDone(l->exec);
}
rc = sqlite3_close(l->conn);
assert(rc == 0);
Expand Down Expand Up @@ -273,8 +271,7 @@ static void leaderApplyFramesCb(struct raft_apply *req,
finish:
l->inflight = NULL;
l->db->tx_id = 0;
l->exec->done = true;
maybeExecDone(l->exec);
leaderExecDone(l->exec);
}

static int leaderApplyFrames(struct exec *req,
Expand Down Expand Up @@ -364,12 +361,11 @@ static void leaderExecV2(struct exec *req)
return;

finish:
l->exec->done = true;
if (rv != 0) {
tracef("exec v2 failed %d", rv);
l->exec->status = rv;
}
maybeExecDone(l->exec);
leaderExecDone(l->exec);
}

static void execBarrierCb(struct barrier *barrier, int status)
Expand All @@ -378,9 +374,8 @@ static void execBarrierCb(struct barrier *barrier, int status)
struct exec *req = barrier->data;
struct leader *l = req->leader;
if (status != 0) {
l->exec->done = true;
l->exec->status = status;
maybeExecDone(l->exec);
leaderExecDone(l->exec);
return;
}
leaderExecV2(req);
Expand All @@ -402,7 +397,6 @@ int leader__exec(struct leader *l,
req->leader = l;
req->stmt = stmt;
req->cb = cb;
req->done = false;
req->barrier.data = req;
req->barrier.cb = NULL;

Expand Down
1 change: 0 additions & 1 deletion src/leader.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct exec
struct leader *leader;
struct barrier barrier;
sqlite3_stmt *stmt;
bool done;
int status;
queue queue;
exec_cb cb;
Expand Down

0 comments on commit 35b5418

Please sign in to comment.