Skip to content

OAK-12299 : precompute elementCount and currentWeight in PersistentDiskCache#3004

Open
nfsantos wants to merge 3 commits into
apache:trunkfrom
nfsantos:OAK-12299
Open

OAK-12299 : precompute elementCount and currentWeight in PersistentDiskCache#3004
nfsantos wants to merge 3 commits into
apache:trunkfrom
nfsantos:OAK-12299

Conversation

@nfsantos

@nfsantos nfsantos commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Track cache size and element count incrementally in AtomicLong fields instead of recomputing them on every stats read via directory.listFiles() and FileUtils.sizeOfDirectory(), which walked the whole cache directory. Counters are seeded from the on-disk state at startup.

…skCache

Track cache size and element count incrementally in AtomicLong fields
instead of recomputing them on every stats read via directory.listFiles()
and FileUtils.sizeOfDirectory(), which walked the whole cache directory.
Counters are seeded from the on-disk state at startup.

@joerghoh joerghoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good, just a minor nit in the tests

}

// One temp file (.part) that must NOT be counted
File temp = new File(cacheFolder, UUID.randomUUID().toString() + System.nanoTime() + ".part");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you reuse the constant TEMP_FILE_SUFFIX in PersistentDiskCache?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b9c4d24

@reschke reschke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be nice to park this until after 2.4.0.

@nfsantos

nfsantos commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Would be nice to park this until after 2.4.0.

I'm neutral on when to merge this. But maybe @joerghoh can comment on whether this change is something that would be useful to get in quickly or if it can wait. I guess this can reduce by a noticeable margin how long it takes to collect metrics from the cache.

BTW, this patch is already live in our Oak fork, so it has been running in production for a couple of months.

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.

3 participants