@@ -18,6 +18,7 @@ import (
1818 "github.com/cockroachdb/pebble/internal/base"
1919 "github.com/cockroachdb/pebble/internal/binfmt"
2020 "github.com/cockroachdb/pebble/internal/bytealloc"
21+ "github.com/cockroachdb/pebble/internal/crc"
2122 "github.com/cockroachdb/pebble/internal/sstableinternal"
2223 "github.com/cockroachdb/pebble/internal/treeprinter"
2324 "github.com/cockroachdb/pebble/objstorage"
@@ -140,6 +141,24 @@ func (l *Layout) Describe(
140141 trailer , offset := make ([]byte , b .Length ), 0
141142 _ = r .blockReader .Readable ().ReadAt (ctx , trailer , int64 (b .Offset ))
142143
144+ // In all cases, we know the version is right before the magic.
145+ version := binary .LittleEndian .Uint32 (trailer [len (trailer )- magicLen - versionLen :])
146+ magicNumber := trailer [len (trailer )- magicLen :]
147+ format , err := parseTableFormat (magicNumber , version )
148+ if err != nil {
149+ panic ("Error parsing table format." )
150+ }
151+
152+ var computedChecksum uint32
153+ var encodedChecksum uint32
154+ if format >= TableFormatPebblev6 {
155+ computedChecksum = crc .CRC (0 ).
156+ Update (trailer [:checkedPebbleDBChecksumOffset ]).
157+ Update (trailer [checkedPebbleDBVersionOffset :]).
158+ Value ()
159+ encodedChecksum = binary .LittleEndian .Uint32 (trailer [checkedPebbleDBChecksumOffset :])
160+ }
161+
143162 if b .Name == "footer" {
144163 checksumType := block .ChecksumType (trailer [0 ])
145164 tpNode .Childf ("%03d checksum type: %s" , offset , checksumType )
@@ -160,22 +179,21 @@ func (l *Layout) Describe(
160179 if b .Name == "leveldb-footer" {
161180 trailing = 8
162181 }
163-
164182 offset += len (trailer ) - trailing
165- trailer = trailer [len (trailer )- trailing :]
166183
167- if b .Name == "footer" {
168- version := trailer [:4 ]
169- tpNode .Childf ("%03d version: %d" , offset , binary .LittleEndian .Uint32 (version ))
170- trailer , offset = trailer [4 :], offset + 4
184+ if format >= TableFormatPebblev6 {
185+ if computedChecksum == encodedChecksum {
186+ tpNode .Childf ("%03d footer checksum: 0x%04x" , offset - 4 , encodedChecksum )
187+ } else {
188+ tpNode .Childf ("%03d invalid footer checksum: 0x%04x, expected: 0x%04x" , offset - 4 , encodedChecksum , computedChecksum )
189+ }
171190 }
172191
173- magicNumber := trailer
192+ tpNode .Childf ("%03d version: %d" , offset , version )
193+ offset = offset + 4
174194 tpNode .Childf ("%03d magic number: 0x%x" , offset , magicNumber )
175-
176195 continue
177196 }
178-
179197 // Read the block and format it. Returns an error if we couldn't read the
180198 // block.
181199 err := func () error {
0 commit comments