當前位置: 首頁>>代碼示例>>Golang>>正文


Golang raft.Server類代碼示例

本文整理匯總了Golang中github.com/goraft/raft.Server的典型用法代碼示例。如果您正苦於以下問題:Golang Server類的具體用法?Golang Server怎麽用?Golang Server使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Server類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SendAppendEntriesRequest

// Sends an AppendEntries RPC to a peer.
func (t *HTTPTransporter) SendAppendEntriesRequest(server raft.Server, peer *raft.Peer, req *raft.AppendEntriesRequest) *raft.AppendEntriesResponse {
	var b bytes.Buffer
	if _, err := req.Encode(&b); err != nil {
		//log.Println("transporter.ae.encoding.error:", err)
		return nil
	}

	url := joinPath(peer.ConnectionString, t.AppendEntriesPath())
	//log.Println(server.Name(), "POST", url)

	//oldTimeout := t.Transport.ResponseHeaderTimeout
	t.Transport.ResponseHeaderTimeout = server.ElectionTimeout()
	httpResp, err := t.httpClient.Post(url, "application/protobuf", &b)
	if httpResp == nil || err != nil {
		//log.Println("transporter.ae.response.error:", err)
		return nil
	}
	//t.Transport.ResponseHeaderTimeout = oldTimeout
	defer httpResp.Body.Close()

	resp := &raft.AppendEntriesResponse{}
	if _, err = resp.Decode(httpResp.Body); err != nil && err != io.EOF {
		//log.Println("transporter.ae.decoding.error:", err)
		return nil
	}

	return resp
}
開發者ID:rrjamie,項目名稱:stripe-ctf-level4,代碼行數:29,代碼來源:transport.go

示例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
}
開發者ID:nettedfish,項目名稱:skydns1,代碼行數:8,代碼來源:command.go

示例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
}
開發者ID:shenlanzifa,項目名稱:weed-fs,代碼行數:10,代碼來源:cluster_commands.go

示例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
}
開發者ID:kratorius,項目名稱:stripe-ctf3,代碼行數:13,代碼來源:sqlquery_command.go

示例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
}
開發者ID:hanshenu,項目名稱:influxdb,代碼行數:12,代碼來源:command.go

示例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
}
開發者ID:rabdureh,項目名稱:influx-attempt,代碼行數:15,代碼來源:command.go

示例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
}
開發者ID:henrik-muehe,項目名稱:level4,代碼行數:17,代碼來源:command.go

示例8: snapshotRecoveryHandler

// Handles incoming SnapshotRecovery requests.
func (t *HTTPTransporter) snapshotRecoveryHandler(server raft.Server) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		//log.Println(server.Name(), "RECV /snapshotRecovery")

		req := &raft.SnapshotRecoveryRequest{}
		if _, err := req.Decode(r.Body); err != nil {
			http.Error(w, "", http.StatusBadRequest)
			return
		}

		resp := server.SnapshotRecoveryRequest(req)
		if _, err := resp.Encode(w); err != nil {
			http.Error(w, "", http.StatusInternalServerError)
			return
		}
	}
}
開發者ID:rrjamie,項目名稱:stripe-ctf-level4,代碼行數:18,代碼來源:transport.go

示例9: 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
}
開發者ID:rrjamie,項目名稱:stripe-ctf-level4,代碼行數:22,代碼來源:server.go

示例10: 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
}
開發者ID:jstanley0,項目名稱:stripe-ctf-3,代碼行數:23,代碼來源:sql_command.go

示例11: Apply

// Apply implements goraft Command interface's Apply function
// It puts a key-value pair in KVstore
func (pcmd *putCommand) Apply(server raft.Server) (interface{}, error) {
	if server.Name() == server.Leader() {
		return nil, nil
	}
	kvs := server.Context().(KVstore)
	err := kvs.Put(pcmd.Key, pcmd.Val)
	return nil, err
}
開發者ID:lilwulin,項目名稱:raftkv,代碼行數:10,代碼來源:commands.go

示例12: Apply

func (c *WriteCommand) Apply(server raft.Server) (interface{}, error) {
	db := server.Context().(*DB)
	db.Put(c.Key, c.Value)
	return nil, nil
}
開發者ID:upccup,項目名稱:cuplearn,代碼行數:5,代碼來源:command.go

示例13: Apply

func (c *UpdateServerStateCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*ClusterConfiguration)
	err := config.UpdateServerState(c.ServerId, c.State)
	return nil, err
}
開發者ID:ronaldevers,項目名稱:influxdb,代碼行數:5,代碼來源:command.go

示例14: Apply

func (c *AddPotentialServerCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	config.AddPotentialServer(c.Server)
	return nil, nil
}
開發者ID:qz267,項目名稱:influxdb,代碼行數:5,代碼來源:command.go

示例15: 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
}
開發者ID:izouxv,項目名稱:raftX,代碼行數:7,代碼來源:remove_tmp_data_command.go


注:本文中的github.com/goraft/raft.Server類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。