-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test routine to allow tests to easily read all points/rangedels/rangekeys from an sstable.
- Loading branch information
1 parent
1210811
commit bc2d51c
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use | ||
// of this source code is governed by a BSD-style license that can be found in | ||
// the LICENSE file. | ||
|
||
package testutils | ||
|
||
// CheckErr can be used to simplify test code that expects no errors. | ||
// Instead of: | ||
// | ||
// v, err := SomeFunc() | ||
// if err != nil { .. } | ||
// | ||
// we can use: | ||
// | ||
// v := testutils.CheckErr(someFunc()) | ||
func CheckErr[V any](v V, err error) V { | ||
if err != nil { | ||
panic(err) | ||
} | ||
return v | ||
} | ||
|
||
// CheckErr2 can be used to simplify test code that expects no errors. | ||
// Instead of: | ||
// | ||
// v, w, err := SomeFunc() | ||
// if err != nil { .. } | ||
// | ||
// we can use: | ||
// | ||
// v, w := testutils.CheckErr2(someFunc()) | ||
func CheckErr2[V any, W any](v V, w W, err error) (V, W) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
return v, w | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use | ||
// of this source code is governed by a BSD-style license that can be found in | ||
// the LICENSE file. | ||
|
||
package sstable | ||
|
||
import ( | ||
"github.com/cockroachdb/pebble/internal/base" | ||
"github.com/cockroachdb/pebble/internal/keyspan" | ||
"github.com/cockroachdb/pebble/internal/testutils" | ||
"github.com/cockroachdb/pebble/objstorage" | ||
) | ||
|
||
// ReadAll returns all point keys, range del spans, and range key spans from an | ||
// sstable. Closes the Readable. Panics on errors. | ||
func ReadAll( | ||
r objstorage.Readable, | ||
) (points []base.InternalKV, rangeDels, rangeKeys []keyspan.Span) { | ||
reader := testutils.CheckErr(NewReader(r, ReaderOptions{})) | ||
defer reader.Close() | ||
pointIter := testutils.CheckErr(reader.NewIter(NoTransforms, nil /* lower */, nil /* upper */)) | ||
defer pointIter.Close() | ||
|
||
for kv := pointIter.First(); kv != nil; kv = pointIter.Next() { | ||
val, _ := testutils.CheckErr2(kv.Value(nil)) | ||
points = append(points, base.InternalKV{ | ||
K: kv.K.Clone(), | ||
V: base.MakeInPlaceValue(val), | ||
}) | ||
} | ||
|
||
if rangeDelIter := testutils.CheckErr(reader.NewRawRangeDelIter(NoTransforms)); rangeDelIter != nil { | ||
defer rangeDelIter.Close() | ||
for s := testutils.CheckErr(rangeDelIter.First()); s != nil; s = testutils.CheckErr(rangeDelIter.Next()) { | ||
rangeDels = append(rangeDels, s.DeepClone()) | ||
} | ||
} | ||
|
||
if rangeKeyIter := testutils.CheckErr(reader.NewRawRangeKeyIter(NoTransforms)); rangeKeyIter != nil { | ||
defer rangeKeyIter.Close() | ||
for s := testutils.CheckErr(rangeKeyIter.First()); s != nil; s = testutils.CheckErr(rangeKeyIter.Next()) { | ||
rangeKeys = append(rangeKeys, s.DeepClone()) | ||
} | ||
} | ||
return points, rangeDels, rangeKeys | ||
} |