1+ // Package with implementation of methods and structures for work with
2+ // Tarantool instance.
13package tarantool
24
35import (
@@ -27,26 +29,26 @@ type ConnEventKind int
2729type ConnLogKind int
2830
2931const (
30- // Connect signals that connection is established or reestablished
32+ // Connected signals that connection is established or reestablished.
3133 Connected ConnEventKind = iota + 1
32- // Disconnect signals that connection is broken
34+ // Disconnected signals that connection is broken.
3335 Disconnected
34- // ReconnectFailed signals that attempt to reconnect has failed
36+ // ReconnectFailed signals that attempt to reconnect has failed.
3537 ReconnectFailed
36- // Either reconnect attempts exhausted, or explicit Close is called
38+ // Either reconnect attempts exhausted, or explicit Close is called.
3739 Closed
3840
39- // LogReconnectFailed is logged when reconnect attempt failed
41+ // LogReconnectFailed is logged when reconnect attempt failed.
4042 LogReconnectFailed ConnLogKind = iota + 1
4143 // LogLastReconnectFailed is logged when last reconnect attempt failed,
4244 // connection will be closed after that.
4345 LogLastReconnectFailed
44- // LogUnexpectedResultId is logged when response with unknown id were received.
46+ // LogUnexpectedResultId is logged when response with unknown id was received.
4547 // Most probably it is due to request timeout.
4648 LogUnexpectedResultId
4749)
4850
49- // ConnEvent is sent throw Notify channel specified in Opts
51+ // ConnEvent is sent throw Notify channel specified in Opts.
5052type ConnEvent struct {
5153 Conn * Connection
5254 Kind ConnEventKind
@@ -80,47 +82,47 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
8082 }
8183}
8284
83- // Connection is a handle to Tarantool.
85+ // Connection is a handle with a single connection to a Tarantool instance .
8486//
8587// It is created and configured with Connect function, and could not be
8688// reconfigured later.
8789//
88- // It is could be "Connected", "Disconnected", and "Closed".
90+ // Connection could be in three possible states:
8991//
90- // When "Connected" it sends queries to Tarantool.
92+ // - In "Connected" state it sends queries to Tarantool.
9193//
92- // When "Disconnected" it rejects queries with ClientError{Code: ErrConnectionNotReady}
94+ // - In "Disconnected" state it rejects queries with ClientError{Code:
95+ // ErrConnectionNotReady}
9396//
94- // When "Closed" it rejects queries with ClientError{Code: ErrConnectionClosed}
95- //
96- // Connection could become "Closed" when Connection .Close() method called,
97- // or when Tarantool disconnected and Reconnect pause is not specified or
98- // MaxReconnects is specified and MaxReconnect reconnect attempts already performed.
97+ // - In "Closed" state it rejects queries with ClientError{Code:
98+ // ErrConnectionClosed}. Connection could become "Closed" when
99+ // Connection.Close() method called, or when Tarantool disconnected and
100+ // Reconnect pause is not specified or MaxReconnects is specified and
101+ // MaxReconnect reconnect attempts already performed.
99102//
100103// You may perform data manipulation operation by calling its methods:
101104// Call*, Insert*, Replace*, Update*, Upsert*, Call*, Eval*.
102105//
103- // In any method that accepts ` space` you my pass either space number or
104- // space name (in this case it will be looked up in schema). Same is true for ` index` .
106+ // In any method that accepts space you my pass either space number or space
107+ // name (in this case it will be looked up in schema). Same is true for index.
105108//
106- // ATTENTION: ` tuple`, ` key`, ` ops` and ` args` arguments for any method should be
109+ // ATTENTION: tuple, key, ops and args arguments for any method should be
107110// and array or should serialize to msgpack array.
108111//
109- // ATTENTION: ` result` argument for *Typed methods should deserialize from
112+ // ATTENTION: result argument for *Typed methods should deserialize from
110113// msgpack array, cause Tarantool always returns result as an array.
111114// For all space related methods and Call* (but not Call17*) methods Tarantool
112115// always returns array of array (array of tuples for space related methods).
113- // For Eval* and Call17* tarantool always returns array, but does not forces
116+ // For Eval* and Call17* Tarantool always returns array, but does not forces
114117// array of arrays.
115-
116118type Connection struct {
117119 addr string
118120 c net.Conn
119121 mutex sync.Mutex
120122 // Schema contains schema loaded on connection.
121123 Schema * Schema
122124 requestId uint32
123- // Greeting contains first message sent by tarantool
125+ // Greeting contains first message sent by Tarantool.
124126 Greeting * Greeting
125127
126128 shard []connShard
@@ -134,7 +136,7 @@ type Connection struct {
134136 lenbuf [PacketLengthBytes ]byte
135137}
136138
137- var _ = Connector (& Connection {}) // check compatibility with connector interface
139+ var _ = Connector (& Connection {}) // Check compatibility with connector interface.
138140
139141type connShard struct {
140142 rmut sync.Mutex
@@ -148,7 +150,7 @@ type connShard struct {
148150 _pad [16 ]uint64
149151}
150152
151- // Greeting is a message sent by tarantool on connect.
153+ // Greeting is a message sent by Tarantool on connect.
152154type Greeting struct {
153155 Version string
154156 auth string
@@ -157,22 +159,22 @@ type Greeting struct {
157159// Opts is a way to configure Connection
158160type Opts struct {
159161 // Timeout is requests timeout.
160- // Also used to setup net.TCPConn.Set(Read|Write)Deadline
162+ // Also used to setup net.TCPConn.Set(Read|Write)Deadline.
161163 Timeout time.Duration
162164 // Reconnect is a pause between reconnection attempts.
163- // If specified, then when tarantool is not reachable or disconnected,
165+ // If specified, then when Tarantool is not reachable or disconnected,
164166 // new connect attempt is performed after pause.
165167 // By default, no reconnection attempts are performed,
166168 // so once disconnected, connection becomes Closed.
167169 Reconnect time.Duration
168170 // MaxReconnects is a maximum reconnect attempts.
169171 // After MaxReconnects attempts Connection becomes closed.
170172 MaxReconnects uint
171- // User name for authorization
173+ // User name for authorization.
172174 User string
173- // Pass is password for authorization
175+ // Pass is password for authorization.
174176 Pass string
175- // RateLimit limits number of 'in-fly' request, ie already put into
177+ // RateLimit limits number of 'in-fly' request, i.e. already put into
176178 // requests queue, but not yet answered by server or timeouted.
177179 // It is disabled by default.
178180 // See RLimitAction for possible actions when RateLimit.reached.
@@ -191,42 +193,37 @@ type Opts struct {
191193 // By default it is runtime.GOMAXPROCS(-1) * 4
192194 Concurrency uint32
193195 // SkipSchema disables schema loading. Without disabling schema loading,
194- // there is no way to create Connection for currently not accessible tarantool .
196+ // there is no way to create Connection for currently not accessible Tarantool .
195197 SkipSchema bool
196198 // Notify is a channel which receives notifications about Connection status
197199 // changes.
198200 Notify chan <- ConnEvent
199- // Handle is user specified value, that could be retrivied with Handle() method
201+ // Handle is user specified value, that could be retrivied with
202+ // Handle() method.
200203 Handle interface {}
201- // Logger is user specified logger used for error messages
204+ // Logger is user specified logger used for error messages.
202205 Logger Logger
203206}
204207
205- // Connect creates and configures new Connection
208+ // Connect creates and configures a new Connection.
206209//
207210// Address could be specified in following ways:
208211//
209- // TCP connections:
210- // - tcp://192.168.1.1:3013
211- // - tcp://my.host:3013
212- // - tcp:192.168.1.1:3013
213- // - tcp:my.host:3013
214- // - 192.168.1.1:3013
215- // - my.host:3013
216- // Unix socket:
217- // - unix:///abs/path/tnt.sock
218- // - unix:path/tnt.sock
219- // - /abs/path/tnt.sock - first '/' indicates unix socket
220- // - ./rel/path/tnt.sock - first '.' indicates unix socket
221- // - unix/:path/tnt.sock - 'unix/' acts as a "host" and "/path..." as a port
212+ // - TCP connections (tcp://192.168.1.1:3013, tcp://my.host:3013,
213+ // tcp:192.168.1.1:3013, tcp:my.host:3013, 192.168.1.1:3013, my.host:3013)
214+ //
215+ // - Unix socket, first '/' or '.' indicates Unix socket
216+ // (unix:///abs/path/tnt.sock, unix:path/tnt.sock, /abs/path/tnt.sock,
217+ // ./rel/path/tnt.sock, unix/:path/tnt.sock)
222218//
223- // Note :
219+ // Notes :
224220//
225221// - If opts.Reconnect is zero (default), then connection either already connected
226222// or error is returned.
227223//
228- // - If opts.Reconnect is non-zero, then error will be returned only if authorization// fails. But if Tarantool is not reachable, then it will attempt to reconnect later
229- // and will not end attempts on authorization failures.
224+ // - If opts.Reconnect is non-zero, then error will be returned only if authorization
225+ // fails. But if Tarantool is not reachable, then it will make an attempt to reconnect later
226+ // and will not finish to make attempts on authorization failures.
230227func Connect (addr string , opts Opts ) (conn * Connection , err error ) {
231228 conn = & Connection {
232229 addr : addr ,
@@ -272,10 +269,10 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
272269 return nil , err
273270 } else if ok && (ter .Code == ErrNoSuchUser ||
274271 ter .Code == ErrPasswordMismatch ) {
275- /* reported auth errors immediatly */
272+ // Reported auth errors immediately.
276273 return nil , err
277274 } else {
278- // without SkipSchema it is useless
275+ // Without SkipSchema it is useless.
279276 go func (conn * Connection ) {
280277 conn .mutex .Lock ()
281278 defer conn .mutex .Unlock ()
@@ -292,7 +289,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
292289 go conn .timeouts ()
293290 }
294291
295- // TODO: reload schema after reconnect
292+ // TODO: reload schema after reconnect.
296293 if ! conn .opts .SkipSchema {
297294 if err = conn .loadSchema (); err != nil {
298295 conn .mutex .Lock ()
@@ -324,12 +321,12 @@ func (conn *Connection) Close() error {
324321 return conn .closeConnection (err , true )
325322}
326323
327- // Addr is configured address of Tarantool socket
324+ // Addr returns a configured address of Tarantool socket.
328325func (conn * Connection ) Addr () string {
329326 return conn .addr
330327}
331328
332- // RemoteAddr is address of Tarantool socket
329+ // RemoteAddr returns an address of Tarantool socket.
333330func (conn * Connection ) RemoteAddr () string {
334331 conn .mutex .Lock ()
335332 defer conn .mutex .Unlock ()
@@ -339,7 +336,7 @@ func (conn *Connection) RemoteAddr() string {
339336 return conn .c .RemoteAddr ().String ()
340337}
341338
342- // LocalAddr is address of outgoing socket
339+ // LocalAddr returns an address of outgoing socket.
343340func (conn * Connection ) LocalAddr () string {
344341 conn .mutex .Lock ()
345342 defer conn .mutex .Unlock ()
@@ -349,7 +346,7 @@ func (conn *Connection) LocalAddr() string {
349346 return conn .c .LocalAddr ().String ()
350347}
351348
352- // Handle returns user specified handle from Opts
349+ // Handle returns a user- specified handle from Opts.
353350func (conn * Connection ) Handle () interface {} {
354351 return conn .opts .Handle
355352}
@@ -416,7 +413,7 @@ func (conn *Connection) dial() (err error) {
416413 }
417414 }
418415
419- // Only if connected and authenticated
416+ // Only if connected and authenticated.
420417 conn .lockShards ()
421418 conn .c = connection
422419 atomic .StoreUint32 (& conn .state , connConnected )
@@ -873,12 +870,12 @@ func (conn *Connection) nextRequestId() (requestId uint32) {
873870 return atomic .AddUint32 (& conn .requestId , 1 )
874871}
875872
876- // ConfiguredTimeout returns timeout from connection config
873+ // ConfiguredTimeout returns a timeout from connection config.
877874func (conn * Connection ) ConfiguredTimeout () time.Duration {
878875 return conn .opts .Timeout
879876}
880877
881- // OverrideSchema sets Schema for the connection
878+ // OverrideSchema sets Schema for the connection.
882879func (conn * Connection ) OverrideSchema (s * Schema ) {
883880 if s != nil {
884881 conn .mutex .Lock ()
0 commit comments