Merge implements the memberlist.Mergeable interface. It allow to merge the content of two different seeds.
(mergeable memberlist.Mergeable, _ bool)
| 21 | // Merge implements the memberlist.Mergeable interface. |
| 22 | // It allow to merge the content of two different seeds. |
| 23 | func (c *ClusterSeed) Merge(mergeable memberlist.Mergeable, _ bool) (change memberlist.Mergeable, err error) { |
| 24 | if mergeable == nil { |
| 25 | return nil, nil |
| 26 | } |
| 27 | other, ok := mergeable.(*ClusterSeed) |
| 28 | if !ok { |
| 29 | return nil, fmt.Errorf("expected *usagestats.ClusterSeed, got %T", mergeable) |
| 30 | } |
| 31 | if other == nil { |
| 32 | return nil, nil |
| 33 | } |
| 34 | // if we already have (c) the oldest key, then should not request change. |
| 35 | if c.CreatedAt.Before(other.CreatedAt) { |
| 36 | return nil, nil |
| 37 | } |
| 38 | if c.CreatedAt.Equal(other.CreatedAt) { |
| 39 | // if we have the exact same creation date but the key is different |
| 40 | // we take the smallest UID using string alphabetical comparison to ensure stability. |
| 41 | if c.UID > other.UID { |
| 42 | *c = *other |
| 43 | return other, nil |
| 44 | } |
| 45 | return nil, nil |
| 46 | } |
| 47 | // if our seed is not the oldest, then we should request a change. |
| 48 | *c = *other |
| 49 | return other, nil |
| 50 | } |
| 51 | |
| 52 | // MergeContent tells if the content of the two seeds are the same. |
| 53 | func (c *ClusterSeed) MergeContent() []string { |
no test coverage detected