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

Method StoreLogs

lib/datastore/flydb.go:69–93  ·  view source on GitHub ↗

StoreLogs is a method on FlyDbStore that stores multiple log entries since FlyDB currently does not support transactions, please be aware that in case of errors, already written data will persist.

(logs []*raft.Log)

Source from the content-addressed store, hash-verified

67// since FlyDB currently does not support transactions,
68// please be aware that in case of errors, already written data will persist.
69func (fds *FlyDbStore) StoreLogs(logs []*raft.Log) error {
70
71 for _, log := range logs {
72 var (
73 key []byte
74 val []byte
75 )
76
77 key = uint64ToBytes(log.Index) // Convert the index to bytes
78 val, err := encoding.EncodeMessagePack(log) // Encode the log entry
79 if err != nil {
80 break
81 }
82 err = fds.conn.Put(key[:], val)
83 if err != nil {
84 return err
85 }
86 if log.Index > fds.lastIndex {
87 fds.lastIndex = log.Index
88 } else if log.Index < fds.firstIndex || fds.firstIndex == 0 {
89 fds.firstIndex = log.Index
90 }
91 }
92 return nil
93}
94
95// DeleteRange is a method on FlyDbStore that deletes a range of log entries
96func (fds *FlyDbStore) DeleteRange(min, max uint64) error {

Callers 15

StoreLogMethod · 0.95
TestRocksDbStore_GetLogFunction · 0.45
TestBoltDbStore_GetLogFunction · 0.45
TestInMemStore_GetLogFunction · 0.45

Calls 3

EncodeMessagePackFunction · 0.92
uint64ToBytesFunction · 0.85
PutMethod · 0.65

Tested by 15

TestRocksDbStore_GetLogFunction · 0.36
TestBoltDbStore_GetLogFunction · 0.36
TestInMemStore_GetLogFunction · 0.36