Susumu Yata
null+****@clear*****
Tue Jul 11 15:12:48 JST 2017
Susumu Yata 2017-07-11 15:12:48 +0900 (Tue, 11 Jul 2017) New Revision: ab14384aa7dc66805d3c005cbdd38d7c4b3f8113 https://github.com/groonga/grnci/commit/ab14384aa7dc66805d3c005cbdd38d7c4b3f8113 Message: Disable the client-side start time and elapsed time. Modified files: v2/gqtp.go v2/http.go v2/libgrn/conn.go v2/libgrn/response.go v2/response.go Modified: v2/gqtp.go (+17 -23) =================================================================== --- v2/gqtp.go 2017-07-11 14:52:31 +0900 (5f68f6a) +++ v2/gqtp.go 2017-07-11 15:12:48 +0900 (ccc2e6c) @@ -48,25 +48,21 @@ type gqtpHeader struct { // gqtpResponse is a GQTP response. type gqtpResponse struct { - client *GQTPClient // Client - conn *GQTPConn // Connection - head gqtpHeader // Current header - start time.Time // Start time - elapsed time.Duration // Elapsed time - err error // Error response - left int // Number of bytes left in the current chunk - broken bool // Whether or not the connection is broken - closed bool // Whether or not the response is closed + client *GQTPClient // Client + conn *GQTPConn // Connection + head gqtpHeader // Current header + err error // Error response + left int // Number of bytes left in the current chunk + broken bool // Whether or not the connection is broken + closed bool // Whether or not the response is closed } // newGQTPResponse returns a new GQTP response. -func newGQTPResponse(conn *GQTPConn, head gqtpHeader, start time.Time, name string) *gqtpResponse { +func newGQTPResponse(conn *GQTPConn, head gqtpHeader, name string) *gqtpResponse { resp := &gqtpResponse{ - conn: conn, - head: head, - start: start, - elapsed: time.Now().Sub(start), - left: int(head.Size), + conn: conn, + head: head, + left: int(head.Size), } if head.Status > 32767 { rc := int(head.Status) - 65536 @@ -76,11 +72,11 @@ func newGQTPResponse(conn *GQTPConn, head gqtpHeader, start time.Time, name stri } func (r *gqtpResponse) Start() time.Time { - return r.start + return time.Time{} } func (r *gqtpResponse) Elapsed() time.Duration { - return r.elapsed + return 0 } func (r *gqtpResponse) Read(p []byte) (int, error) { @@ -276,7 +272,6 @@ func (c *GQTPConn) recvHeader() (gqtpHeader, error) { // execNoBody sends a command without body and receives a response. func (c *GQTPConn) execNoBody(cmd string) (Response, error) { - start := time.Now() name := strings.TrimLeft(cmd, " \t\r\n") if idx := strings.IndexAny(name, " \t\r\n"); idx != -1 { name = name[:idx] @@ -288,12 +283,11 @@ func (c *GQTPConn) execNoBody(cmd string) (Response, error) { if err != nil { return nil, err } - return newGQTPResponse(c, head, start, name), nil + return newGQTPResponse(c, head, name), nil } // execBody sends a command with body and receives a response. func (c *GQTPConn) execBody(cmd string, body io.Reader) (Response, error) { - start := time.Now() name := strings.TrimLeft(cmd, " \t\r\n") if idx := strings.IndexAny(name, " \t\r\n"); idx != -1 { name = name[:idx] @@ -306,7 +300,7 @@ func (c *GQTPConn) execBody(cmd string, body io.Reader) (Response, error) { return nil, err } if head.Status != 0 || head.Size != 0 { - return newGQTPResponse(c, head, start, name), nil + return newGQTPResponse(c, head, name), nil } n := 0 buf := c.getBuffer() @@ -321,7 +315,7 @@ func (c *GQTPConn) execBody(cmd string, body io.Reader) (Response, error) { if err != nil { return nil, err } - return newGQTPResponse(c, head, start, name), nil + return newGQTPResponse(c, head, name), nil } if n == len(buf) { if err := c.sendChunkBytes(buf, 0); err != nil { @@ -332,7 +326,7 @@ func (c *GQTPConn) execBody(cmd string, body io.Reader) (Response, error) { return nil, err } if head.Status != 0 || head.Size != 0 { - return newGQTPResponse(c, head, start, name), nil + return newGQTPResponse(c, head, name), nil } n = 0 } Modified: v2/http.go (+7 -10) =================================================================== --- v2/http.go 2017-07-11 14:52:31 +0900 (b4b691c) +++ v2/http.go 2017-07-11 15:12:48 +0900 (13432d8) @@ -183,7 +183,7 @@ func parseHTTPResponseHeader(resp *http.Response, data []byte) (*httpResponse, e } // newHTTPResponse returns a new httpResponse. -func newHTTPResponse(resp *http.Response, start time.Time) (*httpResponse, error) { +func newHTTPResponse(resp *http.Response) (*httpResponse, error) { buf := make([]byte, httpBufferSize) n := 0 for n < len(buf) { @@ -212,12 +212,10 @@ func newHTTPResponse(resp *http.Response, start time.Time) (*httpResponse, error }) } return &httpResponse{ - resp: resp, - plain: true, - start: start, - elapsed: time.Now().Sub(start), - err: err, - left: data, + resp: resp, + plain: true, + err: err, + left: data, }, nil } @@ -328,7 +326,6 @@ func (c *HTTPClient) Close() error { // exec sends a command and receives a response. func (c *HTTPClient) exec(name string, params map[string]string, body io.Reader) (Response, error) { - start := time.Now() url := *c.url url.Path = path.Join(url.Path, name) if len(params) != 0 { @@ -347,7 +344,7 @@ func (c *HTTPClient) exec(name string, params map[string]string, body io.Reader) "error": err.Error(), }) } - return newHTTPResponse(resp, start) + return newHTTPResponse(resp) } resp, err := c.client.Post(url.String(), "application/json", body) if err != nil { @@ -357,7 +354,7 @@ func (c *HTTPClient) exec(name string, params map[string]string, body io.Reader) "error": err.Error(), }) } - return newHTTPResponse(resp, start) + return newHTTPResponse(resp) } // Exec assembles cmd and body into a Command and calls Query. Modified: v2/libgrn/conn.go (+12 -17) =================================================================== --- v2/libgrn/conn.go 2017-07-11 14:52:31 +0900 (7da73c9) +++ v2/libgrn/conn.go 2017-07-11 15:12:48 +0900 (7880fb1) @@ -7,7 +7,6 @@ import "C" import ( "io" "strings" - "time" "unsafe" "github.com/groonga/grnci/v2" @@ -134,7 +133,6 @@ func (c *Conn) getBuffer() []byte { // execNoBodyGQTP sends a command and receives a response. func (c *Conn) execNoBodyGQTP(cmd string) (grnci.Response, error) { - start := time.Now() name := strings.TrimLeft(cmd, " \t\r\n") if idx := strings.IndexAny(name, " \t\r\n"); idx != -1 { name = name[:idx] @@ -146,18 +144,17 @@ func (c *Conn) execNoBodyGQTP(cmd string) (grnci.Response, error) { if err != nil && len(data) == 0 { return nil, err } - return newGQTPResponse(c, start, name, data, flags, err), nil + return newGQTPResponse(c, name, data, flags, err), nil } // execNoBodyDB executes a command and receives a response. func (c *Conn) execNoBodyDB(cmd string) (grnci.Response, error) { - start := time.Now() if err := c.ctx.Send([]byte(cmd), flagTail); err != nil { data, flags, _ := c.ctx.Recv() - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } data, flags, err := c.ctx.Recv() - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } // execNoBody sends a command without body and receives a response. @@ -170,7 +167,6 @@ func (c *Conn) execNoBody(cmd string) (grnci.Response, error) { // execBodyGQTP sends a command and receives a response. func (c *Conn) execBodyGQTP(cmd string, body io.Reader) (grnci.Response, error) { - start := time.Now() name := strings.TrimLeft(cmd, " \t\r\n") if idx := strings.IndexAny(name, " \t\r\n"); idx != -1 { name = name[:idx] @@ -180,7 +176,7 @@ func (c *Conn) execBodyGQTP(cmd string, body io.Reader) (grnci.Response, error) } data, flags, err := c.ctx.Recv() if len(data) != 0 { - return newGQTPResponse(c, start, name, data, flags, err), nil + return newGQTPResponse(c, name, data, flags, err), nil } if err != nil { return nil, err @@ -196,7 +192,7 @@ func (c *Conn) execBodyGQTP(cmd string, body io.Reader) (grnci.Response, error) } data, flags, err := c.ctx.Recv() if len(data) != 0 || err == nil { - return newGQTPResponse(c, start, name, data, flags, err), nil + return newGQTPResponse(c, name, data, flags, err), nil } return nil, err } @@ -207,7 +203,7 @@ func (c *Conn) execBodyGQTP(cmd string, body io.Reader) (grnci.Response, error) n = 0 data, flags, err = c.ctx.Recv() if len(data) != 0 { - return newGQTPResponse(c, start, name, data, flags, err), nil + return newGQTPResponse(c, name, data, flags, err), nil } if err != nil { return nil, err @@ -218,14 +214,13 @@ func (c *Conn) execBodyGQTP(cmd string, body io.Reader) (grnci.Response, error) // execBodyDB sends a command and receives a response. func (c *Conn) execBodyDB(cmd string, body io.Reader) (grnci.Response, error) { - start := time.Now() if err := c.ctx.Send([]byte(cmd), 0); err != nil { data, flags, _ := c.ctx.Recv() - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } data, flags, err := c.ctx.Recv() if len(data) != 0 || err != nil { - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } n := 0 buf := c.getBuffer() @@ -235,20 +230,20 @@ func (c *Conn) execBodyDB(cmd string, body io.Reader) (grnci.Response, error) { if err != nil { if err := c.ctx.Send(buf[:n], flagTail); err != nil { data, flags, _ := c.ctx.Recv() - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } data, flags, err := c.ctx.Recv() - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } if n == len(buf) { if err := c.ctx.Send(buf, 0); err != nil { data, flags, _ := c.ctx.Recv() - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } n = 0 data, flags, err = c.ctx.Recv() if len(data) != 0 || err != nil { - return newDBResponse(c, start, data, flags, err), nil + return newDBResponse(c, data, flags, err), nil } } } Modified: v2/libgrn/response.go (+19 -25) =================================================================== --- v2/libgrn/response.go 2017-07-11 14:52:31 +0900 (a3fb52e) +++ v2/libgrn/response.go 2017-07-11 15:12:48 +0900 (29ad810) @@ -10,49 +10,43 @@ import ( // response is a response. type response struct { - client *Client - conn *Conn - start time.Time - elapsed time.Duration - left []byte - flags byte - err error - broken bool - closed bool + client *Client + conn *Conn + left []byte + flags byte + err error + broken bool + closed bool } // newGQTPResponse returns a new GQTP response. -func newGQTPResponse(conn *Conn, start time.Time, name string, data []byte, flags byte, err error) *response { +func newGQTPResponse(conn *Conn, name string, data []byte, flags byte, err error) *response { return &response{ - conn: conn, - start: start, - elapsed: time.Now().Sub(start), - left: data, - flags: flags, - err: err, + conn: conn, + left: data, + flags: flags, + err: err, } } // newDBResponse returns a new DB response. -func newDBResponse(conn *Conn, start time.Time, data []byte, flags byte, err error) *response { +func newDBResponse(conn *Conn, data []byte, flags byte, err error) *response { return &response{ - conn: conn, - start: start, - elapsed: time.Now().Sub(start), - left: data, - flags: flags, - err: err, + conn: conn, + left: data, + flags: flags, + err: err, } } // Start returns the start time. func (r *response) Start() time.Time { - return r.start + return time.Time{} } // Elapsed returns the elapsed time. func (r *response) Elapsed() time.Duration { - return r.elapsed + return 0 } // Read reads the response body at most len(p) bytes into p. Modified: v2/response.go (+4 -12) =================================================================== --- v2/response.go 2017-07-11 14:52:31 +0900 (8ec87db) +++ v2/response.go 2017-07-11 15:12:48 +0900 (e85d7e9) @@ -6,20 +6,12 @@ import ( // Response is the interface of responses. type Response interface { - // Start returns the start time of the command. - // The definition of the start time varies according to the protocol. - // - // HTTPClient returns a response with the server-side start time, - // because an HTTP server returns a result with the start time. - // - // GQTPConn and GQTPClient return a response with the client-side start time, - // because a GQTP server does not return the start time. - // libgrn.Conn and libgrn.Client also return the client-side start time. + // Start returns the server-side start time of the command if available. + // Responses of HTTPClient may return a valid (non-zero) time. Start() time.Time - // Elapsed returns the elapsed time of the command. - // The definition of the elapsed time varies likewise the start time. - // See above for the details. + // Elapsed returns the server-side elapsed time of the command if available. + // Responses of HTTPClient may return a valid (non-zero) duration. Elapsed() time.Duration // Read reads the response body at most len(p) bytes into p. -------------- next part -------------- HTML����������������������������... 다운로드