Skip to content

Commit

Permalink
Adding txid to meta surgery
Browse files Browse the repository at this point in the history
It seems advertised in the help, but it wasn't implemented yet.

Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
  • Loading branch information
tjungblu committed Feb 27, 2024
1 parent f09dcc7 commit c132ba3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit c132ba3

Please sign in to comment.