Skip to content

Commit

Permalink
Schedule: print min and max available shreds
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Oct 3, 2023
1 parent 573770b commit 91a6f52
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pkg/blockstore/meta_rocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package blockstore

import (
"encoding/binary"
"fmt"
"math"

Expand Down Expand Up @@ -46,6 +47,82 @@ func (d *DB) MinRoot() (uint64, error) {
return slot, nil
}

func (d *DB) MinShred() (uint64, uint64, shred.Shred, error) {
opts := grocksdb.NewDefaultReadOptions()
opts.SetVerifyChecksums(false)
opts.SetFillCache(false)
iter := d.DB.NewIteratorCF(opts, d.CfDataShred)
defer iter.Close()
iter.SeekToFirst()
for iter.Valid() {
var curSlot, index uint64
valid := iter.Valid()
if valid {
key := iter.Key().Data()
if len(key) != 16 {
iter.Next()
continue
}
curSlot = binary.BigEndian.Uint64(key)
index = binary.BigEndian.Uint64(key[8:])
}
s, err := parseShredAnyVersion(iter.Value().Data())
if err != nil {
iter.Next()
continue
}
if !s.Ok() {
iter.Next()
continue
}
return curSlot, index, s, nil
}
return 0, 0, shred.Shred{}, ErrNotFound
}

func (d *DB) MaxShred() (uint64, uint64, shred.Shred, error) {
opts := grocksdb.NewDefaultReadOptions()
opts.SetVerifyChecksums(false)
opts.SetFillCache(false)
iter := d.DB.NewIteratorCF(opts, d.CfDataShred)
defer iter.Close()
iter.SeekToLast()
for iter.Valid() {
var curSlot, index uint64
valid := iter.Valid()
if valid {
key := iter.Key().Data()
if len(key) != 16 {
iter.Prev()
continue
}
curSlot = binary.BigEndian.Uint64(key)
index = binary.BigEndian.Uint64(key[8:])
}
s, err := parseShredAnyVersion(iter.Value().Data())
if err != nil {
iter.Prev()
continue
}
if !s.Ok() {
iter.Prev()
continue
}
return curSlot, index, s, nil
}
return 0, 0, shred.Shred{}, ErrNotFound
}

func parseShredAnyVersion(data []byte) (shred.Shred, error) {
for _, revision := range []int{shred.RevisionV1, shred.RevisionV2} {
s := shred.NewShredFromSerialized(data, revision)
if s.Ok() {
return s, nil
}
}
return shred.Shred{}, fmt.Errorf("failed to deserialize shred")
}

// MaxMaybeRootedValidSlot returns the last valid slot, either rooted or having meta and entries.
func (d *DB) MaxMaybeRootedValidSlot() (uint64, error) {
opts := grocksdb.NewDefaultReadOptions()
Expand Down
16 changes: 16 additions & 0 deletions pkg/blockstore/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,22 @@ func (schedule *TraversalSchedule) init(
msg += fmt.Sprintf(" MaxMaybeRootedValidSlot=%d", slot)
}
}
{
shredSlot, shredIndex, _, err := h.DB.MinShred()
if err != nil {
msg += fmt.Sprintf(" MinShred=error(%s)", err)
} else {
msg += fmt.Sprintf(" MinShred=%d/%d", shredSlot, shredIndex)
}
}
{
shredSlot, shredIndex, _, err := h.DB.MaxShred()
if err != nil {
msg += fmt.Sprintf(" MaxShred=error(%s)", err)
} else {
msg += fmt.Sprintf(" MaxShred=%d/%d", shredSlot, shredIndex)
}
}
klog.Info(msg)
}
}
Expand Down

0 comments on commit 91a6f52

Please sign in to comment.