@@ -39,6 +39,19 @@ var _ DBPool = &InstancePoolImpl{}
39
39
//
40
40
// Returns:
41
41
// - shard.Shard: The shard that satisfies the callback condition, or nil if no shard satisfies the condition.
42
+ //
43
+ // traverseHostsMatchCB traverses the list of hosts and invokes the provided callback function
44
+ // for each host until the callback returns true. It returns the shard that satisfies the callback
45
+ // condition. If no shard satisfies the condition, it returns nil.
46
+ //
47
+ // Parameters:
48
+ // - clid: The client ID.
49
+ // - key: The shard key.
50
+ // - hosts: The list of hosts to traverse.
51
+ // - cb: The callback function that takes a shard and returns a boolean value.
52
+ //
53
+ // Returns:
54
+ // - shard.Shard: The shard that satisfies the callback condition, or nil if no shard satisfies the condition.
42
55
func (s * InstancePoolImpl ) traverseHostsMatchCB (
43
56
clid uint ,
44
57
key kr.ShardKey , hosts []string , cb func (shard.Shard ) bool ) shard.Shard {
@@ -79,6 +92,20 @@ func (s *InstancePoolImpl) traverseHostsMatchCB(
79
92
// Returns:
80
93
// - shard.Shard: The selected read-only shard host.
81
94
// - error: An error if no suitable shard host is found.
95
+ //
96
+ // SelectReadOnlyShardHost selects a read-only shard host from the given list of hosts based on the provided client ID and shard key.
97
+ // It traverses the hosts and performs checks to ensure the selected shard host is suitable for read-only operations.
98
+ // If a suitable shard host is found, it is returned along with a nil error.
99
+ // If no suitable shard host is found, an error is returned with a message indicating the reason for failure.
100
+ //
101
+ // Parameters:
102
+ // - clid: The client ID.
103
+ // - key: The shard key.
104
+ // - hosts: The list of hosts to traverse.
105
+ //
106
+ // Returns:
107
+ // - shard.Shard: The selected read-only shard host.
108
+ // - error: An error if no suitable shard host is found.
82
109
func (s * InstancePoolImpl ) SelectReadOnlyShardHost (
83
110
clid uint ,
84
111
key kr.ShardKey , hosts []string ) (shard.Shard , error ) {
@@ -116,6 +143,20 @@ func (s *InstancePoolImpl) SelectReadOnlyShardHost(
116
143
// Returns:
117
144
// - shard.Shard: The selected read-write shard host.
118
145
// - error: An error if no suitable shard host is found.
146
+ //
147
+ // SelectReadWriteShardHost selects a read-write shard host from the given list of hosts based on the provided client ID and shard key.
148
+ // It traverses the hosts and checks if each shard is available and suitable for read-write operations.
149
+ // If a suitable shard is found, it is returned along with no error.
150
+ // If no suitable shard is found, an error is returned indicating the failure reason.
151
+ //
152
+ // Parameters:
153
+ // - clid: The client ID.
154
+ // - key: The shard key.
155
+ // - hosts: The list of hosts to traverse.
156
+ //
157
+ // Returns:
158
+ // - shard.Shard: The selected read-write shard host.
159
+ // - error: An error if no suitable shard host is found.
119
160
func (s * InstancePoolImpl ) SelectReadWriteShardHost (
120
161
clid uint ,
121
162
key kr.ShardKey , hosts []string ) (shard.Shard , error ) {
@@ -154,6 +195,19 @@ func (s *InstancePoolImpl) SelectReadWriteShardHost(
154
195
// Returns:
155
196
// - shard.Shard: The acquired shard connection.
156
197
// - error: An error if the connection cannot be established.
198
+ //
199
+ // Connection acquires a new instance connection for a client to a shard with target session attributes.
200
+ // It selects a shard host based on the target session attributes and returns a shard connection.
201
+ // If no connection can be established, it returns an error.
202
+ //
203
+ // Parameters:
204
+ // - clid: The client ID.
205
+ // - key: The shard key.
206
+ // - targetSessionAttrs: The target session attributes.
207
+ //
208
+ // Returns:
209
+ // - shard.Shard: The acquired shard connection.
210
+ // - error: An error if the connection cannot be established.
157
211
func (s * InstancePoolImpl ) Connection (
158
212
clid uint ,
159
213
key kr.ShardKey ,
@@ -204,6 +258,15 @@ func (s *InstancePoolImpl) Connection(
204
258
}
205
259
}
206
260
261
+ // InitRule initializes the backend rule in the instance pool.
262
+ // It takes a pointer to a BackendRule as a parameter and returns an error.
263
+ //
264
+ // Parameters:
265
+ // - rule: A pointer to a BackendRule representing the backend rule to be initialized.
266
+ //
267
+ // Returns:
268
+ // - error: An error if there is an error initializing the backend rule, nil otherwise.
269
+ //
207
270
// InitRule initializes the backend rule in the instance pool.
208
271
// It takes a pointer to a BackendRule as a parameter and returns an error.
209
272
//
@@ -216,17 +279,27 @@ func (s *InstancePoolImpl) InitRule(rule *config.BackendRule) error {
216
279
return s .pool .InitRule (rule )
217
280
}
218
281
282
+ // ShardMapping returns the shard mapping of the instance pool.
219
283
// ShardMapping returns the shard mapping of the instance pool.
220
284
func (s * InstancePoolImpl ) ShardMapping () map [string ]* config.Shard {
221
285
return s .shardMapping
222
286
}
223
287
288
+ // List returns a list of shards in the instance pool.
224
289
// List returns a list of shards in the instance pool.
225
290
func (s * InstancePoolImpl ) List () []shard.Shard {
226
291
/* mutex? */
227
292
return s .pool .List ()
228
293
}
229
294
295
+ // ForEach iterates over each shard in the instance pool and calls the provided callback function.
296
+ // It returns an error if the callback function returns an error.
297
+ //
298
+ // Parameters:
299
+ // - cb: The callback function to be called for each shard in the instance pool.
300
+ //
301
+ // Returns:
302
+ // - error: An error if the callback function returns an error.
230
303
// ForEach iterates over each shard in the instance pool and calls the provided callback function.
231
304
// It returns an error if the callback function returns an error.
232
305
//
@@ -249,6 +322,15 @@ func (s *InstancePoolImpl) ForEach(cb func(sh shard.Shardinfo) error) error {
249
322
//
250
323
// Returns:
251
324
// - error: An error if the shard is discarded or if there is an error putting the shard into the pool.
325
+ // Put puts a shard into the instance pool.
326
+ // It discards the shard if it is not synchronized or if it is not in idle transaction status.
327
+ // Otherwise, it puts the shard into the pool.
328
+ //
329
+ // Parameters:
330
+ // - sh: The shard to be put into the pool.
331
+ //
332
+ // Returns:
333
+ // - error: An error if the shard is discarded or if there is an error putting the shard into the pool.
252
334
func (s * InstancePoolImpl ) Put (sh shard.Shard ) error {
253
335
if sh .Sync () != 0 {
254
336
spqrlog .Zero .Error ().
@@ -267,6 +349,14 @@ func (s *InstancePoolImpl) Put(sh shard.Shard) error {
267
349
return s .pool .Put (sh )
268
350
}
269
351
352
+ // ForEachPool iterates over each pool in the instance pool and calls the provided callback function.
353
+ // It returns an error if the callback function returns an error.
354
+ //
355
+ // Parameters:
356
+ // - cb: The callback function to be called for each pool in the instance pool.
357
+ //
358
+ // Returns:
359
+ // - error: An error if the callback function returns an error.
270
360
// ForEachPool iterates over each pool in the instance pool and calls the provided callback function.
271
361
// It returns an error if the callback function returns an error.
272
362
//
@@ -279,6 +369,14 @@ func (s *InstancePoolImpl) ForEachPool(cb func(pool Pool) error) error {
279
369
return s .pool .ForEachPool (cb )
280
370
}
281
371
372
+ // Cut removes a shard from the instance pool based on the provided host.
373
+ // It returns the removed shard.
374
+ //
375
+ // Parameters:
376
+ // - host: The host of the shard to be removed.
377
+ //
378
+ // Returns:
379
+ // - []shard.Shard: The removed shard.
282
380
// Cut removes a shard from the instance pool based on the provided host.
283
381
// It returns the removed shard.
284
382
//
@@ -291,6 +389,14 @@ func (s *InstancePoolImpl) Cut(host string) []shard.Shard {
291
389
return s .pool .Cut (host )
292
390
}
293
391
392
+ // Discard removes a shard from the instance pool.
393
+ // It returns an error if the removal fails.
394
+ //
395
+ // Parameters:
396
+ // - sh: The shard to be removed from the pool.
397
+ //
398
+ // Returns:
399
+ // - error: An error if the removal fails, nil otherwise.
294
400
// Discard removes a shard from the instance pool.
295
401
// It returns an error if the removal fails.
296
402
//
@@ -311,6 +417,7 @@ func (s *InstancePoolImpl) Discard(sh shard.Shard) error {
311
417
// Parameters:
312
418
// - mapping: A map containing the shard mapping, where the key is the shard name
313
419
// and the value is a pointer to the corresponding Shard configuration.
420
+ // - sp: A StartupParams
314
421
//
315
422
// Returns:
316
423
// - DBPool: A DBPool interface that represents the created pool.
0 commit comments