Skip to content

Conversation

@Higangssh
Copy link

Summary

This PR adds two new flags to the lakefs kv dump command as requested in #9857:

  • --all: Dumps all known partitions instead of just the predefined sections
  • --repo <name>: Dumps only the partition for a specific repository

Changes

  • Added --all flag to enumerate and dump all partitions from SectionMapping
  • Added --repo flag to dump a specific repository's partition using graveler
  • Added GetAllKnownPartitions() and CreateDumpWithPartitions() helper functions
  • Added unit tests for the new dump functionality

Usage

# Dump all partitions
lakefs kv dump --all

# Dump specific repository partition
lakefs kv dump --repo my-repo

# Existing behavior still works
lakefs kv dump --sections auth,pulls

Test

  • Added unit tests in pkg/kv/dump_test.go

Closes #9857

- Add --all flag to dump all known partitions
- Add --repo flag to dump specific repository partition
- Add unit tests for dump functionality

Closes treeverse#9857
@CLAassistant
Copy link

CLAassistant commented Dec 22, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added area/testing Improvements or additions to tests area/KV Improvements to the KV store implementation labels Dec 22, 2025
Copy link
Contributor

@arielshaqed arielshaqed left a comment

Choose a reason for hiding this comment

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

Thanks! Let's test it, and we'll go over now tests later.

kv - kv internal metadata
Default: all supported sections (auth, pulls, kv)`,
Default: all supported sections (auth, pulls, kv)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's now avoid the word "all" here, given that it's but the same as the flag.

var dump *kv.DumpFormat

// Handle different dump modes
if allFlag {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be easier for me to read as a switch statement.

var repoData graveler.RepositoryData
_, err := kv.GetMsg(ctx, kvStore, graveler.RepositoriesPartition(), []byte(repoPath), &repoData)
if err != nil {
if errors.Is(err, kv.ErrNotFound) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use just errors.Is , which is false for nil. This style is used throughout lakeFS.


func TestCreateDumpWithPartitions(t *testing.T) {
ctx := t.Context()
store := kvtest.GetStore(ctx, t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Surprised this works tbh, cool!

dump, err := kv.CreateDumpWithPartitions(ctx, store, []string{"partition1", "partition2"})
require.NoError(t, err)
require.NotNil(t, dump)
require.Len(t, dump.Entries, 3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you verify the returned values?

- Fix duplicate graveler import
- Use static error variables for linter compliance
- Refactor if/else to switch statement
- Simplify error handling with errors.Is pattern
- Add value verification in dump tests
@Higangssh
Copy link
Author

Hi @arielshaqed, thanks for taking the time to review!

I've pushed a new commit addressing your feedback:

  • Changed "all supported sections" to "supported sections" to avoid confusion with the --all flag
  • Refactored the conditional logic to a switch statement
  • Simplified error handling with errors.Is
  • Added static error variables (fixes linter errors too)
  • Added value verification in the tests

Let me know if there's anything else I should change!

Copy link
Contributor

@arielshaqed arielshaqed left a comment

Choose a reason for hiding this comment

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

Thanks! I'll get CI to pass (but please go over my comments) and then pull.

pkg/kv/dump.go Outdated
"kv": {"kv-internal-metadata"}, // kv internal metadata
}

// GetAllKnownPartitions returns all partitions defined in SectionMapping
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? CreateDump still tests len(partitions) == 0 and collects all known partitions.

Comment on lines 24 to 29
require.Equal(t, len(expectedPartitions), len(partitions), "should return all unique partitions")

for _, partition := range partitions {
require.True(t, expectedPartitions[partition], "partition %s should be in expected list", partition)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

- Use CreateDump with empty sections for --all flag
- Remove redundant GetAllKnownPartitions function and test
- Fix gofmt formatting
@Higangssh
Copy link
Author

Hi @arielshaqed, I've addressed your comments:

  • Removed GetAllKnownPartitions and now using CreateDump with empty sections instead
  • Removed the redundant test as well

Thanks again for the helpful feedback!

@arielshaqed
Copy link
Contributor

One last question - have you run it to see that it works (beyond unit tests, which are all well and good but...)?

@arielshaqed arielshaqed added area/UI Improvements or additions to UI include-changelog PR description should be included in next release changelog labels Dec 30, 2025
@Higangssh
Copy link
Author

Yes! I've tested it locally using quickstart mode:

  • lakefs kv dump --quickstart → outputs JSON correctly
  • lakefs kv dump --all --quickstart --pretty → works with pretty formatting
  • lakefs kv dump --repo non-existent --quickstart → returns proper error message

All flags work as expected. The dump is empty since quickstart has no data,
but the command execution and output format are correct

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

Labels

area/KV Improvements to the KV store implementation area/testing Improvements or additions to tests area/UI Improvements or additions to UI include-changelog PR description should be included in next release changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dump repo partition and _all_ partitions in lakefs kv dump

3 participants