2016-05-13 06:49:15 +03:00
|
|
|
// Copyright 2015 The etcd Authors
|
2015-01-25 06:19:16 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2014-10-18 02:41:22 +04:00
|
|
|
|
2014-08-23 02:45:39 +04:00
|
|
|
package raft
|
|
|
|
|
2014-08-28 05:53:18 +04:00
|
|
|
import (
|
2019-05-29 00:59:02 +03:00
|
|
|
pb "go.etcd.io/etcd/raft/raftpb"
|
2014-08-28 05:53:18 +04:00
|
|
|
)
|
|
|
|
|
2014-09-16 04:35:02 +04:00
|
|
|
func applyToStore(ents []pb.Entry) {}
|
|
|
|
func sendMessages(msgs []pb.Message) {}
|
|
|
|
func saveStateToDisk(st pb.HardState) {}
|
|
|
|
func saveToDisk(ents []pb.Entry) {}
|
2014-08-23 02:45:39 +04:00
|
|
|
|
2015-10-21 02:39:29 +03:00
|
|
|
func ExampleNode() {
|
2015-03-24 07:19:03 +03:00
|
|
|
c := &Config{}
|
|
|
|
n := StartNode(c, nil)
|
2016-01-31 23:41:33 +03:00
|
|
|
defer n.Stop()
|
2014-08-23 02:45:39 +04:00
|
|
|
|
2014-08-24 03:06:55 +04:00
|
|
|
// stuff to n happens in other goroutines
|
2014-08-23 02:45:39 +04:00
|
|
|
|
2014-08-23 03:53:56 +04:00
|
|
|
// the last known state
|
2014-09-16 04:35:02 +04:00
|
|
|
var prev pb.HardState
|
2014-08-23 02:45:39 +04:00
|
|
|
for {
|
2016-02-01 08:42:39 +03:00
|
|
|
// Ready blocks until there is new state ready.
|
2014-08-27 02:28:21 +04:00
|
|
|
rd := <-n.Ready()
|
2014-09-17 00:55:00 +04:00
|
|
|
if !isHardStateEqual(prev, rd.HardState) {
|
2014-09-16 04:35:02 +04:00
|
|
|
saveStateToDisk(rd.HardState)
|
|
|
|
prev = rd.HardState
|
2014-08-23 02:45:39 +04:00
|
|
|
}
|
|
|
|
|
2014-08-27 03:19:49 +04:00
|
|
|
saveToDisk(rd.Entries)
|
|
|
|
go applyToStore(rd.CommittedEntries)
|
|
|
|
sendMessages(rd.Messages)
|
2014-08-23 02:45:39 +04:00
|
|
|
}
|
|
|
|
}
|