mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server: Move Storage interface to storage package
This commit is contained in:
parent
703df1c491
commit
d039f016c5
@ -529,7 +529,7 @@ func (b *bootstrappedRaft) newRaftNode(ss *snap.Snapshotter, wal *wal.WAL, cl *m
|
|||||||
Node: n,
|
Node: n,
|
||||||
heartbeat: b.heartbeat,
|
heartbeat: b.heartbeat,
|
||||||
raftStorage: b.storage,
|
raftStorage: b.storage,
|
||||||
storage: NewStorage(wal, ss),
|
storage: serverstorage.NewStorage(b.lg, wal, ss),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"go.etcd.io/etcd/raft/v3"
|
"go.etcd.io/etcd/raft/v3"
|
||||||
"go.etcd.io/etcd/raft/v3/raftpb"
|
"go.etcd.io/etcd/raft/v3/raftpb"
|
||||||
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
|
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
|
||||||
|
serverstorage "go.etcd.io/etcd/server/v3/storage"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ type raftNodeConfig struct {
|
|||||||
isIDRemoved func(id uint64) bool
|
isIDRemoved func(id uint64) bool
|
||||||
raft.Node
|
raft.Node
|
||||||
raftStorage *raft.MemoryStorage
|
raftStorage *raft.MemoryStorage
|
||||||
storage Storage
|
storage serverstorage.Storage
|
||||||
heartbeat time.Duration // for logging
|
heartbeat time.Duration // for logging
|
||||||
// transport specifies the transport to send and receive msgs to members.
|
// transport specifies the transport to send and receive msgs to members.
|
||||||
// Sending messages MUST NOT block. It is okay to drop messages, since
|
// Sending messages MUST NOT block. It is okay to drop messages, since
|
||||||
|
@ -12,13 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package etcdserver
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.etcd.io/etcd/raft/v3/raftpb"
|
"go.etcd.io/etcd/raft/v3/raftpb"
|
||||||
"go.etcd.io/etcd/server/v3/etcdserver/api/snap"
|
"go.etcd.io/etcd/server/v3/etcdserver/api/snap"
|
||||||
"go.etcd.io/etcd/server/v3/storage/wal"
|
"go.etcd.io/etcd/server/v3/storage/wal"
|
||||||
"go.etcd.io/etcd/server/v3/storage/wal/walpb"
|
"go.etcd.io/etcd/server/v3/storage/wal/walpb"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Storage interface {
|
type Storage interface {
|
||||||
@ -36,12 +37,13 @@ type Storage interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type storage struct {
|
type storage struct {
|
||||||
*wal.WAL
|
lg *zap.Logger
|
||||||
*snap.Snapshotter
|
s *snap.Snapshotter
|
||||||
|
w *wal.WAL
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStorage(w *wal.WAL, s *snap.Snapshotter) Storage {
|
func NewStorage(lg *zap.Logger, w *wal.WAL, s *snap.Snapshotter) Storage {
|
||||||
return &storage{w, s}
|
return &storage{lg: lg, w: w, s: s}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveSnap saves the snapshot file to disk and writes the WAL snapshot entry.
|
// SaveSnap saves the snapshot file to disk and writes the WAL snapshot entry.
|
||||||
@ -54,21 +56,33 @@ func (st *storage) SaveSnap(snap raftpb.Snapshot) error {
|
|||||||
// save the snapshot file before writing the snapshot to the wal.
|
// save the snapshot file before writing the snapshot to the wal.
|
||||||
// This makes it possible for the snapshot file to become orphaned, but prevents
|
// This makes it possible for the snapshot file to become orphaned, but prevents
|
||||||
// a WAL snapshot entry from having no corresponding snapshot file.
|
// a WAL snapshot entry from having no corresponding snapshot file.
|
||||||
err := st.Snapshotter.SaveSnap(snap)
|
err := st.s.SaveSnap(snap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// gofail: var raftBeforeWALSaveSnaphot struct{}
|
// gofail: var raftBeforeWALSaveSnaphot struct{}
|
||||||
|
|
||||||
return st.WAL.SaveSnapshot(walsnap)
|
return st.w.SaveSnapshot(walsnap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release releases resources older than the given snap and are no longer needed:
|
// Release releases resources older than the given snap and are no longer needed:
|
||||||
// - releases the locks to the wal files that are older than the provided wal for the given snap.
|
// - releases the locks to the wal files that are older than the provided wal for the given snap.
|
||||||
// - deletes any .snap.db files that are older than the given snap.
|
// - deletes any .snap.db files that are older than the given snap.
|
||||||
func (st *storage) Release(snap raftpb.Snapshot) error {
|
func (st *storage) Release(snap raftpb.Snapshot) error {
|
||||||
if err := st.WAL.ReleaseLockTo(snap.Metadata.Index); err != nil {
|
if err := st.w.ReleaseLockTo(snap.Metadata.Index); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return st.Snapshotter.ReleaseSnapDBs(snap)
|
return st.s.ReleaseSnapDBs(snap)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *storage) Save(s raftpb.HardState, ents []raftpb.Entry) error {
|
||||||
|
return st.w.Save(s, ents)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *storage) Close() error {
|
||||||
|
return st.w.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *storage) Sync() error {
|
||||||
|
return st.w.Sync()
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user