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

Method StoreLogs

lib/datastore/rocksdb.go:76–99  ·  view source on GitHub ↗

StoreLogs is a method on RocksDbStore that stores multiple log entries

(logs []*raft.Log)

Source from the content-addressed store, hash-verified

74
75// StoreLogs is a method on RocksDbStore that stores multiple log entries
76func (rds *RocksDbStore) StoreLogs(logs []*raft.Log) error {
77 wo := gorocksdb.NewDefaultWriteOptions()
78 wb := gorocksdb.NewWriteBatch()
79 wo.SetSync(true)
80 defer func() {
81 wo.Destroy()
82 wb.Destroy()
83 }()
84 for _, log := range logs {
85 var (
86 key []byte
87 val []byte
88 )
89 key = uint64ToBytes(log.Index) // Convert the index to bytes
90 val, err := encoding.EncodeMessagePack(log) // Encode the log entry
91 if err != nil {
92 return err
93 }
94 wb.Put(key, val)
95
96 }
97
98 return rds.conn.Write(wo, wb) // Commit the transaction
99}
100
101// DeleteRange is a method on RocksDbStore that deletes a range of log entries
102func (rds *RocksDbStore) DeleteRange(min, max uint64) error {

Callers 1

StoreLogMethod · 0.95

Calls 5

PutMethod · 0.95
EncodeMessagePackFunction · 0.92
uint64ToBytesFunction · 0.85
NewWriteBatchMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected