MCPcopy
hub / github.com/hashicorp/memberlist / UpdateNode

Method UpdateNode

memberlist.go:513–553  ·  view source on GitHub ↗

UpdateNode is used to trigger re-advertising the local node. This is primarily used with a Delegate to support dynamic updates to the local meta data. This will block until the update message is successfully broadcasted to a member of the cluster, if any exist or until a specified timeout is reache

(timeout time.Duration)

Source from the content-addressed store, hash-verified

511// broadcasted to a member of the cluster, if any exist or until a specified
512// timeout is reached.
513func (m *Memberlist) UpdateNode(timeout time.Duration) error {
514 // Get the node meta data
515 var meta []byte
516 if m.config.Delegate != nil {
517 meta = m.config.Delegate.NodeMeta(MetaMaxSize)
518 if len(meta) > MetaMaxSize {
519 panic("Node meta data provided is longer than the limit")
520 }
521 }
522
523 // Get the existing node
524 m.nodeLock.RLock()
525 state := m.nodeMap[m.config.Name]
526 m.nodeLock.RUnlock()
527
528 // Format a new alive message
529 a := alive{
530 Incarnation: m.nextIncarnation(),
531 Node: m.config.Name,
532 Addr: state.Addr,
533 Port: state.Port,
534 Meta: meta,
535 Vsn: m.config.BuildVsnArray(),
536 }
537 notifyCh := make(chan struct{})
538 m.aliveNode(&a, notifyCh, true)
539
540 // Wait for the broadcast or a timeout
541 if m.anyAlive() {
542 var timeoutCh <-chan time.Time
543 if timeout > 0 {
544 timeoutCh = time.After(timeout)
545 }
546 select {
547 case <-notifyCh:
548 case <-timeoutCh:
549 return fmt.Errorf("timeout waiting for update broadcast")
550 }
551 }
552 return nil
553}
554
555// Deprecated: SendTo is deprecated in favor of SendBestEffort, which requires a node to
556// target. If you don't have a node then use SendToAddress.

Callers 1

Calls 6

nextIncarnationMethod · 0.95
aliveNodeMethod · 0.95
anyAliveMethod · 0.95
BuildVsnArrayMethod · 0.80
ErrorfMethod · 0.80
NodeMetaMethod · 0.65

Tested by 1