Skip to content

Commit

Permalink
remove (almost all) uses of proto.Batch
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg committed Sep 29, 2015
1 parent 0de2df2 commit fa8e0ac
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (db *DB) send(reqs ...proto.Request) (*proto.BatchResponse, *proto.Error) {
br, pErr := db.sender.Send(context.TODO(), ba)
if pErr != nil {
if log.V(1) {
log.Infof("failed %s: %s", proto.Batch, pErr)
log.Infof("failed batch: %s", pErr)
}
return nil, pErr
}
Expand Down
2 changes: 1 addition & 1 deletion client/rpc_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
RegisterSender("rpcs", f)
}

var method = fmt.Sprintf("Server.%s", proto.Batch)
const method = "Server.Batch"

// rpcSender is an implementation of Sender which exposes the
// Key-Value database provided by a Cockroach cluster by connecting
Expand Down
5 changes: 2 additions & 3 deletions kv/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package kv

import (
"fmt"

"golang.org/x/net/context"

"github.com/cockroachdb/cockroach/base"
Expand Down Expand Up @@ -58,7 +56,8 @@ func NewDBServer(ctx *base.Context, sender client.Sender) *DBServer {

// RegisterRPC registers the RPC endpoints.
func (s *DBServer) RegisterRPC(rpcServer *rpc.Server) error {
return rpcServer.Register(fmt.Sprintf("Server.%s", proto.Batch), s.executeCmd, &proto.BatchRequest{})
const method = "Server.Batch"
return rpcServer.Register(method, s.executeCmd, &proto.BatchRequest{})
}

// executeCmd interprets the given message as a *proto.BatchRequest and sends it
Expand Down
5 changes: 3 additions & 2 deletions kv/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ func (ds *DistSender) sendRPC(trace *tracer.Trace, rangeID proto.RangeID, replic
return &proto.BatchResponse{}
}

replies, err := ds.rpcSend(rpcOpts, "Node."+proto.Batch.String(),
addrs, getArgs, getReply, ds.gossip.RPCContext)
const method = "Node.Batch"
replies, err := ds.rpcSend(rpcOpts, method, addrs, getArgs, getReply,
ds.gossip.RPCContext)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions kv/dist_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func TestSendRPCRetry(t *testing.T) {
}
// Define our rpcSend stub which returns success on the second address.
var testFn rpcSendFn = func(_ rpc.Options, method string, addrs []net.Addr, getArgs func(addr net.Addr) gogoproto.Message, getReply func() gogoproto.Message, _ *rpc.Context) ([]gogoproto.Message, error) {
if method == "Node."+proto.Batch.String() {
if method == "Node.Batch" {
// reply from first address failed
_ = getReply()
// reply from second address succeed
Expand Down Expand Up @@ -723,7 +723,7 @@ func TestMultiRangeMergeStaleDescriptor(t *testing.T) {
{Key: proto.Key("c"), Value: proto.Value{Bytes: []byte("2")}},
}
var testFn rpcSendFn = func(_ rpc.Options, method string, addrs []net.Addr, getArgs func(addr net.Addr) gogoproto.Message, getReply func() gogoproto.Message, _ *rpc.Context) ([]gogoproto.Message, error) {
if method != "Node."+proto.Batch.String() {
if method != "Node.Batch" {
t.Fatalf("unexpected method:%s", method)
}
header := getArgs(testAddress).(*proto.BatchRequest).RequestHeader
Expand Down
1 change: 0 additions & 1 deletion kv/local_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (ls *LocalSender) Send(ctx context.Context, ba proto.BatchRequest) (*proto.
}

ctx = log.Add(ctx,
log.Method, proto.Batch, // TODO(tschottdorf): method is always `Batch`.
log.Key, ba.Key,
log.RangeID, ba.RangeID)

Expand Down
2 changes: 1 addition & 1 deletion kv/txn_coord_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (tc *TxnCoordSender) Send(ctx context.Context, ba proto.BatchRequest) (*pro
// TxnID (if applicable). Begin a Trace which follows this request.
trace := tc.tracer.NewTrace(&ba)
defer trace.Finalize()
defer trace.Epoch(fmt.Sprintf("sending %s", proto.Batch))()
defer trace.Epoch("sending batch")()
ctx = tracer.ToCtx(ctx, trace)

// TODO(tschottdorf): No looping through the batch will be necessary once
Expand Down
3 changes: 2 additions & 1 deletion server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ func (n *Node) initNodeID(id proto.NodeID) {
func (n *Node) start(rpcServer *rpc.Server, engines []engine.Engine,
attrs proto.Attributes, stopper *stop.Stopper) error {
n.initDescriptor(rpcServer.Addr(), attrs)
if err := rpcServer.Register("Node."+proto.Batch.String(), n.executeCmd, &proto.BatchRequest{}); err != nil {
const method = "Node.Batch"
if err := rpcServer.Register(method, n.executeCmd, &proto.BatchRequest{}); err != nil {
log.Fatalf("unable to register node service with RPC server: %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion storage/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ func (r *Replica) applyRaftCommand(ctx context.Context, index uint64, originRepl
if rErr == nil && ba.IsWrite() {
// Publish update to event feed.
// TODO(spencer): we should be sending feed updates for each part
// of the batch.
// of the batch. In particular, stats should be reported per-command.
r.rm.EventFeed().updateRange(r, proto.Batch, &ms)
// If the commit succeeded, potentially add range to split queue.
r.maybeAddToSplitQueue()
Expand Down
1 change: 0 additions & 1 deletion util/log/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (
NodeID Field = iota // the ID of the node
StoreID // the ID of the store
RangeID // the ID of the range
Method // the method being executed
Key // a proto.Key related to an event.
maxField // internal field bounding the range of allocated fields
)
4 changes: 2 additions & 2 deletions util/log/field_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package log

import "fmt"

const _Field_name = "NodeIDStoreIDRangeIDMethodKeymaxField"
const _Field_name = "NodeIDStoreIDRangeIDKeymaxField"

var _Field_index = [...]uint8{0, 6, 13, 20, 26, 29, 37}
var _Field_index = [...]uint8{0, 6, 13, 20, 23, 31}

func (i Field) String() string {
if i < 0 || i >= Field(len(_Field_index)-1) {
Expand Down
9 changes: 4 additions & 5 deletions util/log/structured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (t testArg) String() string {

func testContext() context.Context {
ctx := context.Background()
return Add(ctx, NodeID, proto.NodeID(1), StoreID, proto.StoreID(2), RangeID, proto.RangeID(3), Method, proto.Get, Key, proto.Key("key"))
return Add(ctx, NodeID, proto.NodeID(1), StoreID, proto.StoreID(2), RangeID, proto.RangeID(3), Key, proto.Key("key"))
}

func TestSetLogEntry(t *testing.T) {
Expand All @@ -48,7 +48,6 @@ func TestSetLogEntry(t *testing.T) {
nodeID := ctx.Value(NodeID).(proto.NodeID)
storeID := ctx.Value(StoreID).(proto.StoreID)
rangeID := ctx.Value(RangeID).(proto.RangeID)
method := ctx.Value(Method).(proto.Method)
key := ctx.Value(Key).(proto.Key)

testCases := []struct {
Expand All @@ -59,14 +58,14 @@ func TestSetLogEntry(t *testing.T) {
}{
{nil, "", []interface{}{}, LogEntry{}},
{ctx, "", []interface{}{}, LogEntry{
NodeID: &nodeID, StoreID: &storeID, RangeID: &rangeID, Method: &method, Key: key,
NodeID: &nodeID, StoreID: &storeID, RangeID: &rangeID, Key: key,
}},
{ctx, "no args", []interface{}{}, LogEntry{
NodeID: &nodeID, StoreID: &storeID, RangeID: &rangeID, Method: &method, Key: key,
NodeID: &nodeID, StoreID: &storeID, RangeID: &rangeID, Key: key,
Format: "no args",
}},
{ctx, "1 arg %s", []interface{}{"foo"}, LogEntry{
NodeID: &nodeID, StoreID: &storeID, RangeID: &rangeID, Method: &method, Key: key,
NodeID: &nodeID, StoreID: &storeID, RangeID: &rangeID, Key: key,
Format: "1 arg %s",
Args: []LogEntry_Arg{
{Type: "string", Str: "foo"},
Expand Down

0 comments on commit fa8e0ac

Please sign in to comment.