mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

Snapshot takes an io.Writer and writes the entire backend data to the given writer. Snapshot writes a consistent view and does not block other storage operations. Restore restores the in-memory states (index and book keeping) of the storage from the backend data.
26 lines
497 B
Go
26 lines
497 B
Go
package storage
|
|
|
|
import "encoding/binary"
|
|
|
|
type reversion struct {
|
|
main int64
|
|
sub int64
|
|
}
|
|
|
|
func newRevBytes() []byte {
|
|
return make([]byte, 8+1+8)
|
|
}
|
|
|
|
func revToBytes(rev reversion, bytes []byte) {
|
|
binary.BigEndian.PutUint64(bytes, uint64(rev.main))
|
|
bytes[8] = '_'
|
|
binary.BigEndian.PutUint64(bytes[9:], uint64(rev.sub))
|
|
}
|
|
|
|
func bytesToRev(bytes []byte) reversion {
|
|
return reversion{
|
|
main: int64(binary.BigEndian.Uint64(bytes[0:8])),
|
|
sub: int64(binary.BigEndian.Uint64(bytes[9:])),
|
|
}
|
|
}
|