StoreLogs is a method on RocksDbStore that stores multiple log entries
(logs []*raft.Log)
| 74 | |
| 75 | // StoreLogs is a method on RocksDbStore that stores multiple log entries |
| 76 | func (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 |
| 102 | func (rds *RocksDbStore) DeleteRange(min, max uint64) error { |
no test coverage detected