@@ -155,6 +155,7 @@ func (c cassVersion) nodeUpDelay() time.Duration {
155
155
return 10 * time .Second
156
156
}
157
157
158
+ // HostInfo holds information about the host (e.g. addresses and state).
158
159
type HostInfo struct {
159
160
// TODO(zariel): reduce locking maybe, not all values will change, but to ensure
160
161
// that we are thread safe use a mutex to access all fields.
@@ -193,6 +194,7 @@ func newHostInfo(addr net.IP, port int) (*HostInfo, error) {
193
194
return host , nil
194
195
}
195
196
197
+ // Equal returns true if hosts are equal of if connect addresses of the hosts are equal.
196
198
func (h * HostInfo ) Equal (host * HostInfo ) bool {
197
199
if h == host {
198
200
// prevent rlock reentry
@@ -202,6 +204,7 @@ func (h *HostInfo) Equal(host *HostInfo) bool {
202
204
return h .ConnectAddress ().Equal (host .ConnectAddress ())
203
205
}
204
206
207
+ // Peer returns hosts peer.
205
208
func (h * HostInfo ) Peer () net.IP {
206
209
h .mu .RLock ()
207
210
defer h .mu .RUnlock ()
@@ -259,92 +262,107 @@ func (h *HostInfo) ConnectAddress() net.IP {
259
262
return addr
260
263
}
261
264
265
+ // BroadcastAddress returns the broadcast address of the host.
262
266
func (h * HostInfo ) BroadcastAddress () net.IP {
263
267
h .mu .RLock ()
264
268
defer h .mu .RUnlock ()
265
269
return h .broadcastAddress
266
270
}
267
271
272
+ // ListenAddress returns the address on which a host listens for incoming connections.
268
273
func (h * HostInfo ) ListenAddress () net.IP {
269
274
h .mu .RLock ()
270
275
defer h .mu .RUnlock ()
271
276
return h .listenAddress
272
277
}
273
278
279
+ // RPCAddress returns address on which host listens for RPC requests.
274
280
func (h * HostInfo ) RPCAddress () net.IP {
275
281
h .mu .RLock ()
276
282
defer h .mu .RUnlock ()
277
283
return h .rpcAddress
278
284
}
279
285
286
+ // PreferredIP returns the preferred IP of the host.
280
287
func (h * HostInfo ) PreferredIP () net.IP {
281
288
h .mu .RLock ()
282
289
defer h .mu .RUnlock ()
283
290
return h .preferredIP
284
291
}
285
292
293
+ // DataCenter returns the name of the host data center.
286
294
func (h * HostInfo ) DataCenter () string {
287
295
h .mu .RLock ()
288
296
dc := h .dataCenter
289
297
h .mu .RUnlock ()
290
298
return dc
291
299
}
292
300
301
+ // Rack returns the name of the host rack.
293
302
func (h * HostInfo ) Rack () string {
294
303
h .mu .RLock ()
295
304
rack := h .rack
296
305
h .mu .RUnlock ()
297
306
return rack
298
307
}
299
308
309
+ // HostID returns the host ID.
300
310
func (h * HostInfo ) HostID () string {
301
311
h .mu .RLock ()
302
312
defer h .mu .RUnlock ()
303
313
return h .hostId
304
314
}
305
315
316
+ // SetHostID sets the host ID.
306
317
func (h * HostInfo ) SetHostID (hostID string ) {
307
318
h .mu .Lock ()
308
319
defer h .mu .Unlock ()
309
320
h .hostId = hostID
310
321
}
311
322
323
+ // WorkLoad returns the current workload of the host.
312
324
func (h * HostInfo ) WorkLoad () string {
313
325
h .mu .RLock ()
314
326
defer h .mu .RUnlock ()
315
327
return h .workload
316
328
}
317
329
330
+ // Graph returns true if graph mode is enabled for the DSE.
318
331
func (h * HostInfo ) Graph () bool {
319
332
h .mu .RLock ()
320
333
defer h .mu .RUnlock ()
321
334
return h .graph
322
335
}
323
336
337
+ // DSEVersion returns the version of DSE instance.
324
338
func (h * HostInfo ) DSEVersion () string {
325
339
h .mu .RLock ()
326
340
defer h .mu .RUnlock ()
327
341
return h .dseVersion
328
342
}
329
343
344
+ // Partitioner returns the partitioner kind.
330
345
func (h * HostInfo ) Partitioner () string {
331
346
h .mu .RLock ()
332
347
defer h .mu .RUnlock ()
333
348
return h .partitioner
334
349
}
335
350
351
+ // ClusterName returns name of the cluster.
336
352
func (h * HostInfo ) ClusterName () string {
337
353
h .mu .RLock ()
338
354
defer h .mu .RUnlock ()
339
355
return h .clusterName
340
356
}
341
357
358
+ // Version returns version of the Cassandra instance.
342
359
func (h * HostInfo ) Version () cassVersion {
343
360
h .mu .RLock ()
344
361
defer h .mu .RUnlock ()
345
362
return h .version
346
363
}
347
364
365
+ // State returns state of the node.
348
366
func (h * HostInfo ) State () nodeState {
349
367
h .mu .RLock ()
350
368
defer h .mu .RUnlock ()
@@ -358,12 +376,14 @@ func (h *HostInfo) setState(state nodeState) *HostInfo {
358
376
return h
359
377
}
360
378
379
+ // Tokens returns slice of tokens.
361
380
func (h * HostInfo ) Tokens () []string {
362
381
h .mu .RLock ()
363
382
defer h .mu .RUnlock ()
364
383
return h .tokens
365
384
}
366
385
386
+ // Port returns port which used for the connection.
367
387
func (h * HostInfo ) Port () int {
368
388
h .mu .RLock ()
369
389
defer h .mu .RUnlock ()
@@ -432,10 +452,13 @@ func (h *HostInfo) update(from *HostInfo) {
432
452
}
433
453
}
434
454
455
+ // IsUp return true if the host is not nil and if the host state is node NodeUp.
435
456
func (h * HostInfo ) IsUp () bool {
436
457
return h != nil && h .State () == NodeUp
437
458
}
438
459
460
+ // HostnameAndPort returns a network address of the form "host:port".
461
+ // If host contains a colon - "[host]:port" will be returned.
439
462
func (h * HostInfo ) HostnameAndPort () string {
440
463
h .mu .Lock ()
441
464
defer h .mu .Unlock ()
@@ -446,6 +469,8 @@ func (h *HostInfo) HostnameAndPort() string {
446
469
return net .JoinHostPort (h .hostname , strconv .Itoa (h .port ))
447
470
}
448
471
472
+ // ConnectAddressAndPort returns a network address of the form "host:port".
473
+ // If connect address contains a colon - "[host]:port" will be returned.
449
474
func (h * HostInfo ) ConnectAddressAndPort () string {
450
475
h .mu .Lock ()
451
476
defer h .mu .Unlock ()
0 commit comments