Skip to content

Commit

Permalink
tool: Find command to output invalid SSTable Files
Browse files Browse the repository at this point in the history
This pr changes the `find` command to output sstables that cannot be
decoded (instead of returning an error).

Fixes: #2689
  • Loading branch information
raggar authored and jbowens committed Aug 17, 2023
1 parent 856ed36 commit 564b068
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tool/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type findT struct {
tableRefs map[base.FileNum]bool
// Map from file num to table metadata.
tableMeta map[base.FileNum]*manifest.FileMetadata
// List of error messages for SSTables that could not be decoded.
errors []string
}

func newFind(
Expand Down Expand Up @@ -146,6 +148,10 @@ func (f *findT) run(cmd *cobra.Command, args []string) {
fmt.Fprintf(stdout, " ")
formatKeyValue(stdout, f.fmtKey, f.fmtValue, &r.key, r.value)
}

for _, errorMsg := range f.errors {
fmt.Fprint(stdout, errorMsg)
}
}

// Find all of the manifests, logs, and tables in the specified directory.
Expand Down Expand Up @@ -429,7 +435,10 @@ func (f *findT) searchTables(stdout io.Writer, searchKey []byte, refs []findRef)
r, err := sstable.NewReader(readable, opts, f.comparers, f.mergers,
private.SSTableRawTombstonesOpt.(sstable.ReaderOption))
if err != nil {
return err
f.errors = append(f.errors, fmt.Sprintf("Unable to decode sstable %s, %s", f.files[fileNum], err.Error()))
// Ensure the error only gets printed once.
err = nil
return
}
defer r.Close()

Expand Down
9 changes: 9 additions & 0 deletions tool/testdata/find
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,12 @@ eee
----
000004.log
bbb-eee#10,RANGEDEL

find
testdata/find-mixed
hex:636363
--value=null
----
000002.sst
test formatter: ccc#0,SET
Unable to decode sstable find-mixed/000001.sst, pebble/table: invalid table (file size is too small)
1 change: 1 addition & 0 deletions tool/testdata/find-mixed/000001.sst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid
Binary file added tool/testdata/find-mixed/000002.sst
Binary file not shown.

0 comments on commit 564b068

Please sign in to comment.