print objects in hex

This commit is contained in:
Neil Macneale IV
2025-09-17 00:37:14 +00:00
parent a8eeb51612
commit 7157fd4fcf
3 changed files with 36 additions and 6 deletions
@@ -154,8 +154,8 @@ func (cmd ArchiveInspectCmd) Exec(ctx context.Context, commandStr string, args [
debugInfo := inspector.SearchChunkDebug(objectHash)
cli.Printf("Hash: %s\n", debugInfo.Hash)
cli.Printf("Prefix: %d\n", debugInfo.Prefix)
cli.Printf("Suffix: %x\n", debugInfo.Suffix)
cli.Printf("Prefix: 0x%x\n", debugInfo.Prefix)
cli.Printf("Suffix: 0x%x\n", debugInfo.Suffix)
cli.Printf("Index reader type: %s\n", debugInfo.IndexReaderType)
cli.Printf("Chunk count: %d\n", debugInfo.ChunkCount)
cli.Printf("Possible match index: %d\n", debugInfo.PossibleMatch)
@@ -164,7 +164,7 @@ func (cmd ArchiveInspectCmd) Exec(ctx context.Context, commandStr string, args [
cli.Printf("Prefix matches found: %d\n", len(debugInfo.Matches))
for i, match := range debugInfo.Matches {
cli.Printf(" Match %d: index=%d, suffixMatch=%t, suffix=%x\n",
cli.Printf(" Match %d: index=%d, suffixMatch=%t, suffix=0x%x\n",
i, match.Index, match.SuffixMatch, match.SuffixAtIdx)
}
cli.Println()
@@ -179,7 +179,6 @@ func (cmd ArchiveInspectCmd) Exec(ctx context.Context, commandStr string, args [
if chunkInfo == nil {
cli.Printf("Object %s not found in archive\n", objectIdStr)
} else {
cli.Printf("Object ID: %s\n", objectIdStr)
cli.Printf("Compression type: %s\n", chunkInfo.CompressionType)
cli.Printf("Dictionary byte span ID: %d\n", chunkInfo.DictionaryID)
cli.Printf("Data byte span ID: %d\n", chunkInfo.DataID)
@@ -222,6 +221,7 @@ func (cmd ArchiveInspectCmd) Exec(ctx context.Context, commandStr string, args [
return 1
}
cli.Printf("Hash: %s\n", details.Hash)
cli.Printf("Prefix: 0x%x\n", details.Prefix)
cli.Printf("Suffix: 0x%x\n", details.Suffix)
cli.Printf("Dictionary ID: %d\n", details.DictionaryID)
+9
View File
@@ -16,6 +16,7 @@ package nbs
import (
"context"
"encoding/binary"
"fmt"
"github.com/dolthub/dolt/go/store/hash"
@@ -63,6 +64,7 @@ type IndexReaderDetails struct {
ChunkCount uint32
ByteSpanCount uint32
Error string
Hash string
Prefix uint64
Suffix []byte
DictionaryID uint32
@@ -235,6 +237,13 @@ func (ai *ArchiveInspector) GetIndexReaderDetails(idx uint32) *IndexReaderDetail
details.Prefix = prefix
details.Suffix = suffix[:]
// Construct the full hash from prefix and suffix
hashBytes := make([]byte, hash.ByteLen)
binary.BigEndian.PutUint64(hashBytes[:hash.PrefixLen], prefix)
copy(hashBytes[hash.PrefixLen:], suffix[:])
reconstructedHash := hash.New(hashBytes)
details.Hash = reconstructedHash.String()
// Get chunk references
dictID, dataID := ai.reader.indexReader.getChunkRef(idx)
details.DictionaryID = dictID
@@ -54,6 +54,26 @@ teardown() {
[[ "$output" =~ "not found" ]] || false
}
@test "admin-archive-inspect: object-id inspection with existing hash" {
# Use the hash we know exists at index 0
run dolt admin archive-inspect --object-id "4pguchpitq1bsb09ogaivmcstgsnbd3k" "$ARCHIVE_PATH"
[ "$status" -eq 0 ]
echo "------------------"
echo "$output"
echo "------------------"
[[ "$output" =~ "Object inspection:" ]] || false
[[ "$output" =~ "Hash: 4pguchpitq1bsb09ogaivmcstgsnbd3k" ]] || false
[[ "$output" =~ "Prefix: 0x2661e64732ee82be" ]] || false
[[ "$output" =~ "Suffix: 0x2c09c4152fd99cec3975b474" ]] || false
[[ "$output" =~ "Compression type: zstd (with dictionary" ]] || false
[[ "$output" =~ "Dictionary byte span ID: 1" ]] || false
[[ "$output" =~ "Data byte span ID: 70" ]] || false
[[ "$output" =~ "Dictionary byte span: offset=0, length=296" ]] || false
[[ "$output" =~ "Data byte span: offset=20850, length=43" ]] || false
}
@test "admin-archive-inspect: inspect-index with invalid index" {
run dolt admin archive-inspect --inspect-index "invalid" "$ARCHIVE_PATH"
[ "$status" -eq 1 ]
@@ -63,18 +83,19 @@ teardown() {
@test "admin-archive-inspect: inspect-index with valid index" {
run dolt admin archive-inspect --inspect-index "0" "$ARCHIVE_PATH"
[ "$status" -eq 0 ]
[[ "$output" =~ "Index inspection:" ]] || false
[[ "$output" =~ "Index: 0" ]] || false
[[ "$output" =~ "Index reader type: *nbs.inMemoryArchiveIndexReader" ]] || false
[[ "$output" =~ "Chunk count: 230" ]] || false
[[ "$output" =~ "Byte span count: 231" ]] || false
[[ "$output" =~ "Hash: 03fe1b95i4bqpetk2klb46devv1saqmd" ]] || false
[[ "$output" =~ "Prefix: 0xdee0ad259117ac" ]] || false
[[ "$output" =~ "Suffix: 0xbbb4152ab219aeffc3c56acd" ]] || false
}
@test "admin-archive-inspect: inspect-index with out of range index" {
run dolt admin archive-inspect --inspect-index "99999999" "$ARCHIVE_PATH"
# 230 chunks, so index 231 is out of range
run dolt admin archive-inspect --inspect-index "231" "$ARCHIVE_PATH"
[ "$status" -eq 1 ]
[[ "$output" =~ "Error: index out of range" ]] || false
}