org.apache.ignite.internal.processors.cluster

## Class BaselineTopology

- java.lang.Object
- - org.apache.ignite.internal.processors.cluster.BaselineTopology

All Implemented Interfaces:
  Serializable

    public class BaselineTopology
    extends Object
    implements Serializable

BaselineTopology represents a set of "database nodes" - nodes responsible for holding persistent-enabled caches and persisting their information to durable storage. Two major features BaselineTopology allows are:

1. Protection from conflicting updates.
2. Cluster auto activation.

## Protection from conflicting updates

Consider en example: there is a cluster of three nodes, A, B and C, all nodes store persistent data. Cluster history looks like this: [A,B,C] | \ (1)cluster segmentation, two parts get activated independently | | [A,B] [C] | | (2)updates to both parts After independent updates applied to both parts of cluster at point(2) node C should not be allowed to join [A,B] part. The following algorithm makes sure node C will never join [A,B] part back:

1. When the cluster is initially activated BaselineTopology is created; its property branchingPntHash is calculated based on consistent IDs of all nodes.
2. At point(1) two parts are activated separately; BaselineTopology in each is updated: old branchingPntHash is moved to branchingHistory list; new one is calculated based on new set of nodes.
3. If node C tries to join other part of cluster (e.g. after network connectivity repair) [A,B] cluster checks its branchingPntHash and branchingHistory to see if branching history of C's BaselineTopology has diverged from [A,B]. If divergence is detected [A,B] cluster refuses to let C into topology.

All new nodes joining a cluster should pass validation process before join; detailed algorithm of the process is described below.

### Joining node validation algorithm

Node joining a cluster firstly reads its local BaselineTopology from metastore and sends it to the cluster.

1. When BaselineTopology is set (e.g. on first activation) or recreated (e.g. with set-baseline command) its ID on all nodes is incremented by one. So when cluster receives a join request with BaselineTopology it firstly compares joining node BlT ID with local BlT ID. If joining node has a BaselineTopology with ID greater than one in cluster it means that BlT was changed more times there; therefore new node is not allowed to join the cluster.
2. If user manually activates cluster when some of Baseline nodes are offline no new BlT is created. Instead current set of online nodes from BaselineTopology is used to update `branchingPntHash` property of current BaselineTopology. Old value of the property is moved to `branchingHist` list. If joining node and local BlT IDs are the same then cluster takes branchingPntHash of joining node and verifies that its local branchingHist contains that hash. If joining node hash is not presented in cluster branching history list it means that joining node was activated independently of currently running cluster; therefore new node is not allowed to join the cluster. If joining node hash is presented in the history, that it is safe to let the node join the cluster.
3. When BaselineTopology is recreated (e.g. with set-baseline command) previous BaselineTopology is moved to BaselineHistory (consult source code of `GridClusterStateProcessor` for more details). If cluster sees that joining node BlT ID is less than cluster BlT ID it looks up for BaselineHistory item for new node ID. Having this BaselineHistory item cluster verifies that branching history of the item contains branching point hash of joining node (similar check as in the case above with only difference that joining node BlT is compared against BaselineHistory item instead of BaselineTopology). If new node branching point hash is found in the history than node is allowed to join; otherwise it is rejected.

## Cluster auto activation

See Also:
  Serialized Form

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Map<String,Object>` `attributes(Object consId)`
`ClusterNode` `baselineNode(Object consId)`
`List<Long>` `branchingHistory()`
`long` `branchingPointHash()`
`static BaselineTopology` `build(Collection<? extends BaselineNode> nodes, int id)`
`Map<Short,Object>` `compactIdMapping()`
`Map<Object,Short>` `consistentIdMapping()`
`Set<Object>` `consistentIds()`
`List<ClusterNode>` `createBaselineView(List<ClusterNode> aliveNodes, IgnitePredicate<ClusterNode> nodeFilter)`
`List<BaselineNode>` `currentBaseline()`
`static boolean` `equals(BaselineTopology blt1, BaselineTopology blt2)`
`boolean` `equals(Object o)`
`int` `hashCode()`
`int` `id()`
`boolean` `isSatisfied(Collection<ClusterNode> presentedNodes)`
`Object` `resolveConsistentId(Short constId)`
`Short` `resolveShortConsistentId(Object constId)`
`int` `size()`
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Method Detail

#### id

    public int id()

Returns:
  id of this BaselineTopology.

#### consistentIds

    public Set<Object> consistentIds()

Returns:
  Set of consistent IDs.

#### branchingHistory

    public List<Long> branchingHistory()

Returns:
  Activation history.

#### compactIdMapping

    public Map<Short,Object> compactIdMapping()

Returns:
  Compact IDs mapping.

#### consistentIdMapping

    public Map<Object,Short> consistentIdMapping()

Returns:
  Consistent IDs mapping.

#### resolveShortConsistentId

    public Short resolveShortConsistentId(Object constId)

Returns:
  Short consistent Id.

#### resolveConsistentId

    public Object resolveConsistentId(Short constId)

Returns:
  Object consistent Id.

#### branchingPointHash

    public long branchingPointHash()

Returns:
  Activation hash.

#### attributes

    public Map<String,Object> attributes(Object consId)

Parameters:
  `consId` - Node consistent ID.
Returns:
  Node attributes map.

#### currentBaseline

    public List<BaselineNode> currentBaseline()

#### baselineNode

    public ClusterNode baselineNode(Object consId)

Parameters:
  `consId` - Consistent ID.
Returns:
  Baseline node, if present in the baseline, or `null` if absent.

#### createBaselineView

    public List<ClusterNode> createBaselineView(List<ClusterNode> aliveNodes,
                                                @Nullable
                                                IgnitePredicate<ClusterNode> nodeFilter)

Parameters:
  `aliveNodes` - Sorted list of currently alive nodes.
  `nodeFilter` - Node filter.
Returns:
  Sorted list of baseline topology nodes.

#### isSatisfied

    public boolean isSatisfied(@NotNull
                               Collection<ClusterNode> presentedNodes)

Parameters:
  `presentedNodes` - Nodes present in cluster.
Returns:
  `True` if current topology satisfies baseline.

#### size

    public int size()

Returns:
  Size of the baseline topology.

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### equals

    public static boolean equals(BaselineTopology blt1,
                                 BaselineTopology blt2)

Parameters:
  `blt1` - Baseline topology instance.
  `blt2` - Baseline topology instance.
Returns:
  `True` if equals.

#### build

    @Nullable
    public static BaselineTopology build(Collection<? extends BaselineNode> nodes,
                                                   int id)

Parameters:
  `nodes` - Nodes.
  `id` - ID of BaselineTopology to build.
Returns:
  Baseline topology consisting of given nodes.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019