mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package etcdserver
|
|
|
|
import (
|
|
"github.com/coreos/etcd/raft/raftpb"
|
|
"github.com/coreos/etcd/snap"
|
|
"github.com/coreos/etcd/wal"
|
|
)
|
|
|
|
type Storage interface {
|
|
// Save function saves ents and state to the underlying stable storage.
|
|
// Save MUST block until st and ents are on stable storage.
|
|
Save(st raftpb.HardState, ents []raftpb.Entry) error
|
|
// SaveSnap function saves snapshot to the underlying stable storage.
|
|
SaveSnap(snap raftpb.Snapshot) error
|
|
|
|
// TODO: WAL should be able to control cut itself. After implement self-controlled cut,
|
|
// remove it in this interface.
|
|
// Cut cuts out a new wal file for saving new state and entries.
|
|
Cut() error
|
|
// Close closes the Storage and performs finalization.
|
|
Close() error
|
|
}
|
|
|
|
type storage struct {
|
|
*wal.WAL
|
|
*snap.Snapshotter
|
|
}
|
|
|
|
func NewStorage(w *wal.WAL, s *snap.Snapshotter) Storage {
|
|
return &storage{w, s}
|
|
}
|
|
|
|
// SaveSnap saves the snapshot to disk and release the locked
|
|
// wal files since they will not be used.
|
|
func (st *storage) SaveSnap(snap raftpb.Snapshot) error {
|
|
err := st.Snapshotter.SaveSnap(snap)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = st.WAL.ReleaseLockTo(snap.Metadata.Index)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|