Skip to content

Commit

Permalink
Ensure that deleteAll() schedules a commit.
Browse files Browse the repository at this point in the history
This doesn't really matter for workerd, where the commit callback is a no-op. It matters in production, though.
  • Loading branch information
kentonv committed Sep 12, 2024
1 parent abdf88d commit cf8c335
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/workerd/io/actor-sqlite.c++
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ ActorCacheInterface::DeleteAllResults ActorSqlite::deleteAll(WriteOptions option
}
}

if (!deleteAllCommitScheduled) {
// We'll want to make sure the commit callback is called for the deleteAll().
commitTasks.add(outputGate.lockWhile(kj::evalLater([this]() mutable -> kj::Promise<void> {
// Don't commit if shutdown() has been called.
requireNotBroken();

deleteAllCommitScheduled = false;
return commitCallback();
})));
deleteAllCommitScheduled = true;
}

uint count = kv.deleteAll();
return {
.backpressure = kj::none,
Expand Down
5 changes: 4 additions & 1 deletion src/workerd/io/actor-sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ActorSqlite final: public ActorCacheInterface, private kj::TaskSet::ErrorH
Hooks& hooks = const_cast<Hooks&>(Hooks::DEFAULT));

bool isCommitScheduled() {
return !currentTxn.is<NoTxn>();
return !currentTxn.is<NoTxn>() || deleteAllCommitScheduled;
}

kj::Maybe<SqliteDatabase&> getSqliteDatabase() override {
Expand Down Expand Up @@ -157,6 +157,9 @@ class ActorSqlite final: public ActorCacheInterface, private kj::TaskSet::ErrorH
// transactions should be used in the meantime.
kj::OneOf<NoTxn, ImplicitTxn*, ExplicitTxn*> currentTxn = NoTxn();

// If true, then a commit is scheduled as a result of deleteAll() having been called.
bool deleteAllCommitScheduled = false;

kj::TaskSet commitTasks;

void onWrite();
Expand Down

0 comments on commit cf8c335

Please sign in to comment.