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)
| 67 | // since FlyDB currently does not support transactions, |
| 68 | // please be aware that in case of errors, already written data will persist. |
| 69 | func (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 |
| 96 | func (fds *FlyDbStore) DeleteRange(min, max uint64) error { |