LastIndex is a method on BoltDbStore that returns the last index in the log
()
| 89 | |
| 90 | // LastIndex is a method on BoltDbStore that returns the last index in the log |
| 91 | func (ds *BoltDbStore) LastIndex() (uint64, error) { |
| 92 | tx, err := ds.conn.Begin(false) |
| 93 | if err != nil { |
| 94 | return 0, err |
| 95 | } |
| 96 | defer check(tx.Rollback) |
| 97 | var ( |
| 98 | key []byte |
| 99 | idx uint64 |
| 100 | ) |
| 101 | curs := tx.Bucket(bucketLogs).Cursor() // Get a cursor for the logs bucket |
| 102 | key, _ = curs.Last() // Retrieve the last key in the bucket |
| 103 | if key != nil { |
| 104 | idx = binary.BigEndian.Uint64(key) // Convert the key from bytes to uint64 |
| 105 | } |
| 106 | return idx, nil |
| 107 | } |
| 108 | |
| 109 | // GetLog is a method on BoltDbStore that retrieves a log entry by its index |
| 110 | func (ds *BoltDbStore) GetLog(index uint64, log *raft.Log) error { |