Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding txid to meta surgery #702

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/bbolt/command_surgery_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
metaFieldRoot = "root"
metaFieldFreelist = "freelist"
metaFieldPgid = "pgid"
metaFieldTxid = "txid"
)

func newSurgeryMetaCommand() *cobra.Command {
Expand Down Expand Up @@ -88,6 +89,7 @@ var allowedMetaUpdateFields = map[string]struct{}{
metaFieldRoot: {},
metaFieldFreelist: {},
metaFieldPgid: {},
metaFieldTxid: {},
}

// AddFlags sets the flags for `meta update` command.
Expand Down Expand Up @@ -220,6 +222,8 @@ func updateMetaField(m *common.Meta, fields map[string]uint64) bool {
m.SetFreelist(common.Pgid(val))
case metaFieldPgid:
m.SetPgid(common.Pgid(val))
case metaFieldTxid:
m.SetTxid(common.Txid(val))
}

changed = true
Expand Down
12 changes: 12 additions & 0 deletions cmd/bbolt/command_surgery_meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestSurgery_Meta_Update(t *testing.T) {
root common.Pgid
freelist common.Pgid
pgid common.Pgid
txid common.Txid
}{
{
name: "root changed",
Expand All @@ -53,6 +54,10 @@ func TestSurgery_Meta_Update(t *testing.T) {
name: "pgid changed",
pgid: 600,
},
{
name: "txid changed",
txid: 42,
},
{
name: "both root and freelist changed",
root: 45,
Expand All @@ -68,6 +73,7 @@ func TestSurgery_Meta_Update(t *testing.T) {
root: 43,
freelist: 62,
pgid: 256,
txid: 22,
},
}

Expand All @@ -93,6 +99,9 @@ func TestSurgery_Meta_Update(t *testing.T) {
if tc.pgid != 0 {
fields = append(fields, fmt.Sprintf("pgid:%d", tc.pgid))
}
if tc.txid != 0 {
fields = append(fields, fmt.Sprintf("txid:%d", tc.txid))
}

rootCmd := main.NewRootCommand()
output := filepath.Join(t.TempDir(), "db")
Expand Down Expand Up @@ -120,6 +129,9 @@ func TestSurgery_Meta_Update(t *testing.T) {
if tc.pgid != 0 {
require.Equal(t, tc.pgid, m.Pgid())
}
if tc.txid != 0 {
require.Equal(t, tc.txid, m.Txid())
}
})
}
}
Expand Down
Loading