本文整理汇总了Golang中github.com/coreos/etcd/raft.IsEmptyHardState函数的典型用法代码示例。如果您正苦于以下问题:Golang IsEmptyHardState函数的具体用法?Golang IsEmptyHardState怎么用?Golang IsEmptyHardState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsEmptyHardState函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: logRaftReady
func (s *state) logRaftReady(readyGroups map[uint64]raft.Ready) {
for groupID, ready := range readyGroups {
if log.V(5) {
log.Infof("node %v: group %v raft ready", s.nodeID, groupID)
if ready.SoftState != nil {
log.Infof("SoftState updated: %+v", *ready.SoftState)
}
if !raft.IsEmptyHardState(ready.HardState) {
log.Infof("HardState updated: %+v", ready.HardState)
}
for i, e := range ready.Entries {
log.Infof("New Entry[%d]: %.200s", i, raft.DescribeEntry(e, s.EntryFormatter))
}
for i, e := range ready.CommittedEntries {
log.Infof("Committed Entry[%d]: %.200s", i, raft.DescribeEntry(e, s.EntryFormatter))
}
if !raft.IsEmptySnap(ready.Snapshot) {
log.Infof("Snapshot updated: %.200s", ready.Snapshot.String())
}
for i, m := range ready.Messages {
log.Infof("Outgoing Message[%d]: %.200s", i, raft.DescribeMessage(m, s.EntryFormatter))
}
}
}
}
开发者ID:huaxling,项目名称:cockroach,代码行数:25,代码来源:multiraft.go
示例2: handleWriteReady
// handleWriteReady converts a set of raft.Ready structs into a writeRequest
// to be persisted, marks the group as writing and sends it to the writeTask.
func (s *state) handleWriteReady(readyGroups map[uint64]raft.Ready) {
if log.V(6) {
log.Infof("node %v write ready, preparing request", s.nodeID)
}
writeRequest := newWriteRequest()
for groupID, ready := range readyGroups {
raftGroupID := proto.RaftID(groupID)
g, ok := s.groups[raftGroupID]
if !ok {
if log.V(6) {
log.Infof("dropping write request to group %d", groupID)
}
continue
}
g.writing = true
gwr := &groupWriteRequest{}
if !raft.IsEmptyHardState(ready.HardState) {
gwr.state = ready.HardState
}
if !raft.IsEmptySnap(ready.Snapshot) {
gwr.snapshot = ready.Snapshot
}
if len(ready.Entries) > 0 {
gwr.entries = ready.Entries
}
writeRequest.groups[raftGroupID] = gwr
}
s.writeTask.in <- writeRequest
}
开发者ID:huaxling,项目名称:cockroach,代码行数:32,代码来源:multiraft.go
示例3: start
func (n *Node) start() {
tk := time.Tick(5 * time.Millisecond)
for {
select {
case <-tk:
n.Tick()
case rd := <-n.Ready():
if !raft.IsEmptyHardState(rd.HardState) {
n.state = rd.HardState
n.storage.SetHardState(n.state)
}
n.storage.Append(rd.Entries)
n.send(rd.Messages)
if !raft.IsEmptySnap(rd.Snapshot) {
n.storage.ApplySnapshot(rd.Snapshot)
}
time.Sleep(time.Millisecond)
for _, entry := range rd.CommittedEntries {
n.process(entry)
// if entry.Type == raftpb.EntryConfChange {
// }
// var cc raftpb.ConfChange
// cc.Unmarshal(entry.Data)
// n.ApplyConfChange(cc)
}
n.Advance()
case m := <-n.receive():
n.Step(context.TODO(), m)
}
}
}
开发者ID:syhao,项目名称:sunbase,代码行数:31,代码来源:node.go
示例4: logRaftReady
func logRaftReady(storeID roachpb.StoreID, groupID roachpb.RangeID, ready raft.Ready) {
if log.V(5) {
// Globally synchronize to avoid interleaving different sets of logs in tests.
logRaftReadyMu.Lock()
defer logRaftReadyMu.Unlock()
log.Infof("store %s: group %s raft ready", storeID, groupID)
if ready.SoftState != nil {
log.Infof("SoftState updated: %+v", *ready.SoftState)
}
if !raft.IsEmptyHardState(ready.HardState) {
log.Infof("HardState updated: %+v", ready.HardState)
}
for i, e := range ready.Entries {
log.Infof("New Entry[%d]: %.200s", i, raft.DescribeEntry(e, raftEntryFormatter))
}
for i, e := range ready.CommittedEntries {
log.Infof("Committed Entry[%d]: %.200s", i, raft.DescribeEntry(e, raftEntryFormatter))
}
if !raft.IsEmptySnap(ready.Snapshot) {
log.Infof("Snapshot updated: %.200s", ready.Snapshot.String())
}
for i, m := range ready.Messages {
log.Infof("Outgoing Message[%d]: %.200s", i, raft.DescribeMessage(m, raftEntryFormatter))
}
}
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:26,代码来源:raft.go
示例5: start
func (n *node) start() {
n.stopc = make(chan struct{})
ticker := time.Tick(5 * time.Millisecond)
go func() {
for {
select {
case <-ticker:
n.Tick()
case rd := <-n.Ready():
if !raft.IsEmptyHardState(rd.HardState) {
n.state = rd.HardState
n.storage.SetHardState(n.state)
}
n.storage.Append(rd.Entries)
go func() {
for _, m := range rd.Messages {
n.iface.send(m)
}
}()
n.Advance()
case m := <-n.iface.recv():
n.Step(context.TODO(), m)
case <-n.stopc:
n.Stop()
log.Printf("raft.%d: stop", n.id)
n.Node = nil
close(n.stopc)
return
}
}
}()
}
开发者ID:CedarLogic,项目名称:arangodb,代码行数:33,代码来源:node.go
示例6: updateHardState
func updateHardState(eng engine.ReadWriter, s storagebase.ReplicaState) error {
// Load a potentially existing HardState as we may need to preserve
// information about cast votes. For example, during a Split for which
// another node's new right-hand side has contacted us before our left-hand
// side called in here to create the group.
rangeID := s.Desc.RangeID
oldHS, err := loadHardState(eng, rangeID)
if err != nil {
return err
}
newHS := raftpb.HardState{
Term: s.TruncatedState.Term,
Commit: s.RaftAppliedIndex,
}
if !raft.IsEmptyHardState(oldHS) {
if oldHS.Commit > newHS.Commit {
newHS.Commit = oldHS.Commit
}
if oldHS.Term > newHS.Term {
newHS.Term = oldHS.Term
}
newHS.Vote = oldHS.Vote
}
return setHardState(eng, rangeID, newHS)
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:28,代码来源:replica_state.go
示例7: save
// Don't call this multiple times concurrently
func (s *raftStorage) save(state raftpb.HardState, entries []raftpb.Entry) error {
wb := s.db.NewBatch()
if !raft.IsEmptyHardState(state) {
stateBytes, err := state.Marshal()
if err != nil {
return err
}
wb.Put(s.hardStateKey, stateBytes)
}
if len(entries) > 0 {
lastIndex, err := s.LastIndex()
if err != nil {
return err
}
if entries[0].Index > lastIndex+1 {
panic(fmt.Errorf("missing log entries [last: %d, append at: %d]", lastIndex, entries[0].Index))
}
// clear all old entries past the new index, if any
for ix := entries[0].Index; ix <= lastIndex; ix++ {
wb.Delete(s.getEntryKey(ix))
}
// append the new entries
for _, entry := range entries {
entryBytes, err := entry.Marshal()
if err != nil {
return err
}
wb.Put(s.getEntryKey(entry.Index), entryBytes)
}
}
err := s.db.Write(wb)
return err
}
开发者ID:yahoo,项目名称:coname,代码行数:34,代码来源:raftlog.go
示例8: saveToStorage
// HardState contains term, vote and commit.
// Snapshot contains data and snapshot metadata.
func (n *node) saveToStorage(hardState raftpb.HardState,
entries []raftpb.Entry, snapshot raftpb.Snapshot) {
if !raft.IsEmptySnap(snapshot) {
fmt.Printf("saveToStorage snapshot: %v\n", snapshot.String())
le, err := n.store.LastIndex()
if err != nil {
log.Fatalf("While retrieving last index: %v\n", err)
}
te, err := n.store.Term(le)
if err != nil {
log.Fatalf("While retrieving term: %v\n", err)
}
fmt.Printf("%d node Term for le: %v is %v\n", n.id, le, te)
if snapshot.Metadata.Index <= le {
fmt.Printf("%d node ignoring snapshot. Last index: %v\n", n.id, le)
return
}
if err := n.store.ApplySnapshot(snapshot); err != nil {
log.Fatalf("Applying snapshot: %v", err)
}
}
if !raft.IsEmptyHardState(hardState) {
n.store.SetHardState(hardState)
}
n.store.Append(entries)
}
开发者ID:dgraph-io,项目名称:experiments,代码行数:31,代码来源:main.go
示例9: logRaftReady
func logRaftReady(ctx context.Context, prefix fmt.Stringer, ready raft.Ready) {
if log.V(5) {
var buf bytes.Buffer
if ready.SoftState != nil {
fmt.Fprintf(&buf, " SoftState updated: %+v\n", *ready.SoftState)
}
if !raft.IsEmptyHardState(ready.HardState) {
fmt.Fprintf(&buf, " HardState updated: %+v\n", ready.HardState)
}
for i, e := range ready.Entries {
fmt.Fprintf(&buf, " New Entry[%d]: %.200s\n",
i, raft.DescribeEntry(e, raftEntryFormatter))
}
for i, e := range ready.CommittedEntries {
fmt.Fprintf(&buf, " Committed Entry[%d]: %.200s\n",
i, raft.DescribeEntry(e, raftEntryFormatter))
}
if !raft.IsEmptySnap(ready.Snapshot) {
fmt.Fprintf(&buf, " Snapshot updated: %.200s\n", ready.Snapshot.String())
}
for i, m := range ready.Messages {
fmt.Fprintf(&buf, " Outgoing Message[%d]: %.200s\n",
i, raft.DescribeMessage(m, raftEntryFormatter))
}
log.Infof(ctx, "%s raft ready\n%s", prefix, buf.String())
}
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:27,代码来源:raft.go
示例10: Save
func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error {
w.mu.Lock()
defer w.mu.Unlock()
// short cut, do not call sync
if raft.IsEmptyHardState(st) && len(ents) == 0 {
return nil
}
// TODO(xiangli): no more reference operator
for i := range ents {
if err := w.saveEntry(&ents[i]); err != nil {
return err
}
}
if err := w.saveState(&st); err != nil {
return err
}
fstat, err := w.f.Stat()
if err != nil {
return err
}
if fstat.Size() < segmentSizeBytes {
return w.sync()
}
// TODO: add a test for this code path when refactoring the tests
return w.cut()
}
开发者ID:rnd-ua,项目名称:scope,代码行数:29,代码来源:wal.go
示例11: Save
func (w *WAL) Save(st raftpb.HardState, ents []raftpb.Entry) error {
w.mu.Lock()
defer w.mu.Unlock()
// short cut, do not call sync
if raft.IsEmptyHardState(st) && len(ents) == 0 {
return nil
}
mustSync := mustSync(st, w.state, len(ents))
// TODO(xiangli): no more reference operator
for i := range ents {
if err := w.saveEntry(&ents[i]); err != nil {
return err
}
}
if err := w.saveState(&st); err != nil {
return err
}
curOff, err := w.tail().Seek(0, os.SEEK_CUR)
if err != nil {
return err
}
if curOff < SegmentSizeBytes {
if mustSync {
return w.sync()
}
return nil
}
// TODO: add a test for this code path when refactoring the tests
return w.cut()
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:35,代码来源:wal.go
示例12: SaveState
func (w *WAL) SaveState(s *raftpb.HardState) error {
if raft.IsEmptyHardState(*s) {
return nil
}
b := pbutil.MustMarshal(s)
rec := &walpb.Record{Type: stateType, Data: b}
return w.encoder.encode(rec)
}
开发者ID:dterei,项目名称:etcd,代码行数:8,代码来源:wal.go
示例13: handleRaftReady
func (s *state) handleRaftReady(readyGroups map[uint64]raft.Ready) {
// Soft state is updated immediately; everything else waits for handleWriteReady.
for groupID, ready := range readyGroups {
if log.V(5) {
log.Infof("node %v: group %v raft ready", s.nodeID, groupID)
if ready.SoftState != nil {
log.Infof("SoftState updated: %+v", *ready.SoftState)
}
if !raft.IsEmptyHardState(ready.HardState) {
log.Infof("HardState updated: %+v", ready.HardState)
}
for i, e := range ready.Entries {
log.Infof("New Entry[%d]: %.200s", i, raft.DescribeEntry(e, s.EntryFormatter))
}
for i, e := range ready.CommittedEntries {
log.Infof("Committed Entry[%d]: %.200s", i, raft.DescribeEntry(e, s.EntryFormatter))
}
if !raft.IsEmptySnap(ready.Snapshot) {
log.Infof("Snapshot updated: %.200s", ready.Snapshot.String())
}
for i, m := range ready.Messages {
log.Infof("Outgoing Message[%d]: %.200s", i, raft.DescribeMessage(m, s.EntryFormatter))
}
}
g, ok := s.groups[groupID]
if !ok {
// This is a stale message for a removed group
log.V(4).Infof("node %v: dropping stale ready message for group %v", s.nodeID, groupID)
continue
}
term := g.committedTerm
if ready.SoftState != nil {
// Always save the leader whenever we get a SoftState.
g.leader = NodeID(ready.SoftState.Lead)
}
if len(ready.CommittedEntries) > 0 {
term = ready.CommittedEntries[len(ready.CommittedEntries)-1].Term
}
if term != g.committedTerm && g.leader != 0 {
// Whenever the committed term has advanced and we know our leader,
// emit an event.
g.committedTerm = term
s.sendEvent(&EventLeaderElection{
GroupID: groupID,
NodeID: NodeID(g.leader),
Term: g.committedTerm,
})
// Re-submit all pending proposals
for _, prop := range g.pending {
s.proposalChan <- prop
}
}
}
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:56,代码来源:multiraft.go
示例14: writeInitialState
// writeInitialState bootstraps a new Raft group (i.e. it is called when we
// bootstrap a Range, or when setting up the right hand side of a split).
// Its main task is to persist a consistent Raft (and associated Replica) state
// which does not start from zero but presupposes a few entries already having
// applied.
// The supplied MVCCStats are used for the Stats field after adjusting for
// persisting the state itself, and the updated stats are returned.
func writeInitialState(
eng engine.ReadWriter, ms enginepb.MVCCStats, desc roachpb.RangeDescriptor,
) (enginepb.MVCCStats, error) {
rangeID := desc.RangeID
var s storagebase.ReplicaState
s.TruncatedState = &roachpb.RaftTruncatedState{
Term: raftInitialLogTerm,
Index: raftInitialLogIndex,
}
s.RaftAppliedIndex = s.TruncatedState.Index
s.Desc = &roachpb.RangeDescriptor{
RangeID: rangeID,
}
s.Stats = ms
newMS, err := saveState(eng, s)
if err != nil {
return enginepb.MVCCStats{}, err
}
// Load a potentially existing HardState as we may need to preserve
// information about cast votes. For example, during a Split for which
// another node's new right-hand side has contacted us before our left-hand
// side called in here to create the group.
oldHS, err := loadHardState(eng, rangeID)
if err != nil {
return enginepb.MVCCStats{}, err
}
newHS := raftpb.HardState{
Term: s.TruncatedState.Term,
Commit: s.TruncatedState.Index,
}
if !raft.IsEmptyHardState(oldHS) {
if oldHS.Commit > newHS.Commit {
newHS.Commit = oldHS.Commit
}
if oldHS.Term > newHS.Term {
newHS.Term = oldHS.Term
}
newHS.Vote = oldHS.Vote
}
if err := setHardState(eng, rangeID, newHS); err != nil {
return enginepb.MVCCStats{}, err
}
if err := setLastIndex(eng, rangeID, s.TruncatedState.Index); err != nil {
return enginepb.MVCCStats{}, err
}
return newMS, nil
}
开发者ID:the872,项目名称:cockroach,代码行数:62,代码来源:replica_state.go
示例15: saveToStorage
// Saves a log entry to our Store
func (n *Node) saveToStorage(hardState raftpb.HardState, entries []raftpb.Entry, snapshot raftpb.Snapshot) {
n.Store.Append(entries)
if !raft.IsEmptyHardState(hardState) {
n.Store.SetHardState(hardState)
}
if !raft.IsEmptySnap(snapshot) {
n.Store.ApplySnapshot(snapshot)
}
}
开发者ID:abronan,项目名称:proton,代码行数:12,代码来源:node.go
示例16: SaveState
func (w *WAL) SaveState(s *raftpb.HardState) error {
if raft.IsEmptyHardState(*s) {
return nil
}
b, err := s.Marshal()
if err != nil {
panic(err)
}
rec := &walpb.Record{Type: stateType, Data: b}
return w.encoder.encode(rec)
}
开发者ID:digideskio,项目名称:etcd,代码行数:11,代码来源:wal.go
示例17: SaveState
func (w *WAL) SaveState(s *raftpb.HardState) error {
if raft.IsEmptyHardState(*s) {
return nil
}
log.Printf("path=%s wal.saveState state=\"%+v\"", w.f.Name(), s)
b, err := s.Marshal()
if err != nil {
panic(err)
}
rec := &walpb.Record{Type: stateType, Data: b}
return w.encoder.encode(rec)
}
开发者ID:leandroferro,项目名称:etcd,代码行数:12,代码来源:wal.go
示例18: start
// start runs the storage loop in a goroutine.
func (w *writeTask) start(stopper *stop.Stopper) {
stopper.RunWorker(func() {
for {
var request *writeRequest
select {
case <-w.ready:
continue
case <-stopper.ShouldStop():
return
case request = <-w.in:
}
if log.V(6) {
log.Infof("writeTask got request %#v", *request)
}
response := &writeResponse{make(map[roachpb.RangeID]*groupWriteResponse)}
for groupID, groupReq := range request.groups {
group, err := w.storage.GroupStorage(groupID, groupReq.replicaID)
if err == ErrGroupDeleted {
if log.V(4) {
log.Infof("dropping write to deleted group %v", groupID)
}
continue
} else if err != nil {
log.Fatalf("GroupStorage(group %s, replica %s) failed: %s", groupID,
groupReq.replicaID, err)
}
groupResp := &groupWriteResponse{raftpb.HardState{}, -1, -1, groupReq.entries}
response.groups[groupID] = groupResp
if !raft.IsEmptyHardState(groupReq.state) {
err := group.SetHardState(groupReq.state)
if err != nil {
panic(err) // TODO(bdarnell): mark this node dead on storage errors
}
groupResp.state = groupReq.state
}
if !raft.IsEmptySnap(groupReq.snapshot) {
err := group.ApplySnapshot(groupReq.snapshot)
if err != nil {
panic(err) // TODO(bdarnell)
}
}
if len(groupReq.entries) > 0 {
err := group.Append(groupReq.entries)
if err != nil {
panic(err) // TODO(bdarnell)
}
}
}
w.out <- response
}
})
}
开发者ID:ruo91,项目名称:cockroach,代码行数:54,代码来源:storage.go
示例19: InitialState
// InitialState implements the raft.Storage interface.
// InitialState requires that the replica lock be held.
func (r *Replica) InitialState() (raftpb.HardState, raftpb.ConfState, error) {
hs, err := loadHardState(context.Background(), r.store.Engine(), r.RangeID)
// For uninitialized ranges, membership is unknown at this point.
if raft.IsEmptyHardState(hs) || err != nil {
return raftpb.HardState{}, raftpb.ConfState{}, err
}
var cs raftpb.ConfState
for _, rep := range r.mu.state.Desc.Replicas {
cs.Nodes = append(cs.Nodes, uint64(rep.ReplicaID))
}
return hs, cs, nil
}
开发者ID:yaojingguo,项目名称:cockroach,代码行数:15,代码来源:replica_raftstorage.go
示例20: handleWriteReady
// handleWriteReady converts a set of raft.Ready structs into a writeRequest
// to be persisted, marks the group as writing and sends it to the writeTask.
// It will only do this for groups which are tagged via the map.
func (s *state) handleWriteReady(checkReadyGroupIDs map[roachpb.RangeID]struct{}) map[roachpb.RangeID]raft.Ready {
if log.V(6) {
log.Infof("node %v write ready, preparing request", s.nodeID)
}
s.lockStorage()
defer s.unlockStorage()
writeRequest := newWriteRequest()
readys := make(map[roachpb.RangeID]raft.Ready)
for groupID := range checkReadyGroupIDs {
g, ok := s.groups[groupID]
if !ok {
if log.V(6) {
log.Infof("dropping write request to group %d", groupID)
}
continue
}
if !g.raftGroup.HasReady() {
continue
}
ready := g.raftGroup.Ready()
readys[groupID] = ready
g.writing = true
gwr := &groupWriteRequest{}
var err error
gwr.replicaID, err = s.Storage().ReplicaIDForStore(groupID, s.storeID)
if err != nil {
if log.V(1) {
log.Warningf("failed to look up replica ID for range %v (disabling replica ID check): %s",
groupID, err)
}
gwr.replicaID = 0
}
if !raft.IsEmptyHardState(ready.HardState) {
gwr.state = ready.HardState
}
if !raft.IsEmptySnap(ready.Snapshot) {
gwr.snapshot = ready.Snapshot
}
if len(ready.Entries) > 0 {
gwr.entries = ready.Entries
}
writeRequest.groups[groupID] = gwr
}
// If no ready, don't write to writeTask as caller will
// not wait on s.writeTask.out when len(readys) == 0.
if len(readys) > 0 {
s.writeTask.in <- writeRequest
}
return readys
}
开发者ID:haint504,项目名称:cockroach,代码行数:54,代码来源:multiraft.go
注:本文中的github.com/coreos/etcd/raft.IsEmptyHardState函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论