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

Method StoreLogs

lib/datastore/boltdb.go:134–157  ·  view source on GitHub ↗

StoreLogs is a method on BoltDbStore that stores multiple log entries

(logs []*raft.Log)

Source from the content-addressed store, hash-verified

132
133// StoreLogs is a method on BoltDbStore that stores multiple log entries
134func (ds *BoltDbStore) StoreLogs(logs []*raft.Log) error {
135 tx, err := ds.conn.Begin(true) // Start a read-write transaction
136 if err != nil {
137 return err
138 }
139 defer check(tx.Rollback)
140 bucket := tx.Bucket(bucketLogs)
141 for _, log := range logs {
142 var (
143 key []byte
144 val []byte
145 )
146 key = uint64ToBytes(log.Index) // Convert the index to bytes
147 val, err = encoding.EncodeMessagePack(log) // Encode the log entry
148 if err != nil {
149 break
150 }
151 err = bucket.Put(key[:], val)
152 if err != nil {
153 return err
154 }
155 }
156 return tx.Commit() // Commit the transaction
157}
158
159// DeleteRange is a method on BoltDbStore that deletes a range of log entries
160func (ds *BoltDbStore) DeleteRange(min, max uint64) error {

Callers 1

StoreLogMethod · 0.95

Calls 5

EncodeMessagePackFunction · 0.92
checkFunction · 0.85
uint64ToBytesFunction · 0.85
CommitMethod · 0.80
PutMethod · 0.65

Tested by

no test coverage detected