MCPcopy
hub / github.com/etcd-io/bbolt / TestFindPathsToKey_MultipleBuckets

Function TestFindPathsToKey_MultipleBuckets

internal/surgeon/xray_test.go:90–128  ·  view source on GitHub ↗

TestFindPathsToKey_MultipleBuckets ensures the shared visited map in traverse does not suppress legitimate paths when the same key appears in more than one bucket. Each top-level bucket owns a disjoint page sub-tree, so both occurrences of the key must be returned.

(t *testing.T)

Source from the content-addressed store, hash-verified

88// in more than one bucket. Each top-level bucket owns a disjoint page
89// sub-tree, so both occurrences of the key must be returned.
90func TestFindPathsToKey_MultipleBuckets(t *testing.T) {
91 sharedKey := []byte("shared")
92 bucketA := []byte("bucketA")
93 bucketB := []byte("bucketB")
94
95 db := btesting.MustCreateDB(t)
96 // Fill each bucket with enough entries that it owns a real (non-inline)
97 // root page and its own leaf pages, so the shared key lands on a pgid
98 // the visited map actually tracks.
99 require.NoError(t, db.Update(func(tx *bbolt.Tx) error {
100 for _, name := range [][]byte{bucketA, bucketB} {
101 b, err := tx.CreateBucket(name)
102 require.NoError(t, err)
103 for i := 0; i < 500; i++ {
104 k := []byte(fmt.Sprintf("%04d", i))
105 require.NoError(t, b.Put(k, make([]byte, 100)))
106 }
107 require.NoError(t, b.Put(sharedKey, []byte("v")))
108 }
109 return nil
110 }))
111 require.NoError(t, db.Close())
112
113 paths, err := surgeon.NewXRay(db.Path()).FindPathsToKey(sharedKey)
114 require.NoError(t, err)
115 require.Len(t, paths, 2, "expected one path per bucket containing the shared key")
116
117 leafPgids := make(map[common.Pgid]struct{})
118 for _, p := range paths {
119 require.NotEmpty(t, p)
120 leaf := p[len(p)-1]
121 leafPgids[leaf] = struct{}{}
122
123 page, _, err := guts_cli.ReadPage(db.Path(), uint64(leaf))
124 require.NoError(t, err)
125 require.True(t, page.IsLeafPage(), "terminal page in stack must be a leaf")
126 }
127 require.Len(t, leafPgids, 2, "the two paths must terminate on distinct leaf pages")
128}
129
130func TestFindPathsToKey_Bucket(t *testing.T) {
131 rootBucket := []byte("data")

Callers

nothing calls this directly

Calls 11

MustCreateDBFunction · 0.92
NewXRayFunction · 0.92
ReadPageFunction · 0.92
UpdateMethod · 0.80
FindPathsToKeyMethod · 0.80
IsLeafPageMethod · 0.80
CreateBucketMethod · 0.45
PutMethod · 0.45
CloseMethod · 0.45
PathMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected