Skip to content

ChunkCache drops a dirty chunk if saving it during eviction fails #372

Open

Description

@Francy2009

I was reading ChunkCache while working on #370 and noticed this:

try {
    chunkSaver.save(index, chunk);
} catch (IOException | NonWritableChannelException e) {
    exceptionsDuringWrite.add(e);
}
bufferPool.recycle(chunk.data());

By the time this runs the chunk is already out of the cache, so if the save fails there is nothing left to retry. The exception is recorded and surfaces later in force(), but the data is gone, and the write() that produced it had already returned, so from the caller's side it looks written.

The cache holds at most five idle chunks (MAX_CACHED_CLEARTEXT_CHUNKS), so writing a file with more chunks evicts dirty ones as a matter of course. A transient ENOSPC or EIO at the wrong moment is enough.

I have not tried to reproduce it. It needs the save to fail exactly during eviction, so I guess it takes fault injection rather than a real filesystem.

It also does not look like a one-liner: the listener runs inside Caffeine's eviction (.executor(Runnable::run)), so re-inserting from there would just evict again. Keeping failed chunks in a side map drained by flush(), or keeping dirty chunks out of eviction altogether, both seem plausible.

Happy to take this if you think it is worth fixing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions