Skip to content

Commit 5bbfc0a

Browse files
committed
comment fixes
1 parent 099577d commit 5bbfc0a

12 files changed

+146
-179
lines changed

connection.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ func (conn *Connection) reader(r io.Reader, c Conn) {
830830
conn.opts.Logger.Report(LogWatchEventReadFailed, conn, err)
831831
}
832832
continue
833-
} else if header.Code == PushCode {
833+
} else if iproto.Type(header.Code) == iproto.IPROTO_CHUNK {
834834
if fut = conn.peekFuture(header.RequestId); fut != nil {
835835
fut.AppendPush(header, &buf)
836836
}
@@ -874,8 +874,7 @@ func (conn *Connection) eventer(events <-chan connWatchEvent) {
874874

875875
func (conn *Connection) newFuture(req Request) (fut *Future) {
876876
ctx := req.Ctx()
877-
fut = NewFuture()
878-
fut.SetRequest(req)
877+
fut = NewFuture(req)
879878
if conn.rlimit != nil && conn.opts.RLimitAction == RLimitDrop {
880879
select {
881880
case conn.rlimit <- struct{}{}:
@@ -1204,7 +1203,7 @@ func (conn *Connection) nextRequestId(context bool) (requestId uint32) {
12041203
func (conn *Connection) Do(req Request) *Future {
12051204
if connectedReq, ok := req.(ConnectedRequest); ok {
12061205
if connectedReq.Conn() != conn {
1207-
fut := NewFuture()
1206+
fut := NewFuture(req)
12081207
fut.SetError(errUnknownRequest)
12091208
return fut
12101209
}

const.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ const (
99
)
1010

1111
const (
12-
OkCode = uint32(iproto.IPROTO_OK)
13-
PushCode = uint32(iproto.IPROTO_CHUNK)
12+
OkCode = int(iproto.IPROTO_OK)
1413
)

future.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ func (it *asyncResponseIterator) nextResponse() (resp Response) {
126126
return resp
127127
}
128128

129-
// NewFuture creates a new empty Future.
130-
func NewFuture() (fut *Future) {
129+
// NewFuture creates a new empty Future for a given Request.
130+
func NewFuture(req Request) (fut *Future) {
131131
fut = &Future{}
132132
fut.ready = make(chan struct{}, 1000000000)
133133
fut.done = make(chan struct{})
134134
fut.pushes = make([]Response, 0)
135+
fut.req = req
135136
return fut
136137
}
137138

future_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func assertResponseIteratorFinished(t testing.TB, it ResponseIterator) {
3737
}
3838

3939
func TestFutureGetIteratorNoItems(t *testing.T) {
40-
fut := NewFuture()
40+
fut := NewFuture(test_helpers.NewMockRequest())
4141

4242
it := fut.GetIterator()
4343
if it.Next() {
@@ -50,7 +50,7 @@ func TestFutureGetIteratorNoItems(t *testing.T) {
5050
func TestFutureGetIteratorNoResponse(t *testing.T) {
5151
pushHeader := Header{}
5252
push := &PushResponse{}
53-
fut := NewFuture()
53+
fut := NewFuture(test_helpers.NewMockRequest())
5454
fut.AppendPush(pushHeader, nil)
5555

5656
push.Decode()
@@ -69,7 +69,7 @@ func TestFutureGetIteratorNoResponse(t *testing.T) {
6969
func TestFutureGetIteratorNoResponseTimeout(t *testing.T) {
7070
pushHeader := Header{}
7171
push := &PushResponse{}
72-
fut := NewFuture()
72+
fut := NewFuture(test_helpers.NewMockRequest())
7373
fut.AppendPush(pushHeader, nil)
7474

7575
push.Decode()
@@ -90,7 +90,7 @@ func TestFutureGetIteratorResponseOnTimeout(t *testing.T) {
9090
respHeader := Header{}
9191
push := &PushResponse{}
9292
resp := &test_helpers.MockResponse{}
93-
fut := NewFuture()
93+
fut := NewFuture(test_helpers.NewMockRequest())
9494
fut.AppendPush(pushHeader, nil)
9595

9696
push.Decode()
@@ -133,8 +133,7 @@ func TestFutureGetIteratorResponseOnTimeout(t *testing.T) {
133133

134134
func TestFutureGetIteratorFirstResponse(t *testing.T) {
135135
resp := &test_helpers.MockResponse{}
136-
fut := NewFuture()
137-
fut.SetRequest(test_helpers.NewMockRequest())
136+
fut := NewFuture(test_helpers.NewMockRequest())
138137
fut.SetResponse(Header{}, nil)
139138
fut.SetResponse(Header{}, nil)
140139

@@ -153,7 +152,7 @@ func TestFutureGetIteratorFirstError(t *testing.T) {
153152
const errMsg1 = "error1"
154153
const errMsg2 = "error2"
155154

156-
fut := NewFuture()
155+
fut := NewFuture(test_helpers.NewMockRequest())
157156
fut.SetError(errors.New(errMsg1))
158157
fut.SetError(errors.New(errMsg2))
159158

@@ -174,8 +173,7 @@ func TestFutureGetIteratorResponse(t *testing.T) {
174173
&test_helpers.MockResponse{},
175174
}
176175
header := Header{}
177-
fut := NewFuture()
178-
fut.SetRequest(test_helpers.NewMockRequest())
176+
fut := NewFuture(test_helpers.NewMockRequest())
179177
for i, resp := range responses {
180178
resp.Decode()
181179
if i == len(responses)-1 {
@@ -210,7 +208,7 @@ func TestFutureGetIteratorError(t *testing.T) {
210208
{},
211209
}
212210
err := errors.New(errMsg)
213-
fut := NewFuture()
211+
fut := NewFuture(test_helpers.NewMockRequest())
214212
for _, resp := range responses {
215213
fut.AppendPush(Header{}, nil)
216214
resp.Decode()
@@ -245,8 +243,7 @@ func TestFutureSetStateRaceCondition(t *testing.T) {
245243
err := errors.New("any error")
246244

247245
for i := 0; i < 1000; i++ {
248-
fut := NewFuture()
249-
fut.SetRequest(test_helpers.NewMockRequest())
246+
fut := NewFuture(test_helpers.NewMockRequest())
250247
for j := 0; j < 9; j++ {
251248
go func(opt int) {
252249
if opt%3 == 0 {

pool/connection_pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ func (p *ConnectionPool) getConnByMode(defaultMode Mode,
14601460
}
14611461

14621462
func newErrorFuture(err error) *tarantool.Future {
1463-
fut := tarantool.NewFuture()
1463+
fut := tarantool.NewFuture(nil)
14641464
fut.SetError(err)
14651465
return fut
14661466
}

prepared.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package tarantool
33
import (
44
"context"
55
"fmt"
6-
"io"
7-
"io/ioutil"
8-
96
"github.com/tarantool/go-iproto"
107
"github.com/vmihailenco/msgpack/v5"
8+
"io"
119
)
1210

1311
// PreparedID is a type for Prepared Statement ID
@@ -99,21 +97,10 @@ func (req *PrepareRequest) Context(ctx context.Context) *PrepareRequest {
9997

10098
// CreateResponse creates a response for the PrepareRequest.
10199
func (req *PrepareRequest) CreateResponse(header Header, body io.Reader) (Response, error) {
102-
if body == nil {
103-
baseResp := baseResponse{header: header}
104-
return &PrepareResponse{baseResponse: baseResp}, nil
105-
}
106-
if buf, ok := body.(*smallBuf); ok {
107-
baseResp := baseResponse{header: header, buf: *buf}
108-
return &PrepareResponse{baseResponse: baseResp}, nil
109-
}
110-
data, err := ioutil.ReadAll(body)
100+
baseResp, err := createBaseResponse(header, body)
111101
if err != nil {
112102
return nil, err
113103
}
114-
baseResp := baseResponse{
115-
header: header, buf: smallBuf{b: data},
116-
}
117104
return &PrepareResponse{baseResponse: baseResp}, nil
118105
}
119106

@@ -200,20 +187,9 @@ func (req *ExecutePreparedRequest) Context(ctx context.Context) *ExecutePrepared
200187

201188
// CreateResponse creates a response for the ExecutePreparedRequest.
202189
func (req *ExecutePreparedRequest) CreateResponse(header Header, body io.Reader) (Response, error) {
203-
if body == nil {
204-
baseResp := baseResponse{header: header}
205-
return &ExecuteResponse{baseResponse: baseResp}, nil
206-
}
207-
if buf, ok := body.(*smallBuf); ok {
208-
baseResp := baseResponse{header: header, buf: *buf}
209-
return &ExecuteResponse{baseResponse: baseResp}, nil
210-
}
211-
data, err := ioutil.ReadAll(body)
190+
baseResp, err := createBaseResponse(header, body)
212191
if err != nil {
213192
return nil, err
214193
}
215-
baseResp := baseResponse{
216-
header: header, buf: smallBuf{b: data},
217-
}
218194
return &ExecuteResponse{baseResponse: baseResp}, nil
219195
}

request.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"reflect"
109
"strings"
1110
"sync"
@@ -853,19 +852,10 @@ func (req *baseRequest) Ctx() context.Context {
853852

854853
// CreateResponse creates a response for the baseRequest.
855854
func (req *baseRequest) CreateResponse(header Header, body io.Reader) (Response, error) {
856-
if body == nil {
857-
return &baseResponse{header: header}, nil
858-
}
859-
if buf, ok := body.(*smallBuf); ok {
860-
return &baseResponse{header: header, buf: *buf}, nil
861-
}
862-
data, err := ioutil.ReadAll(body)
855+
resp, err := createBaseResponse(header, body)
863856
if err != nil {
864857
return nil, err
865858
}
866-
resp := baseResponse{
867-
header: header, buf: smallBuf{b: data},
868-
}
869859
return &resp, nil
870860
}
871861

@@ -961,19 +951,10 @@ func (req authRequest) Body(res SchemaResolver, enc *msgpack.Encoder) error {
961951

962952
// CreateResponse creates a response for the authRequest.
963953
func (req authRequest) CreateResponse(header Header, body io.Reader) (Response, error) {
964-
if body == nil {
965-
return &baseResponse{header: header}, nil
966-
}
967-
if buf, ok := body.(*smallBuf); ok {
968-
return &baseResponse{header: header, buf: *buf}, nil
969-
}
970-
data, err := ioutil.ReadAll(body)
954+
resp, err := createBaseResponse(header, body)
971955
if err != nil {
972956
return nil, err
973957
}
974-
resp := baseResponse{
975-
header: header, buf: smallBuf{b: data},
976-
}
977958
return &resp, nil
978959
}
979960

@@ -1121,21 +1102,10 @@ func (req *SelectRequest) Context(ctx context.Context) *SelectRequest {
11211102

11221103
// CreateResponse creates a response for the SelectRequest.
11231104
func (req *SelectRequest) CreateResponse(header Header, body io.Reader) (Response, error) {
1124-
if body == nil {
1125-
baseResp := baseResponse{header: header}
1126-
return &SelectResponse{baseResponse: baseResp}, nil
1127-
}
1128-
if buf, ok := body.(*smallBuf); ok {
1129-
baseResp := baseResponse{header: header, buf: *buf}
1130-
return &SelectResponse{baseResponse: baseResp}, nil
1131-
}
1132-
data, err := ioutil.ReadAll(body)
1105+
baseResp, err := createBaseResponse(header, body)
11331106
if err != nil {
11341107
return nil, err
11351108
}
1136-
baseResp := baseResponse{
1137-
header: header, buf: smallBuf{b: data},
1138-
}
11391109
return &SelectResponse{baseResponse: baseResp}, nil
11401110
}
11411111

@@ -1540,21 +1510,10 @@ func (req *ExecuteRequest) Context(ctx context.Context) *ExecuteRequest {
15401510

15411511
// CreateResponse creates a response for the ExecuteRequest.
15421512
func (req *ExecuteRequest) CreateResponse(header Header, body io.Reader) (Response, error) {
1543-
if body == nil {
1544-
baseResp := baseResponse{header: header}
1545-
return &ExecuteResponse{baseResponse: baseResp}, nil
1546-
}
1547-
if buf, ok := body.(*smallBuf); ok {
1548-
baseResp := baseResponse{header: header, buf: *buf}
1549-
return &ExecuteResponse{baseResponse: baseResp}, nil
1550-
}
1551-
data, err := ioutil.ReadAll(body)
1513+
baseResp, err := createBaseResponse(header, body)
15521514
if err != nil {
15531515
return nil, err
15541516
}
1555-
baseResp := baseResponse{
1556-
header: header, buf: smallBuf{b: data},
1557-
}
15581517
return &ExecuteResponse{baseResponse: baseResp}, nil
15591518
}
15601519

0 commit comments

Comments
 (0)