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 : "github.com/cockroachdb/pebble/internal/base" 9 : "github.com/cockroachdb/pebble/internal/keyspan" 10 : "github.com/cockroachdb/pebble/internal/testutils" 11 : "github.com/cockroachdb/pebble/objstorage" 12 : ) 13 : 14 : // ReadAll returns all point keys, range del spans, and range key spans from an 15 : // sstable. Closes the Readable. Panics on errors. 16 : func ReadAll( 17 : r objstorage.Readable, 18 1 : ) (points []base.InternalKV, rangeDels, rangeKeys []keyspan.Span) { 19 1 : reader := testutils.CheckErr(NewReader(r, ReaderOptions{})) 20 1 : defer reader.Close() 21 1 : pointIter := testutils.CheckErr(reader.NewIter(NoTransforms, nil /* lower */, nil /* upper */)) 22 1 : defer pointIter.Close() 23 1 : 24 1 : for kv := pointIter.First(); kv != nil; kv = pointIter.Next() { 25 0 : val, _ := testutils.CheckErr2(kv.Value(nil)) 26 0 : points = append(points, base.InternalKV{ 27 0 : K: kv.K.Clone(), 28 0 : V: base.MakeInPlaceValue(val), 29 0 : }) 30 0 : } 31 : 32 1 : if rangeDelIter := testutils.CheckErr(reader.NewRawRangeDelIter(NoTransforms)); rangeDelIter != nil { 33 1 : defer rangeDelIter.Close() 34 1 : for s := testutils.CheckErr(rangeDelIter.First()); s != nil; s = testutils.CheckErr(rangeDelIter.Next()) { 35 1 : rangeDels = append(rangeDels, s.DeepClone()) 36 1 : } 37 : } 38 : 39 1 : if rangeKeyIter := testutils.CheckErr(reader.NewRawRangeKeyIter(NoTransforms)); rangeKeyIter != nil { 40 1 : defer rangeKeyIter.Close() 41 1 : for s := testutils.CheckErr(rangeKeyIter.First()); s != nil; s = testutils.CheckErr(rangeKeyIter.Next()) { 42 1 : rangeKeys = append(rangeKeys, s.DeepClone()) 43 1 : } 44 : } 45 1 : return points, rangeDels, rangeKeys 46 : }