本文整理汇总了Golang中github.com/hashicorp/raft.SnapshotSink类的典型用法代码示例。如果您正苦于以下问题:Golang SnapshotSink类的具体用法?Golang SnapshotSink怎么用?Golang SnapshotSink使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SnapshotSink类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: persistIndexes
func (s *nomadSnapshot) persistIndexes(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the indexes
iter, err := s.snap.Indexes()
if err != nil {
return err
}
for {
// Get the next item
raw := iter.Next()
if raw == nil {
break
}
// Prepare the request struct
idx := raw.(*state.IndexEntry)
// Write out a node registration
sink.Write([]byte{byte(IndexSnapshot)})
if err := encoder.Encode(idx); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例2: persistEvals
func (s *nomadSnapshot) persistEvals(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the evaluations
evals, err := s.snap.Evals()
if err != nil {
return err
}
for {
// Get the next item
raw := evals.Next()
if raw == nil {
break
}
// Prepare the request struct
eval := raw.(*structs.Evaluation)
// Write out the evaluation
sink.Write([]byte{byte(EvalSnapshot)})
if err := encoder.Encode(eval); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例3: persistJobs
func (s *nomadSnapshot) persistJobs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the jobs
jobs, err := s.snap.Jobs()
if err != nil {
return err
}
for {
// Get the next item
raw := jobs.Next()
if raw == nil {
break
}
// Prepare the request struct
job := raw.(*structs.Job)
// Write out a job registration
sink.Write([]byte{byte(JobSnapshot)})
if err := encoder.Encode(job); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例4: persistTombstones
func (s *consulSnapshot) persistTombstones(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
stones, err := s.state.Tombstones()
if err != nil {
return err
}
for stone := stones.Next(); stone != nil; stone = stones.Next() {
sink.Write([]byte{byte(structs.TombstoneRequestType)})
// For historical reasons, these are serialized in the snapshots
// as KV entries. We want to keep the snapshot format compatible
// with pre-0.6 versions for now.
s := stone.(*state.Tombstone)
fake := &structs.DirEntry{
Key: s.Key,
RaftIndex: structs.RaftIndex{
ModifyIndex: s.Index,
},
}
if err := encoder.Encode(fake); err != nil {
return err
}
}
return nil
}
开发者ID:catroot,项目名称:consul,代码行数:26,代码来源:fsm.go
示例5: persistPeriodicLaunches
func (s *nomadSnapshot) persistPeriodicLaunches(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the jobs
launches, err := s.snap.PeriodicLaunches()
if err != nil {
return err
}
for {
// Get the next item
raw := launches.Next()
if raw == nil {
break
}
// Prepare the request struct
launch := raw.(*structs.PeriodicLaunch)
// Write out a job registration
sink.Write([]byte{byte(PeriodicLaunchSnapshot)})
if err := encoder.Encode(launch); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例6: Persist
func (s *consulSnapshot) Persist(sink raft.SnapshotSink) error {
// Register the nodes
encoder := codec.NewEncoder(sink, msgpackHandle)
// Write the header
header := snapshotHeader{
LastIndex: s.state.LastIndex(),
}
if err := encoder.Encode(&header); err != nil {
sink.Cancel()
return err
}
if err := s.persistNodes(sink, encoder); err != nil {
sink.Cancel()
return err
}
if err := s.persistSessions(sink, encoder); err != nil {
sink.Cancel()
return err
}
if err := s.persistACLs(sink, encoder); err != nil {
sink.Cancel()
return err
}
if err := s.persistKV(sink, encoder); err != nil {
sink.Cancel()
return err
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:34,代码来源:fsm.go
示例7: persistKV
func (s *consulSnapshot) persistKV(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
streamCh := make(chan interface{}, 256)
errorCh := make(chan error)
go func() {
if err := s.state.KVSDump(streamCh); err != nil {
errorCh <- err
}
}()
for {
select {
case raw := <-streamCh:
if raw == nil {
return nil
}
sink.Write([]byte{byte(structs.KVSRequestType)})
if err := encoder.Encode(raw); err != nil {
return err
}
case err := <-errorCh:
return err
}
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:27,代码来源:fsm.go
示例8: persistNodes
func (s *nomadSnapshot) persistNodes(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the nodes
nodes, err := s.snap.Nodes()
if err != nil {
return err
}
for {
// Get the next item
raw := nodes.Next()
if raw == nil {
break
}
// Prepare the request struct
node := raw.(*structs.Node)
// Write out a node registration
sink.Write([]byte{byte(NodeSnapshot)})
if err := encoder.Encode(node); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例9: persistAllocs
func (s *nomadSnapshot) persistAllocs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
// Get all the allocations
allocs, err := s.snap.Allocs()
if err != nil {
return err
}
for {
// Get the next item
raw := allocs.Next()
if raw == nil {
break
}
// Prepare the request struct
alloc := raw.(*structs.Allocation)
// Write out the evaluation
sink.Write([]byte{byte(AllocSnapshot)})
if err := encoder.Encode(alloc); err != nil {
return err
}
}
return nil
}
开发者ID:dgshep,项目名称:nomad,代码行数:26,代码来源:fsm.go
示例10: Persist
func (snap *masterSnapshot) Persist(sink raft.SnapshotSink) error {
data, _ := json.Marshal(snap.data)
_, err := sink.Write(data)
if err != nil {
sink.Cancel()
}
return err
}
开发者ID:abligh,项目名称:ghostfish,代码行数:8,代码来源:raft.go
示例11: Persist
// See raft.SnapshotSink.
func (m *MockSnapshot) Persist(sink raft.SnapshotSink) error {
hd := codec.MsgpackHandle{}
enc := codec.NewEncoder(sink, &hd)
if err := enc.Encode(m.logs[:m.maxIndex]); err != nil {
sink.Cancel()
return err
}
sink.Close()
return nil
}
开发者ID:pulcy,项目名称:vault-monkey,代码行数:11,代码来源:snapshot_test.go
示例12: Persist
func (fsm *fsm) Persist(sink raft.SnapshotSink) error {
fsm.Lock()
defer fsm.Unlock()
data, _ := json.Marshal(fsm)
_, err := sink.Write(data)
if err != nil {
sink.Cancel()
}
return err
}
开发者ID:justincampbell,项目名称:goflake,代码行数:11,代码来源:raft.go
示例13: Persist
func (mfsm *MyFsm) Persist(sink raft.SnapshotSink) error {
mfsm.mutex.Lock()
defer mfsm.mutex.Unlock()
var buffer bytes.Buffer
enc := gob.NewEncoder(&buffer)
enc.Encode(mfsm.data)
n, err := sink.Write(buffer.Bytes())
if err != nil {
fmt.Printf("Error in snapshotting %s\n", err)
return err
}
fmt.Printf("Snapshotted %d bytes", n)
return nil
}
开发者ID:nipuntalukdar,项目名称:NipunTalukdarExamples,代码行数:15,代码来源:raftmodule.go
示例14: persistPreparedQueries
func (s *consulSnapshot) persistPreparedQueries(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
queries, err := s.state.PreparedQueries()
if err != nil {
return err
}
for _, query := range queries {
sink.Write([]byte{byte(structs.PreparedQueryRequestType)})
if err := encoder.Encode(query); err != nil {
return err
}
}
return nil
}
开发者ID:catroot,项目名称:consul,代码行数:15,代码来源:fsm.go
示例15: persistKVs
func (s *consulSnapshot) persistKVs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
entries, err := s.state.KVs()
if err != nil {
return err
}
for entry := entries.Next(); entry != nil; entry = entries.Next() {
sink.Write([]byte{byte(structs.KVSRequestType)})
if err := encoder.Encode(entry.(*structs.DirEntry)); err != nil {
return err
}
}
return nil
}
开发者ID:catroot,项目名称:consul,代码行数:15,代码来源:fsm.go
示例16: persistSessions
func (s *consulSnapshot) persistSessions(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
sessions, err := s.state.SessionList()
if err != nil {
return err
}
for _, s := range sessions {
sink.Write([]byte{byte(structs.SessionRequestType)})
if err := encoder.Encode(s); err != nil {
return err
}
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:15,代码来源:fsm.go
示例17: persistSessions
func (s *consulSnapshot) persistSessions(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
sessions, err := s.state.Sessions()
if err != nil {
return err
}
for session := sessions.Next(); session != nil; session = sessions.Next() {
sink.Write([]byte{byte(structs.SessionRequestType)})
if err := encoder.Encode(session.(*structs.Session)); err != nil {
return err
}
}
return nil
}
开发者ID:catroot,项目名称:consul,代码行数:15,代码来源:fsm.go
示例18: persistACLs
func (s *consulSnapshot) persistACLs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
acls, err := s.state.ACLs()
if err != nil {
return err
}
for acl := acls.Next(); acl != nil; acl = acls.Next() {
sink.Write([]byte{byte(structs.ACLRequestType)})
if err := encoder.Encode(acl.(*structs.ACL)); err != nil {
return err
}
}
return nil
}
开发者ID:catroot,项目名称:consul,代码行数:15,代码来源:fsm.go
示例19: persistACLs
func (s *consulSnapshot) persistACLs(sink raft.SnapshotSink,
encoder *codec.Encoder) error {
acls, err := s.state.ACLList()
if err != nil {
return err
}
for _, s := range acls {
sink.Write([]byte{byte(structs.ACLRequestType)})
if err := encoder.Encode(s); err != nil {
return err
}
}
return nil
}
开发者ID:askagirl,项目名称:consul,代码行数:15,代码来源:fsm.go
示例20: Persist
// Persist writes a robustSnapshot to disk, i.e. handles the
// serialization details.
func (s *robustSnapshot) Persist(sink raft.SnapshotSink) error {
stateMsg := types.RobustMessage{
Type: types.RobustState,
Data: base64.StdEncoding.EncodeToString(s.state), // TODO: find a more straight-forward way to encode this
}
stateMsgJson, err := json.Marshal(&stateMsg)
if err != nil {
return err
}
stateMsgRaftJson, err := json.Marshal(&raft.Log{
Type: raft.LogCommand,
Index: 0, // never passed to raft.
Data: stateMsgJson,
})
if err != nil {
return err
}
log.Printf("Copying non-deleted messages into snapshot\n")
snapshotBytes, err := sink.Write(stateMsgRaftJson)
if err != nil {
return err
}
iterator := s.store.GetBulkIterator(s.firstIndex, s.lastIndex+1)
defer iterator.Release()
available := iterator.First()
for available {
if err := iterator.Error(); err != nil {
return err
}
n, err := sink.Write(iterator.Value())
if err != nil {
return err
}
snapshotBytes += n
available = iterator.Next()
}
log.Printf("snapshot: wrote %d bytes", snapshotBytes)
log.Printf("Snapshot done\n")
return nil
}
开发者ID:aftran,项目名称:robustirc,代码行数:47,代码来源:compaction.go
注:本文中的github.com/hashicorp/raft.SnapshotSink类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论