Class SchemaRegistry
- java.lang.Object
-
- org.apache.flink.cdc.runtime.operators.schema.common.SchemaRegistry
-
- All Implemented Interfaces:
AutoCloseable,org.apache.flink.api.common.state.CheckpointListener,org.apache.flink.runtime.operators.coordination.CoordinationRequestHandler,org.apache.flink.runtime.operators.coordination.OperatorCoordinator
- Direct Known Subclasses:
SchemaCoordinator,SchemaCoordinator
@Internal public abstract class SchemaRegistry extends Object implements org.apache.flink.runtime.operators.coordination.OperatorCoordinator, org.apache.flink.runtime.operators.coordination.CoordinationRequestHandler
An abstract centralized schema registry that accepts requests fromSchemaEvolutionClient. A legit schema registry should be able to:- Handle schema retrieval requests from
SchemaEvolutionClients - Accept and trace sink writers' registering events
- Snapshot & Restore its state during checkpoints
These abilities are done by overriding abstract methods ofSchemaRegistry. All methods will run in givenExecutorServiceasynchronously exceptSchemaRegistry#restore.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.operators.coordination.OperatorCoordinator
org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Context, org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Provider, org.apache.flink.runtime.operators.coordination.OperatorCoordinator.SubtaskGateway
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<Integer>activeSinkWritersprotected SchemaChangeBehaviorbehaviorprotected org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Contextcontextprotected ExecutorServicecoordinatorExecutorprotected intcurrentParallelismprotected ExistingTableSchemaExpanderexistingTableSchemaExpanderprotected ExistingTableSchemaExpansionModeexistingTableSchemaExpansionModeprotected Map<Integer,Throwable>failedReasonsprotected MetadataAppliermetadataApplierprotected StringoperatorNameprotected RouteModerouteModeprotected TableIdRouterrouterprotected List<RouteRule>routingRulesprotected java.time.DurationrpcTimeoutprotected SchemaManagerschemaManager
-
Constructor Summary
Constructors Modifier Constructor Description protectedSchemaRegistry(org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Context context, String operatorName, ExecutorService coordinatorExecutor, MetadataApplier metadataApplier, List<RouteRule> routingRules, RouteMode routeMode, SchemaChangeBehavior schemaChangeBehavior, ExistingTableSchemaExpansionMode existingTableSchemaExpansionMode, java.time.Duration rpcTimeout)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcheckpointCoordinator(long checkpointId, CompletableFuture<byte[]> completableFuture)voidclose()voidemplaceEvolvedSchema(TableId tableId, Schema schema)voidemplaceOriginalSchema(TableId tableId, Schema schema)voidexecutionAttemptFailed(int subTaskId, int attemptNumber, Throwable reason)voidexecutionAttemptReady(int subTaskId, int attemptNumber, org.apache.flink.runtime.operators.coordination.OperatorCoordinator.SubtaskGateway gateway)protected booleanexpandExistingTableSchemaIfNeeded(SchemaChangeEvent schemaChangeEvent)Handles the initialCreateTableEventfor an existing target table.protected <T extends Throwable>
voidfailJob(String taskDescription, T t)CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse>handleCoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest request)protected abstract voidhandleCustomCoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest request, CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> responseFuture)Coordination handler for customizedCoordinationRequests.voidhandleEventFromOperator(int subTaskId, int attemptNumber, org.apache.flink.runtime.operators.coordination.OperatorEvent event)protected abstract voidhandleFlushSuccessEvent(FlushSuccessEvent event)Overridable handler forFlushSuccessEvents.protected voidhandleGetEvolvedSchemaRequest(GetEvolvedSchemaRequest request, CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> responseFuture)Overridable handler forGetEvolvedSchemaRequests.protected voidhandleGetOriginalSchemaRequest(GetOriginalSchemaRequest request, CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> responseFuture)Overridable handler forGetOriginalSchemaRequests.protected voidhandleSinkWriterRegisterEvent(SinkWriterRegisterEvent event)Overridable handler forSinkWriterRegisterEvents.protected voidhandleUnrecoverableError(String taskDescription, Throwable t)Last chance to execute codes before job fails globally.protected abstract voidinitialize()(Re)initializes transient state, both onstart()and after a coordinator reset.protected voidloopUntil(java.util.function.BooleanSupplier conditionChecker, Runnable message, java.time.Duration timeout, java.time.Duration interval)Keeps checking ifconditionCheckeris satisfied.protected voidloopWhen(java.util.function.BooleanSupplier conditionChecker, Runnable message, java.time.Duration timeout, java.time.Duration interval)Keeps checking ifconditionCheckeris satisfied.voidnotifyCheckpointComplete(long checkpointId)voidresetToCheckpoint(long checkpointId, byte[] checkpointData)protected abstract voidrestore(byte[] checkpointData)Restore schema registry state from byte array.protected voidrunInEventLoop(org.apache.flink.util.function.ThrowingRunnable<Throwable> action, String actionName, Object... actionNameFormatParameters)Run a time-consuming task in givenExecutorService.protected abstract voidshutdown()Stops schema-change work from the previous coordinator generation.protected abstract voidsnapshot(CompletableFuture<byte[]> resultFuture)Snapshot current schema registry state in byte array form.voidstart()voidsubtaskReset(int subTaskId, long checkpointId)
-
-
-
Field Detail
-
context
protected final org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Context context
-
operatorName
protected final String operatorName
-
coordinatorExecutor
protected final ExecutorService coordinatorExecutor
-
metadataApplier
protected final MetadataApplier metadataApplier
-
rpcTimeout
protected final java.time.Duration rpcTimeout
-
routeMode
protected final RouteMode routeMode
-
behavior
protected final SchemaChangeBehavior behavior
-
existingTableSchemaExpansionMode
protected final ExistingTableSchemaExpansionMode existingTableSchemaExpansionMode
-
currentParallelism
protected transient int currentParallelism
-
schemaManager
protected transient SchemaManager schemaManager
-
router
protected transient TableIdRouter router
-
existingTableSchemaExpander
protected transient ExistingTableSchemaExpander existingTableSchemaExpander
-
-
Constructor Detail
-
SchemaRegistry
protected SchemaRegistry(org.apache.flink.runtime.operators.coordination.OperatorCoordinator.Context context, String operatorName, ExecutorService coordinatorExecutor, MetadataApplier metadataApplier, List<RouteRule> routingRules, RouteMode routeMode, SchemaChangeBehavior schemaChangeBehavior, ExistingTableSchemaExpansionMode existingTableSchemaExpansionMode, java.time.Duration rpcTimeout)
-
-
Method Detail
-
start
public void start() throws Exception- Specified by:
startin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator- Throws:
Exception
-
expandExistingTableSchemaIfNeeded
protected boolean expandExistingTableSchemaIfNeeded(SchemaChangeEvent schemaChangeEvent)
Handles the initialCreateTableEventfor an existing target table.- Returns:
- whether the caller should proceed to apply the original
CreateTableEventto the sink;CHECKmode returnsfalseafter a successful check.
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator- Throws:
Exception
-
snapshot
protected abstract void snapshot(CompletableFuture<byte[]> resultFuture) throws Exception
Snapshot current schema registry state in byte array form.- Throws:
Exception
-
restore
protected abstract void restore(byte[] checkpointData) throws ExceptionRestore schema registry state from byte array.- Throws:
Exception
-
shutdown
protected abstract void shutdown() throws ExceptionStops schema-change work from the previous coordinator generation. Implementations must block until the previous generation's worker has fully exited, withinrpcTimeout.- Throws:
Exception
-
initialize
protected abstract void initialize()
(Re)initializes transient state, both onstart()and after a coordinator reset.
-
handleSinkWriterRegisterEvent
protected void handleSinkWriterRegisterEvent(SinkWriterRegisterEvent event) throws Exception
Overridable handler forSinkWriterRegisterEvents.- Throws:
Exception
-
handleFlushSuccessEvent
protected abstract void handleFlushSuccessEvent(FlushSuccessEvent event) throws Exception
Overridable handler forFlushSuccessEvents.- Throws:
Exception
-
handleGetEvolvedSchemaRequest
protected void handleGetEvolvedSchemaRequest(GetEvolvedSchemaRequest request, CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> responseFuture) throws Exception
Overridable handler forGetEvolvedSchemaRequests.- Throws:
Exception
-
handleGetOriginalSchemaRequest
protected void handleGetOriginalSchemaRequest(GetOriginalSchemaRequest request, CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> responseFuture) throws Exception
Overridable handler forGetOriginalSchemaRequests.- Throws:
Exception
-
handleCustomCoordinationRequest
protected abstract void handleCustomCoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest request, CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> responseFuture) throws ExceptionCoordination handler for customizedCoordinationRequests.- Throws:
Exception
-
handleUnrecoverableError
protected void handleUnrecoverableError(String taskDescription, Throwable t)
Last chance to execute codes before job fails globally.
-
handleCoordinationRequest
public final CompletableFuture<org.apache.flink.runtime.operators.coordination.CoordinationResponse> handleCoordinationRequest(org.apache.flink.runtime.operators.coordination.CoordinationRequest request)
- Specified by:
handleCoordinationRequestin interfaceorg.apache.flink.runtime.operators.coordination.CoordinationRequestHandler
-
handleEventFromOperator
public final void handleEventFromOperator(int subTaskId, int attemptNumber, org.apache.flink.runtime.operators.coordination.OperatorEvent event)- Specified by:
handleEventFromOperatorin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator
-
subtaskReset
public final void subtaskReset(int subTaskId, long checkpointId)- Specified by:
subtaskResetin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator
-
executionAttemptFailed
public void executionAttemptFailed(int subTaskId, int attemptNumber, @Nullable Throwable reason)- Specified by:
executionAttemptFailedin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator
-
executionAttemptReady
public final void executionAttemptReady(int subTaskId, int attemptNumber, org.apache.flink.runtime.operators.coordination.OperatorCoordinator.SubtaskGateway gateway)- Specified by:
executionAttemptReadyin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator
-
checkpointCoordinator
public final void checkpointCoordinator(long checkpointId, CompletableFuture<byte[]> completableFuture) throws Exception- Specified by:
checkpointCoordinatorin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator- Throws:
Exception
-
notifyCheckpointComplete
public final void notifyCheckpointComplete(long checkpointId)
- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.api.common.state.CheckpointListener- Specified by:
notifyCheckpointCompletein interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator
-
resetToCheckpoint
public final void resetToCheckpoint(long checkpointId, @Nullable byte[] checkpointData) throws Exception- Specified by:
resetToCheckpointin interfaceorg.apache.flink.runtime.operators.coordination.OperatorCoordinator- Throws:
Exception
-
runInEventLoop
protected void runInEventLoop(org.apache.flink.util.function.ThrowingRunnable<Throwable> action, String actionName, Object... actionNameFormatParameters)
Run a time-consuming task in givenExecutorService. All overridable functions have been wrapped inside already, so there's no need to call this method again. However, if you're overriding methods fromOperatorCoordinatororCoordinationRequestHandlerdirectly, make sure you're running heavy logics inside, or the entire job might hang!
-
loopUntil
protected void loopUntil(java.util.function.BooleanSupplier conditionChecker, Runnable message, java.time.Duration timeout, java.time.Duration interval) throws TimeoutExceptionKeeps checking ifconditionCheckeris satisfied. If not, emit a message and retry.- Throws:
TimeoutException
-
loopWhen
protected void loopWhen(java.util.function.BooleanSupplier conditionChecker, Runnable message, java.time.Duration timeout, java.time.Duration interval) throws TimeoutExceptionKeeps checking ifconditionCheckeris satisfied. Otherwise, emit a message and retry.- Throws:
TimeoutException
-
emplaceOriginalSchema
@VisibleForTesting public void emplaceOriginalSchema(TableId tableId, Schema schema)
-
emplaceEvolvedSchema
@VisibleForTesting public void emplaceEvolvedSchema(TableId tableId, Schema schema)
-
-