本文整理汇总了Golang中github.com/goraft/raft.Server.Context方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.Context方法的具体用法?Golang Server.Context怎么用?Golang Server.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/goraft/raft.Server
的用法示例。
在下文中一共展示了Server.Context方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Apply
func (dcmd *delCommand) Apply(server raft.Server) (interface{}, error) {
if server.Name() == server.Leader() {
return nil, nil
}
kvs := server.Context().(KVstore)
err := kvs.Delete(dcmd.Key)
return nil, err
}
示例2: Apply
func (c *AddCallbackCommand) Apply(server raft.Server) (interface{}, error) {
reg := server.Context().(registry.Registry)
err := reg.AddCallback(c.Service, c.Callback)
if err == nil {
log.Println("Added Callback:", c.Service, c.Callback)
}
return c.Service, err
}
示例3: Apply
//???
func (c *MaxVolumeIdCommand) Apply(server raft.Server) (interface{}, error) {
topo := server.Context().(*Topology)
before := topo.GetMaxVolumeId()
topo.UpAdjustMaxVolumeId(c.MaxVolumeId)
glog.V(4).Infoln("max volume id", before, "==>", topo.GetMaxVolumeId())
return nil, nil
}
示例4: Apply
// Writes a value to a key.
func (c *QueryCommand) Apply(server raft.Server) (interface{}, error) {
db := server.Context().(*sql.SQL)
output, err := db.CacheExec(c.Create, c.Name, c.FriendCount, c.FavoriteWord)
if err != nil {
return nil, err
}
formatted := fmt.Sprintf("SequenceNumber: %d\n%s", output.SequenceNumber, output.Output)
return []byte(formatted), nil
}
示例5: Apply
func (c *CreateShardsCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*cluster.ClusterConfiguration)
createdShards, err := config.AddShards(c.Shards)
if err != nil {
return nil, err
}
createdShardData := make([]*cluster.NewShardData, 0)
for _, s := range createdShards {
createdShardData = append(createdShardData, s.ToNewShardData())
}
return createdShardData, nil
}
示例6: Apply
func (c *SaveSubscriptionCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*cluster.ClusterConfiguration)
createdSubscription, err := config.AddSubscription(c.Subscription)
fmt.Println("we are here in command.go's Apply function")
if err != nil {
return nil, err
}
//createdSubscriptionData := make(*cluster.Subscription, 0)
//for _, s := range createdSubscription {
//createdSubscriptionData = append(createdSubscriptionData, s.ToNewSubscriptionData())
//}
//return createdSubscriptionData, nil
return createdSubscription, nil
return nil, nil
}
示例7: Apply
// Execute an SQL statement
func (c *WriteCommand) Apply(server raft.Server) (interface{}, error) {
sql := server.Context().(*sql.SQL)
job := sql.Execute(c.Query)
go func() {
output := []byte(<-job.OutChan)
seq := job.Seq
formatted := fmt.Sprintf("SequenceNumber: %d\n%s",
seq, output)
sql.Respond(c.Id, []byte(formatted))
}()
return []byte(""), nil
}
示例8: Apply
// Writes a value to a key.
func (c *BatchCommand) Apply(server raft.Server) (interface{}, error) {
//log.Printf(("Applying Batch Size: %v", len(c.Queries))
db := server.Context().(*DB)
for _, output := range db.ExecuteBatch(c.Queries) {
db.notify <- output
}
// for _, query := range c.Queries {
// output, err := db.Execute(*query)
// if err != nil {
// log.Fatal("Error applying command")
// return nil, err
// }
// db.notify <- output
// }
return nil, nil
}
示例9: Apply
// Writes a value to a key.
func (c *SqlCommand) Apply(server raft.Server) (interface{}, error) {
db := server.Context().(*sql.SQL)
output, err := db.Execute("tehrafts", inflate(c.Query))
if err != nil {
var msg string
if output != nil && len(output.Stderr) > 0 {
template := `Error executing %#v (%s)
SQLite error: %s`
msg = fmt.Sprintf(template, c.Query, err.Error(), util.FmtOutput(output.Stderr))
} else {
msg = err.Error()
}
return nil, errors.New(msg)
}
formatted := fmt.Sprintf("SequenceNumber: %d\n%s",
output.SequenceNumber, output.Stdout)
return []byte(formatted), nil
}
示例10: Apply
func (c *WriteCommand) Apply(server raft.Server) (interface{}, error) {
db := server.Context().(*DB)
db.Put(c.Key, c.Value)
return nil, nil
}
示例11: Apply
func (c *UpdateServerStateCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
err := config.UpdateServerState(c.ServerId, c.State)
return nil, err
}
示例12: Apply
func (c *AddPotentialServerCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*cluster.ClusterConfiguration)
config.AddPotentialServer(c.Server)
return nil, nil
}
示例13: Apply
// Writes a value to a key.
func (c *SetCommand) Apply(server raft.Server) (interface{}, error) {
fs := server.Context().(*db.Fs)
return fs.Apply(c.Key, c.Value, c.Verb, c.Oper)
}
示例14: Apply
// Writes a value to a key.
func (c *RemoveTmpDataCommand) Apply(server raft.Server) (interface{}, error) {
fs := server.Context().(*db.Fs)
//log.Printf("RemoveTempDataIp: %v\n", c.Key)
fs.RemoveTempData(c.Key)
return nil, nil
}