Skip to content

CacheVersion is not set correctly in JournalWriter #386

Description

@LautjeDS

Describe the bug
cacheVersion is not written to the journal correctly. An identical setup with just the cacheVersion variable changed on a FileCache and starting out from no cache saved at all, will yield two wildly different outcomes. When the version is set to one, it works perfectly. However, if it is anything but 1, each time the cache is initialized it will reset. This is because the version is not written to the journal but is indeed checked correctly on loading. Since the default version is 1 it works fine but if it is anything but 1 the cache will be reset on startup, which is intended, but since the version is not written this happens each time.

To Reproduce
Steps to reproduce the behavior:

  1. Have a FileCache with a version of anything other than 1
  2. After the cache is initialized, add an item to it (observe it is saved properly and everything seems to be working fine)
  3. Close and reopen the cache (observe it is cleared)

Expected behavior
The version number should be written to the journal and therefore checked correctly.

System (please complete the following information):

  • Device: Google Pixel 8
  • OS: Android 16

Additional context
I spent multiple hours tracking down the issue, since I thought it was my fault but, for once, it wasn't :). It comes down to the writing of the header in the journal file: the JournalWriter has a parameter called cacheVersion, which is never explicitly set and therefore always has the default value of 1. It should be a matter of setting this parameter on creation of the writer to the wanted value. This would need to happen in the following places:

  • When the OkioFileKache is opened
  • When the journal is rebuilt
  • Technically it should also be set when the JournalWriter is created in the OkioFileKache and used for entries, but since the header is not written in these cases it could be skipped

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions