Skip to content

Helper files for flatKV cache#3056

Open
cody-littley wants to merge 5 commits intomainfrom
cjl/cache-auxilery
Open

Helper files for flatKV cache#3056
cody-littley wants to merge 5 commits intomainfrom
cjl/cache-auxilery

Conversation

@cody-littley
Copy link
Contributor

Describe your changes and provide context

These are helper files for the FlatKV cache. Not general purpose utilities, but also not the core cache implementation.

Testing performed to validate your change

Tested in main branch (unit tests, benchmark, etc)

@github-actions
Copy link

github-actions bot commented Mar 11, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 12, 2026, 2:10 PM

@github-actions
Copy link

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 11, 2026, 5:43 PM

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 97.36842% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.38%. Comparing base (8724492) to head (5c46647).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/db_engine/pebbledb/pebblecache/cache.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3056      +/-   ##
==========================================
+ Coverage   58.28%   58.38%   +0.09%     
==========================================
  Files        2072     2083      +11     
  Lines      171414   171162     -252     
==========================================
+ Hits        99909    99929      +20     
+ Misses      62584    62299     -285     
- Partials     8921     8934      +13     
Flag Coverage Δ
sei-chain-pr 97.36% <97.36%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-db/db_engine/pebbledb/pebblecache/lru_queue.go 100.00% <100.00%> (ø)
...ei-db/db_engine/pebbledb/pebblecache/noop_cache.go 100.00% <100.00%> (ø)
...db/db_engine/pebbledb/pebblecache/shard_manager.go 100.00% <100.00%> (ø)
sei-db/db_engine/types/types.go 100.00% <100.00%> (ø)
sei-db/db_engine/pebbledb/pebblecache/cache.go 0.00% <0.00%> (ø)

... and 249 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

IsDelete bool
}

// Cache describes a cache kapable of being used by a FlatKV store.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: capable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

lru.totalSize += size
}

// Signal that an entry has been interated with, moving it to the to the back of the queue
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: interacted, double to the

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


// A utility for assigning keys to shard indices.
type shardManager struct {
// A random seed that makmes it hard for an attacker to predict the shard index and to skew the distribution.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: makes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


// Shard returns a shard index in [0, numShards).
// addr should be the raw address bytes (e.g., 20-byte ETH address).
func (s *shardManager) Shard(addr []byte) uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest adding unit testings for shard_manager.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

func (s *shardManager) Shard(addr []byte) uint64 {
h := s.pool.Get().(*maphash.Hash)
h.SetSeed(s.seed)
h.Reset()
Copy link
Contributor

Choose a reason for hiding this comment

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

curious how does the h.SetSeed(s.seed) then h.Resest() next line work work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

h.Reset() doesn't remove the seed, it just removes the accumulated digest. But digging deeper into the implementation, it looks like h.SetSeed() also removes any accumulated digest, so this call was redundant. Removed.


// Creates a new Sharder. Number of shards must be a power of two and greater than 0.
func NewShardManager(numShards uint64) (*shardManager, error) {
if numShards <= 0 || (numShards&(numShards-1)) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, numShards == 0 for uint64

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

// Create a new LRU queue.
func NewLRUQueue() *lruQueue {
Copy link
Contributor

Choose a reason for hiding this comment

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

Exported constructor returns unexported type lru_queue.go, shard_manager.go

NewLRUQueue() and NewShardManager() are exported but return unexported types. Since both are internal, how about unexport the constructors: newLRUQueue, newShardManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

constructors are no longer exported

key []byte,
// the size of the key + value
size int,
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Push() accepts negative values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed type to uint64

if err != nil {
keys[k] = types.BatchGetResult{Error: err}
} else {
keys[k] = types.BatchGetResult{Value: val, Found: found}
Copy link
Contributor

Choose a reason for hiding this comment

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

looks the error result is silently swallow 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 so that if any of the get calls fail, then this entire method returns an error. Should simplify caller logic (they won't have to scan the entire map before using the results).

// The key to update.
Key []byte
// The value to set. If nil, the key will be deleted.
Value []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

in the comment, when the value is nil, the key will be deleted. with this, do we still ned IsDelete ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, simplified

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants