add snapshot
This commit is contained in:
3
etcd.go
3
etcd.go
@ -234,6 +234,7 @@ func main() {
|
|||||||
|
|
||||||
// Create etcd key-value store
|
// Create etcd key-value store
|
||||||
etcdStore = store.CreateStore(maxSize)
|
etcdStore = store.CreateStore(maxSize)
|
||||||
|
snapConf = newSnapshotConf()
|
||||||
|
|
||||||
startRaft(raftTLSConfig)
|
startRaft(raftTLSConfig)
|
||||||
|
|
||||||
@ -346,7 +347,7 @@ func startRaft(tlsConfig TLSConfig) {
|
|||||||
|
|
||||||
// open the snapshot
|
// open the snapshot
|
||||||
if snapshot {
|
if snapshot {
|
||||||
go raftServer.Snapshot()
|
go monitorSnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// start to response to raft requests
|
// start to response to raft requests
|
||||||
|
@ -109,6 +109,7 @@ func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
|
|||||||
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
|
||||||
if raftServer.State() == "leader" {
|
if raftServer.State() == "leader" {
|
||||||
if body, err := raftServer.Do(c); err != nil {
|
if body, err := raftServer.Do(c); err != nil {
|
||||||
|
|
||||||
if _, ok := err.(store.NotFoundError); ok {
|
if _, ok := err.(store.NotFoundError); ok {
|
||||||
(*w).WriteHeader(http.StatusNotFound)
|
(*w).WriteHeader(http.StatusNotFound)
|
||||||
(*w).Write(newJsonError(100, err.Error()))
|
(*w).Write(newJsonError(100, err.Error()))
|
||||||
|
@ -18,8 +18,16 @@ type EtcdStats struct {
|
|||||||
TestAndSets uint64 `json:"testAndSets"`
|
TestAndSets uint64 `json:"testAndSets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stats returns the basic statistics information of etcd storage
|
// Stats returns the basic statistics information of etcd storage since its recent start
|
||||||
func (s *Store) Stats() []byte {
|
func (s *Store) Stats() []byte {
|
||||||
b, _ := json.Marshal(s.BasicStats)
|
b, _ := json.Marshal(s.BasicStats)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalWrites returns the total write operations
|
||||||
|
// It helps with snapshot
|
||||||
|
func (s *Store) TotalWrites() uint64 {
|
||||||
|
bs := s.BasicStats
|
||||||
|
|
||||||
|
return bs.Deletes + bs.Sets + bs.TestAndSets
|
||||||
|
}
|
11
third_party/github.com/coreos/go-raft/server.go
vendored
11
third_party/github.com/coreos/go-raft/server.go
vendored
@ -1025,16 +1025,7 @@ func (s *Server) RemovePeer(name string) error {
|
|||||||
// Log compaction
|
// Log compaction
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
|
|
||||||
// The background snapshot function
|
func (s *Server) TakeSnapshot() error {
|
||||||
func (s *Server) Snapshot() {
|
|
||||||
for {
|
|
||||||
// TODO: change this... to something reasonable
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
s.takeSnapshot()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) takeSnapshot() error {
|
|
||||||
//TODO put a snapshot mutex
|
//TODO put a snapshot mutex
|
||||||
s.debugln("take Snapshot")
|
s.debugln("take Snapshot")
|
||||||
if s.currentSnapshot != nil {
|
if s.currentSnapshot != nil {
|
||||||
|
Reference in New Issue
Block a user