Skip to content

Commit

Permalink
Fix cluster module
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Mar 10, 2024
1 parent 332d98f commit 9c0928b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 71 deletions.
4 changes: 2 additions & 2 deletions cluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Client) GetNodeAPIAddr(nodeAddr string, timeout time.Duration) (string,
// Execute performs an Execute on a remote node. If username is an empty string
// no credential information will be included in the Execute request to the
// remote node.
func (c *Client) Execute(er *command.ExecuteRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration, retries int) ([]*command.ExecuteResult, error) {
func (c *Client) Execute(er *command.ExecuteRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration, retries int) ([]*command.ExecuteQueryResponse, error) {
command := &proto.Command{
Type: proto.Command_COMMAND_TYPE_EXECUTE,
Request: &proto.Command_ExecuteRequest{
Expand All @@ -152,7 +152,7 @@ func (c *Client) Execute(er *command.ExecuteRequest, nodeAddr string, creds *pro
if a.Error != "" {
return nil, errors.New(a.Error)
}
return a.Results, nil
return a.Response, nil
}

// Query performs a Query on a remote node.
Expand Down
96 changes: 48 additions & 48 deletions cluster/proto/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cluster/proto/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ message Command {

message CommandExecuteResponse {
string error = 1;
repeated command.ExecuteResult results = 2;
repeated command.ExecuteQueryResponse response = 2;
}

message CommandQueryResponse {
Expand Down
9 changes: 4 additions & 5 deletions cluster/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ type Dialer interface {

// Database is the interface any queryable system must implement
type Database interface {
// Execute executes a slice of queries, none of which is expected
// to return rows.
Execute(er *command.ExecuteRequest) ([]*command.ExecuteResult, error)
// Execute executes a slice of SQL statements.
Execute(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error)

// Query executes a slice of queries, each of which returns rows.
Query(qr *command.QueryRequest) ([]*command.QueryRows, error)
Expand Down Expand Up @@ -317,8 +316,8 @@ func (s *Service) handleConn(conn net.Conn) {
if err != nil {
resp.Error = err.Error()
} else {
resp.Results = make([]*command.ExecuteResult, len(res))
copy(resp.Results, res)
resp.Response = make([]*command.ExecuteQueryResponse, len(res))
copy(resp.Response, res)
}
}
marshalAndWrite(conn, resp)
Expand Down
28 changes: 17 additions & 11 deletions cluster/service_db_clstr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Test_ServiceExecute(t *testing.T) {
}

// Ready for Execute tests now.
db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) {
if er.Request.Statements[0].Sql != "some SQL" {
t.Fatalf("incorrect SQL statement received")
}
Expand All @@ -56,15 +56,19 @@ func Test_ServiceExecute(t *testing.T) {
t.Fatalf("incorrect error message received, got: %s", err.Error())
}

db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) {
if er.Request.Statements[0].Sql != "some SQL" {
t.Fatalf("incorrect SQL statement received")
}
result := &command.ExecuteResult{
LastInsertId: 1234,
RowsAffected: 5678,
response := &command.ExecuteQueryResponse{
Result: &command.ExecuteQueryResponse_E{
E: &command.ExecuteResult{
LastInsertId: 1234,
RowsAffected: 5678,
},
},
}
return []*command.ExecuteResult{result}, nil
return []*command.ExecuteQueryResponse{response}, nil
}
res, err := c.Execute(executeRequestFromString("some SQL"), s.Addr(), NO_CREDS, longWait, defaultMaxRetries)
if err != nil {
Expand All @@ -74,14 +78,16 @@ func Test_ServiceExecute(t *testing.T) {
t.Fatalf("unexpected results for execute, expected %s, got %s", exp, got)
}

db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) {
if er.Request.Statements[0].Sql != "some SQL" {
t.Fatalf("incorrect SQL statement received")
}
result := &command.ExecuteResult{
Error: "no such table",
response := &command.ExecuteQueryResponse{
Result: &command.ExecuteQueryResponse_Error{
Error: "no such table",
},
}
return []*command.ExecuteResult{result}, nil
return []*command.ExecuteQueryResponse{response}, nil
}
res, err = c.Execute(executeRequestFromString("some SQL"), s.Addr(), NO_CREDS, longWait, defaultMaxRetries)
if err != nil {
Expand All @@ -91,7 +97,7 @@ func Test_ServiceExecute(t *testing.T) {
t.Fatalf("unexpected results for execute, expected %s, got %s", exp, got)
}

db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
db.executeFn = func(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) {
time.Sleep(longWait)
return nil, nil
}
Expand Down
8 changes: 4 additions & 4 deletions cluster/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,14 +434,14 @@ func mustNewMockTLSTransport() *mockTransport {
}

type mockDatabase struct {
executeFn func(er *command.ExecuteRequest) ([]*command.ExecuteResult, error)
executeFn func(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error)
queryFn func(qr *command.QueryRequest) ([]*command.QueryRows, error)
requestFn func(rr *command.ExecuteQueryRequest) ([]*command.ExecuteQueryResponse, error)
backupFn func(br *command.BackupRequest, dst io.Writer) error
loadFn func(lr *command.LoadRequest) error
}

func (m *mockDatabase) Execute(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
func (m *mockDatabase) Execute(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) {
return m.executeFn(er)
}

Expand Down Expand Up @@ -471,8 +471,8 @@ func (m *mockDatabase) Load(lr *command.LoadRequest) error {
}

func mustNewMockDatabase() *mockDatabase {
e := func(er *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
return []*command.ExecuteResult{}, nil
e := func(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) {
return []*command.ExecuteQueryResponse{}, nil
}
q := func(er *command.QueryRequest) ([]*command.QueryRows, error) {
return []*command.QueryRows{}, nil
Expand Down

0 comments on commit 9c0928b

Please sign in to comment.