Line data Source code
1 : // Copyright 2024 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 : // of this source code is governed by a BSD-style license that can be found in 3 : // the LICENSE file. 4 : 5 : package sstable 6 : 7 : import ( 8 : "context" 9 : 10 : "github.com/cockroachdb/pebble/internal/base" 11 : "github.com/cockroachdb/pebble/internal/keyspan" 12 : "github.com/cockroachdb/pebble/internal/testutils" 13 : "github.com/cockroachdb/pebble/objstorage" 14 : ) 15 : 16 : // ReadAll returns all point keys, range del spans, and range key spans from an 17 : // sstable. Closes the Readable. Panics on errors. 18 : func ReadAll( 19 : r objstorage.Readable, 20 0 : ) (points []base.InternalKV, rangeDels, rangeKeys []keyspan.Span) { 21 0 : reader := testutils.CheckErr(NewReader(context.Background(), r, ReaderOptions{})) 22 0 : defer reader.Close() 23 0 : pointIter := testutils.CheckErr(reader.NewIter(NoTransforms, nil /* lower */, nil /* upper */)) 24 0 : defer pointIter.Close() 25 0 : 26 0 : for kv := pointIter.First(); kv != nil; kv = pointIter.Next() { 27 0 : val, _ := testutils.CheckErr2(kv.Value(nil)) 28 0 : points = append(points, base.InternalKV{ 29 0 : K: kv.K.Clone(), 30 0 : V: base.MakeInPlaceValue(val), 31 0 : }) 32 0 : } 33 : 34 0 : ctx := context.Background() 35 0 : if rangeDelIter := testutils.CheckErr(reader.NewRawRangeDelIter(ctx, NoFragmentTransforms)); rangeDelIter != nil { 36 0 : defer rangeDelIter.Close() 37 0 : for s := testutils.CheckErr(rangeDelIter.First()); s != nil; s = testutils.CheckErr(rangeDelIter.Next()) { 38 0 : rangeDels = append(rangeDels, s.Clone()) 39 0 : } 40 : } 41 : 42 0 : if rangeKeyIter := testutils.CheckErr(reader.NewRawRangeKeyIter(ctx, NoFragmentTransforms)); rangeKeyIter != nil { 43 0 : defer rangeKeyIter.Close() 44 0 : for s := testutils.CheckErr(rangeKeyIter.First()); s != nil; s = testutils.CheckErr(rangeKeyIter.Next()) { 45 0 : rangeKeys = append(rangeKeys, s.Clone()) 46 0 : } 47 : } 48 0 : return points, rangeDels, rangeKeys 49 : }