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

Method GetLog

lib/datastore/boltdb.go:110–126  ·  view source on GitHub ↗

GetLog is a method on BoltDbStore that retrieves a log entry by its index

(index uint64, log *raft.Log)

Source from the content-addressed store, hash-verified

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 {
111 ds.mux.RLock()
112 defer ds.mux.RUnlock()
113 tx, err := ds.conn.Begin(false) // Start a read-only transaction
114 if err != nil {
115 return err
116 }
117 defer check(tx.Rollback)
118
119 bucket := tx.Bucket(bucketLogs) // Get the logs bucket
120 val := bucket.Get(uint64ToBytes(index)) // Retrieve the log entry by index
121
122 if val == nil {
123 return raft.ErrLogNotFound // Return an error if the log entry is not found
124 }
125 return encoding.DecodeMessagePack(val, log) // Decode the log entry and assign it to the log variable
126}
127
128// StoreLog is a method on BoltDbStore that stores a single log entry
129func (ds *BoltDbStore) StoreLog(log *raft.Log) error {

Callers

nothing calls this directly

Calls 4

DecodeMessagePackFunction · 0.92
checkFunction · 0.85
uint64ToBytesFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected