MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / LastIndex

Method LastIndex

lib/datastore/boltdb.go:91–107  ·  view source on GitHub ↗

LastIndex is a method on BoltDbStore that returns the last index in the log

()

Source from the content-addressed store, hash-verified

89
90// LastIndex is a method on BoltDbStore that returns the last index in the log
91func (ds *BoltDbStore) LastIndex() (uint64, error) {
92 tx, err := ds.conn.Begin(false)
93 if err != nil {
94 return 0, err
95 }
96 defer check(tx.Rollback)
97 var (
98 key []byte
99 idx uint64
100 )
101 curs := tx.Bucket(bucketLogs).Cursor() // Get a cursor for the logs bucket
102 key, _ = curs.Last() // Retrieve the last key in the bucket
103 if key != nil {
104 idx = binary.BigEndian.Uint64(key) // Convert the key from bytes to uint64
105 }
106 return idx, nil
107}
108
109// GetLog is a method on BoltDbStore that retrieves a log entry by its index
110func (ds *BoltDbStore) GetLog(index uint64, log *raft.Log) error {

Callers

nothing calls this directly

Calls 1

checkFunction · 0.85

Tested by

no test coverage detected