Skip to content

Conversation

@kim
Copy link
Contributor

@kim kim commented Jan 7, 2026

This is the second step to make in-memory-only databases not touch the disk at all.

While at it, also make it so file-backed module logs are streamed in constant memory where possible.

Depends-on: #3912

Expected complexity level and risk

2

Testing

Added some unit-level tests.

@kim kim requested review from coolreader18 and gefjon January 7, 2026 10:45
@kim kim force-pushed the kim/in-memory-module-logs branch from 3e71368 to fe02d88 Compare January 7, 2026 11:46
@kim kim changed the base branch from master to kim/move-lockfile January 7, 2026 11:47
@kim kim force-pushed the kim/in-memory-module-logs branch 2 times, most recently from fa8fb90 to 5c76b8e Compare January 7, 2026 17:53
@kim kim force-pushed the kim/move-lockfile branch from 41ec927 to ae2e579 Compare January 7, 2026 19:19
@kim kim force-pushed the kim/in-memory-module-logs branch from 5c76b8e to 9ce1579 Compare January 7, 2026 19:21
.map(Ok::<_, std::convert::Infallible>);
let Some(host) = worker_ctx.leader(database.id).await.map_err(log_and_500)? else {
if follow {
return Err((StatusCode::NOT_FOUND, "Host not running, cannot follow logs").into());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a misleading error message. My reading of the doc comment on NodeDelegate::leader is that it will spawn the host if necessary, and will only return None for databases whose leader is not assigned to this node. (I am unsure of the interaction with in-memory databases, if that's relevant in this path.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm you're right. This has been incorrect before because it isn't considered that this might be the right host to read disk-backed module logs from, but the database is not running (e.g. because it is suspended, or currently bootstrapping).

For now, I'll revert to return 404 with the message of the get_leader_replica_by_database call above, and remove that call as it is redundant.
I'll come up with a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kim kim force-pushed the kim/in-memory-module-logs branch from 2be2fd8 to 1486274 Compare January 8, 2026 07:29
Base automatically changed from kim/move-lockfile to master January 8, 2026 09:29
@kim kim force-pushed the kim/in-memory-module-logs branch from 1486274 to 87525f8 Compare January 8, 2026 10:22
// Cap reading the tail into memory at a few hundred KiB.
let n = n.min(2500);
let (tail, more) = {
let inner = self.inner.lock_arc();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems questionable to me - won't this block if another thread is in the process of doing the sync_data() call below?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to do this we should just make it an async mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to do this if we don't want to serve duplicate log lines.

Using an async mutex doesn't work, though, as we are calling DatabaseLogger:write from within an async context virtually everywhere. I guess we always had a problem with blocking here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it to use message-passing. PTAL

@kim kim force-pushed the kim/in-memory-module-logs branch 3 times, most recently from a16cf24 to c7ad80b Compare January 9, 2026 13:47
@kim kim force-pushed the kim/in-memory-module-logs branch 2 times, most recently from edb5dc8 to 38524a5 Compare January 9, 2026 14:53
This is the second step to make in-memory-only databases not touch the disk
at all.

While at it, also make it so file-backed module logs are streamed in
constant memory where possible.

Co-authored-by: Phoebe Goldman <[email protected]>
Signed-off-by: Kim Altintop <[email protected]>
@kim kim force-pushed the kim/in-memory-module-logs branch from 38524a5 to 84ff62d Compare January 9, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants