Package org.apache.cassandra.schema
Class DefaultSchemaUpdateHandler
- java.lang.Object
-
- org.apache.cassandra.schema.DefaultSchemaUpdateHandler
-
- All Implemented Interfaces:
IEndpointStateChangeSubscriber,SchemaUpdateHandler
public class DefaultSchemaUpdateHandler extends java.lang.Object implements SchemaUpdateHandler, IEndpointStateChangeSubscriber
-
-
Constructor Summary
Constructors Constructor Description DefaultSchemaUpdateHandler(java.util.function.BiConsumer<SchemaTransformation.SchemaTransformationResult,java.lang.Boolean> updateCallback)DefaultSchemaUpdateHandler(MigrationCoordinator migrationCoordinator, MessagingService messagingService, boolean requireSchemas, java.util.function.BiConsumer<SchemaTransformation.SchemaTransformationResult,java.lang.Boolean> updateCallback)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SchemaTransformation.SchemaTransformationResultapply(SchemaTransformation transformation, boolean local)Applies schema transformation in the underlying storage and synchronizes with other nodes.voidbeforeChange(InetAddressAndPort endpoint, EndpointState currentState, ApplicationState newStateKey, VersionedValue newValue)Awaitableclear()When clear is called the update handler will flag that the clear was requested.java.util.Map<java.util.UUID,java.util.Set<InetAddressAndPort>>getOutstandingSchemaVersions()voidonAlive(InetAddressAndPort endpoint, EndpointState state)voidonChange(InetAddressAndPort endpoint, ApplicationState state, VersionedValue value)voidonDead(InetAddressAndPort endpoint, EndpointState state)voidonJoin(InetAddressAndPort endpoint, EndpointState epState)Use to inform interested parties about the change in the state for specified endpointvoidonRemove(InetAddressAndPort endpoint)voidonRestart(InetAddressAndPort endpoint, EndpointState state)Called whenever a node is restarted.voidreset(boolean local)Resets the schema either by reloading data from the local storage or from the other nodes.voidstart()Starts actively synchronizing schema with the rest of the cluster.booleanwaitUntilReady(java.time.Duration timeout)Waits until the schema update handler is ready and returns the result.
-
-
-
Constructor Detail
-
DefaultSchemaUpdateHandler
public DefaultSchemaUpdateHandler(java.util.function.BiConsumer<SchemaTransformation.SchemaTransformationResult,java.lang.Boolean> updateCallback)
-
DefaultSchemaUpdateHandler
public DefaultSchemaUpdateHandler(MigrationCoordinator migrationCoordinator, MessagingService messagingService, boolean requireSchemas, java.util.function.BiConsumer<SchemaTransformation.SchemaTransformationResult,java.lang.Boolean> updateCallback)
-
-
Method Detail
-
start
public void start()
Description copied from interface:SchemaUpdateHandlerStarts actively synchronizing schema with the rest of the cluster. It is called in the very beginning of the node startup. It is not expected to block - to await for the startup completion we have another methodSchemaUpdateHandler.waitUntilReady(Duration).- Specified by:
startin interfaceSchemaUpdateHandler
-
waitUntilReady
public boolean waitUntilReady(java.time.Duration timeout)
Description copied from interface:SchemaUpdateHandlerWaits until the schema update handler is ready and returns the result. If the method returnsfalseit means that readiness could not be achieved within the specified period of time. The method can be used just to check if schema is ready by passingDuration.ZEROas the timeout - in such case it returns immediately.- Specified by:
waitUntilReadyin interfaceSchemaUpdateHandler- Parameters:
timeout- the maximum time to wait for schema readiness- Returns:
- whether readiness is achieved
-
onRemove
public void onRemove(InetAddressAndPort endpoint)
- Specified by:
onRemovein interfaceIEndpointStateChangeSubscriber
-
onChange
public void onChange(InetAddressAndPort endpoint, ApplicationState state, VersionedValue value)
- Specified by:
onChangein interfaceIEndpointStateChangeSubscriber
-
onJoin
public void onJoin(InetAddressAndPort endpoint, EndpointState epState)
Description copied from interface:IEndpointStateChangeSubscriberUse to inform interested parties about the change in the state for specified endpoint- Specified by:
onJoinin interfaceIEndpointStateChangeSubscriber- Parameters:
endpoint- endpoint for which the state change occurred.epState- state that actually changed for the above endpoint.
-
beforeChange
public void beforeChange(InetAddressAndPort endpoint, EndpointState currentState, ApplicationState newStateKey, VersionedValue newValue)
- Specified by:
beforeChangein interfaceIEndpointStateChangeSubscriber
-
onAlive
public void onAlive(InetAddressAndPort endpoint, EndpointState state)
- Specified by:
onAlivein interfaceIEndpointStateChangeSubscriber
-
onDead
public void onDead(InetAddressAndPort endpoint, EndpointState state)
- Specified by:
onDeadin interfaceIEndpointStateChangeSubscriber
-
onRestart
public void onRestart(InetAddressAndPort endpoint, EndpointState state)
Description copied from interface:IEndpointStateChangeSubscriberCalled whenever a node is restarted. Note that there is no guarantee when that happens that the node was previously marked down. It will have only ifstate.isAlive() == falseasstateis from before the restarted node is marked up.- Specified by:
onRestartin interfaceIEndpointStateChangeSubscriber
-
apply
public SchemaTransformation.SchemaTransformationResult apply(SchemaTransformation transformation, boolean local)
Description copied from interface:SchemaUpdateHandlerApplies schema transformation in the underlying storage and synchronizes with other nodes.- Specified by:
applyin interfaceSchemaUpdateHandler- Parameters:
transformation- schema transformation to be performedlocal- if true, the caller does not require synchronizing schema with other nodes - in practise local is used only in some tests- Returns:
- transformation result
-
reset
public void reset(boolean local)
Description copied from interface:SchemaUpdateHandlerResets the schema either by reloading data from the local storage or from the other nodes. Once the schema is refreshed, the callbacks provided in the factory method are executed, and the updated schema version is announced.- Specified by:
resetin interfaceSchemaUpdateHandler- Parameters:
local- whether we should reset with locally stored schema or fetch the schema from other nodes
-
clear
public Awaitable clear()
When clear is called the update handler will flag that the clear was requested. It means that migration coordinator will think that we have empty schema version and will apply whatever it receives from other nodes. When a first attempt to apply mutations from other node is called, it will first clear the schema and apply the mutations on a truncated table. The flag is then reset.This way the clear is postponed until we really fetch any schema we can use as a replacement. Otherwise, nothing will happen. We will simply reset the flag after the timeout and throw exceptions to the caller.
- Specified by:
clearin interfaceSchemaUpdateHandler- Returns:
-
getOutstandingSchemaVersions
public java.util.Map<java.util.UUID,java.util.Set<InetAddressAndPort>> getOutstandingSchemaVersions()
-
-