public class DistributedMetaStorageImpl extends GridProcessorAdapter implements DistributedMetaStorage, IgniteChangeGlobalStateSupport
Implementation of DistributedMetaStorage based on MetaStorage for persistence and discovery SPI
for communication.
It is based on existing local metastorage API for persistent clusters (in-memory clusters and client nodes will store data in memory). Write/remove operation use Discovery SPI to send updates to the cluster, it guarantees updates order and the fact that all existing (alive) nodes have handled the update message.
As a way to find out which node has the latest data there is a "version" value of distributed metastorage,
(DistributedMetaStorageVersion) which is basically the pair <number of all updates, hash of all
updates>. First element of the pair is the value of getUpdatesCount().
Whole updates history until some point in the past is stored along with the data, so when an outdated node
connects to the cluster it will receive all the missing data and apply it locally. Listeners will also be invoked
after such updates. If there's not enough history stored or joining node is clear then it'll receive shapshot of
distributed metastorage (usually called fullData in code) so there won't be inconsistencies.
DistributedMetaStorageUpdateMessage,
DistributedMetaStorageUpdateAckMessageGridComponent.DiscoveryDataExchangeType| Modifier and Type | Field and Description |
|---|---|
static String |
DISTRIBUTED_METASTORE_VIEW
Name of the system view for a system
MetaStorage. |
static String |
DISTRIBUTED_METASTORE_VIEW_DESC
Description of the system view for a
MetaStorage. |
static String |
NOT_SUPPORTED_MSG
Message indicating that clusted is in a mixed state and writing cannot be completed because of that.
|
ctx, diagnosticLog, logIGNITE_INTERNAL_KEY_PREFIX| Constructor and Description |
|---|
DistributedMetaStorageImpl(GridKernalContext ctx) |
| Modifier and Type | Method and Description |
|---|---|
void |
collectGridNodeData(DiscoveryDataBag dataBag)
Collects discovery data on nodes already in grid on receiving
TcpDiscoveryNodeAddedMessage. |
void |
collectJoiningNodeData(DiscoveryDataBag dataBag)
Collects discovery data on joining node before sending
TcpDiscoveryJoinRequestMessage request. |
boolean |
compareAndRemove(@NotNull String key,
@NotNull Serializable expVal)
Remove value from distributed metastorage but only if current value matches the expected one.
|
boolean |
compareAndSet(@NotNull String key,
@Nullable Serializable expVal,
@NotNull Serializable newVal)
Write value into distributed metastorage but only if current value matches the expected one.
|
GridFutureAdapter<Boolean> |
compareAndSetAsync(@NotNull String key,
@Nullable Serializable expVal,
@NotNull Serializable newVal)
Write value into distributed metastorage asynchronously but only if current value matches the expected one.
|
@Nullable GridComponent.DiscoveryDataExchangeType |
discoveryDataType()
Gets unique component type to distinguish components providing discovery data.
|
long |
getUpdatesCount()
Get the total number of updates (write/remove) that metastorage ever had.
|
void |
inMemoryReadyForRead()
Executed roughly at the same time as
onMetaStorageReadyForRead(ReadOnlyMetastorage). |
void |
iterate(@NotNull String keyPrefix,
@NotNull BiConsumer<String,? super Serializable> cb)
Iterate over all values corresponding to the keys with given prefix.
|
void |
listen(@NotNull Predicate<String> keyPred,
DistributedMetaStorageListener<?> lsnr)
Add listener on data updates.
|
void |
onActivate(GridKernalContext kctx)
Called when cluster performing activation.
|
void |
onDeActivate(GridKernalContext kctx)
Called when cluster performing deactivation.
|
void |
onDisconnected(IgniteFuture<?> reconnectFut)
Client disconnected callback.
|
void |
onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data)
Receives discovery data object from remote nodes (called
on new node during discovery process).
|
void |
onJoiningNodeDataReceived(DiscoveryDataBag.JoiningNodeDiscoveryData discoData)
Method is called on nodes that are already in grid (not on joining node).
|
void |
onKernalStop(boolean cancel)
Callback to notify that kernal is about to stop.
|
IgniteInternalFuture<?> |
onReconnected(boolean clusterRestarted)
Client reconnected callback.
|
<T extends Serializable> |
read(@NotNull String key)
Get value by the key.
|
void |
remove(@NotNull String key)
Remove value from distributed metastorage.
|
GridFutureAdapter<?> |
removeAsync(@NotNull String key)
Remove value from distributed metastorage asynchronously.
|
void |
start()
Starts grid component.
|
@Nullable IgniteNodeValidationResult |
validateNode(ClusterNode node,
DiscoveryDataBag.JoiningNodeDiscoveryData discoData)
Validates that new node can join grid topology, this method is called on coordinator
node before new node joins topology.
|
void |
write(@NotNull String key,
@NotNull Serializable val)
Write value into distributed metastorage.
|
GridFutureAdapter<?> |
writeAsync(@NotNull String key,
@NotNull Serializable val)
Write value into distributed metastorage asynchronously.
|
assertParameter, onKernalStart, printMemoryStats, stop, toString, validateNodeclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisSupportedpublic static final String NOT_SUPPORTED_MSG
public static final String DISTRIBUTED_METASTORE_VIEW
MetaStorage.public static final String DISTRIBUTED_METASTORE_VIEW_DESC
MetaStorage.public DistributedMetaStorageImpl(GridKernalContext ctx)
ctx - Kernal context.public void start()
throws IgniteCheckedException
start in interface GridComponentstart in class GridProcessorAdapterIgniteCheckedException - Throws in case of any errors.public void onKernalStop(boolean cancel)
onKernalStop in interface GridComponentonKernalStop in class GridProcessorAdaptercancel - If true then ignore worker's queue and finish it as fast as possible. Otherwise
just wait until queue is empty and worker completed its job.public void inMemoryReadyForRead()
onMetaStorageReadyForRead(ReadOnlyMetastorage).public void onActivate(GridKernalContext kctx)
onActivate in interface IgniteChangeGlobalStateSupportkctx - Kernal context.public void onDeActivate(GridKernalContext kctx)
onDeActivate in interface IgniteChangeGlobalStateSupportkctx - Kernal context.public long getUpdatesCount()
getUpdatesCount in interface ReadableDistributedMetaStorage@Nullable public <T extends Serializable> T read(@NotNull @NotNull String key) throws IgniteCheckedException
read in interface ReadableDistributedMetaStoragekey - The key.IgniteCheckedException - If reading or unmarshalling failed.public void write(@NotNull
@NotNull String key,
@NotNull
@NotNull Serializable val)
throws IgniteCheckedException
write in interface DistributedMetaStoragekey - The key.val - Value to write. Must not be null.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public GridFutureAdapter<?> writeAsync(@NotNull @NotNull String key, @NotNull @NotNull Serializable val) throws IgniteCheckedException
writeAsync in interface DistributedMetaStoragekey - The key.val - Value to write. Must not be null.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public GridFutureAdapter<?> removeAsync(@NotNull @NotNull String key) throws IgniteCheckedException
removeAsync in interface DistributedMetaStoragekey - The key.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public void remove(@NotNull
@NotNull String key)
throws IgniteCheckedException
remove in interface DistributedMetaStoragekey - The key.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public boolean compareAndSet(@NotNull
@NotNull String key,
@Nullable
@Nullable Serializable expVal,
@NotNull
@NotNull Serializable newVal)
throws IgniteCheckedException
compareAndSet in interface DistributedMetaStoragekey - The key.expVal - Expected value. Might be null.newVal - Value to write. Must not be null.True if expected value matched the actual one and write was completed successfully.
False otherwise.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public GridFutureAdapter<Boolean> compareAndSetAsync(@NotNull @NotNull String key, @Nullable @Nullable Serializable expVal, @NotNull @NotNull Serializable newVal) throws IgniteCheckedException
compareAndSetAsync in interface DistributedMetaStoragekey - The key.expVal - Expected value. Might be null.newVal - Value to write. Must not be null.True if expected value matched the actual one and write was completed successfully.
False otherwise.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public boolean compareAndRemove(@NotNull
@NotNull String key,
@NotNull
@NotNull Serializable expVal)
throws IgniteCheckedException
compareAndRemove in interface DistributedMetaStoragekey - The key.expVal - Expected value. Must not be null.True if expected value matched the actual one and remove was completed successfully.
False otherwise.IgniteCheckedException - In case of marshalling error or some other unexpected exception.public void iterate(@NotNull
@NotNull String keyPrefix,
@NotNull
@NotNull BiConsumer<String,? super Serializable> cb)
throws IgniteCheckedException
iterate in interface ReadableDistributedMetaStoragekeyPrefix - Prefix for the keys that will be iterated.cb - Callback that will be applied to all <key, value> pairs.IgniteCheckedException - If reading or unmarshalling failed.public void listen(@NotNull
@NotNull Predicate<String> keyPred,
DistributedMetaStorageListener<?> lsnr)
listen in interface ReadableDistributedMetaStoragekeyPred - Predicate to check whether this listener should be invoked on given key update or not.lsnr - Listener object.DistributedMetaStorageListener@Nullable public @Nullable GridComponent.DiscoveryDataExchangeType discoveryDataType()
GridComponent.collectJoiningNodeData(DiscoveryDataBag)
or GridComponent.collectGridNodeData(DiscoveryDataBag).discoveryDataType in interface GridComponentdiscoveryDataType in class GridProcessorAdapterpublic void collectJoiningNodeData(DiscoveryDataBag dataBag)
TcpDiscoveryJoinRequestMessage request.collectJoiningNodeData in interface GridComponentcollectJoiningNodeData in class GridProcessorAdapterdataBag - container object to store discovery data in.@Nullable public @Nullable IgniteNodeValidationResult validateNode(ClusterNode node, DiscoveryDataBag.JoiningNodeDiscoveryData discoData)
getUpdatesCount() is not zero).
validateNode in interface GridComponentvalidateNode in class GridProcessorAdapternode - Joining node.discoData - Joining node discovery data.null in case of success.public void onJoiningNodeDataReceived(DiscoveryDataBag.JoiningNodeDiscoveryData discoData)
validateNode(ClusterNode, DiscoveryDataBag.JoiningNodeDiscoveryData) has already been invoked we
can be sure that joining node has valid discovery data. Current method does something meaningful only if joining
node has bigger distributed metastorage version, in this case all required updates will be applied.onJoiningNodeDataReceived in interface GridComponentonJoiningNodeDataReceived in class GridProcessorAdapterdiscoData - DiscoveryDataBag.JoiningNodeDiscoveryData interface to retrieve discovery data of joining node.public void collectGridNodeData(DiscoveryDataBag dataBag)
TcpDiscoveryNodeAddedMessage.
fullData) is collected along with
available history. Goal of collecting history in second case is to allow all nodes in cluster to have the same
history so connection of new server will always give the same result.collectGridNodeData in interface GridComponentcollectGridNodeData in class GridProcessorAdapterdataBag - container object to store discovery data in.public void onDisconnected(IgniteFuture<?> reconnectFut)
onDisconnected in interface GridComponentonDisconnected in class GridProcessorAdapterreconnectFut - Reconnect future.public IgniteInternalFuture<?> onReconnected(boolean clusterRestarted)
onReconnected in interface GridComponentonReconnected in class GridProcessorAdapterclusterRestarted - Cluster restarted flag.public void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data)
onGridDataReceived in interface GridComponentonGridDataReceived in class GridProcessorAdapterdata - Grid discovery data.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.9.1 Release Date : December 9 2020