Skip to content

Conversation

@arielshaqed
Copy link
Contributor

@arielshaqed arielshaqed commented Dec 14, 2025

Raised by @nopcoder in #9766.

Rather than use a home-brewed (but fast!) KV, use Badger - same as "local" - with in-memory mode.

@github-actions github-actions bot added area/gateway Changes to the gateway area/testing Improvements or additions to tests area/hooks improvements or additions to the hooks subsystem area/KV Improvements to the KV store implementation labels Dec 14, 2025
@arielshaqed arielshaqed added minor-change Used for PRs that don't require issue attached include-changelog PR description should be included in next release changelog labels Dec 14, 2025
@arielshaqed arielshaqed requested review from Copilot and nopcoder and removed request for nopcoder December 14, 2025 15:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces a custom in-memory key-value store implementation with Badger's built-in in-memory mode. The change consolidates the codebase by using the same underlying storage engine (Badger) for both local file-based and in-memory KV stores.

Key changes:

  • Removed the custom pkg/kv/mem package (store.go and store_test.go)
  • Added MemDriver to pkg/kv/local/driver.go alongside the existing LocalDriver
  • Updated all imports across the codebase from pkg/kv/mem to pkg/kv/local

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/kv/mem/store.go Deleted custom in-memory KV implementation using sortedmap
pkg/kv/mem/store_test.go Deleted tests for custom mem KV implementation
pkg/kv/local/driver.go Added MemDriver that creates Badger in-memory stores; renamed DriverName constants
pkg/kv/local/store.go Updated mutex name from driverLock to localDriverLock
pkg/kv/local/store_test.go Added TestMemKV function; updated driver name references
pkg/kv/msg_test.go Updated driver name references and added benchmark test
pkg/kv/kvtest/store.go Updated import from mem to local package
pkg/stats/usage_counter_test.go Removed unused mem import
pkg/gateway/testutil/gateway_setup.go Updated import from mem to local package
pkg/gateway/multipart/main_test.go Removed unused mem import
pkg/distributed/mc_owner_test.go Updated import from mem to local package
pkg/api/serve_test.go Updated driver name reference and import
pkg/actions/service_test.go Removed unused mem import
contrib/auth/acl/cmd/acl/cmd/run.go Removed mem import
cmd/lakefs/cmd/run.go Updated driver name references and removed mem import
cmd/lakefs/cmd/root.go Updated driver name references and removed mem import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Type: local.MemDriverName,
})
if err != nil {
t.Fatalf("failed to open kv '%s' store: %s", local.LocalDriverName, err)
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The error message uses the wrong driver name. It should use local.MemDriverName instead of local.LocalDriverName to match the driver type being tested.

Suggested change
t.Fatalf("failed to open kv '%s' store: %s", local.LocalDriverName, err)
t.Fatalf("failed to open kv '%s' store: %s", local.MemDriverName, err)

Copilot uses AI. Check for mistakes.
Comment on lines +316 to +320
b.Run("mem (run with --benchmem)", func(b *testing.B) {
source := rand.NewSource(randomGetSeed)
b.ResetTimer()
testGetMsgs(b, ctx, store, b.N, int32(b.N), source)
})
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

This benchmark test is named "mem (run with --benchmem)" but it appears to be running within the context of all driver benchmarks (mem, local, postgres, dynamoDB). The name is confusing because it suggests it's specifically for the mem driver, but it's actually nested inside each driver's benchmark loop. This benchmark should either be renamed to clarify what it's testing, or moved to the appropriate location if it's only meant for the mem driver.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +78
func (d *MemDriver) Open(ctx context.Context, _ kvparams.Config) (kv.Store, error) {
// no database open for this path
logger := logging.FromContext(ctx).WithField("store", "mem")
opts := badger.DefaultOptions("").WithInMemory(true)
opts.Logger = &BadgerLogger{logger}
db, err := badger.Open(opts)
if err != nil {
return nil, err
}
connection := &Store{
db: db,
logger: logger,
prefetchSize: memPrefetchSize,
}
connection.refCount++
return connection, nil
}
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The MemDriver creates a Store without setting the path field, which causes a problem in the Store.Close() method. When Close() is called, it attempts to delete from dbMap using s.path as the key, but since path is empty for mem stores, this will try to delete the empty string key from dbMap. Additionally, mem stores are never added to dbMap, so they shouldn't be trying to remove themselves from it. The refCount management also doesn't make sense for mem stores since each call to Open creates a new independent in-memory database. Consider either setting a unique path identifier for mem stores or having MemDriver create a different Store type that doesn't use dbMap-based lifecycle management.

Copilot uses AI. Check for mistakes.
@arielshaqed
Copy link
Contributor Author

Blocked by failing tests - #9793.

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

Labels

area/gateway Changes to the gateway area/hooks improvements or additions to the hooks subsystem area/KV Improvements to the KV store implementation area/testing Improvements or additions to tests include-changelog PR description should be included in next release changelog minor-change Used for PRs that don't require issue attached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants