Implementation:Apache Shardingsphere ExclusiveOperatorEngine Execute
| Knowledge Sources | |
|---|---|
| Domains | Mode_Management, Concurrency |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Engine for executing operations under exclusive distributed locks with timeout handling.
Description
ExclusiveOperatorEngine manages the execution of operations that require exclusive access in a ShardingSphere deployment. It acquires an exclusive lock from ExclusiveOperatorContext, executes a callback, and releases the lock afterward. Supports both void callbacks and callbacks that return a result. Uses ExclusiveOperationNodePath to define the lock scope.
Usage
Use this engine when performing operations that must be mutually exclusive across nodes, such as metadata schema changes or storage unit modifications.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: ExclusiveOperatorEngine.java
- Lines: 1-72
Signature
@RequiredArgsConstructor
public final class ExclusiveOperatorEngine {
private final ExclusiveOperatorContext exclusiveOperatorContext;
public void executeInExclusive(ExclusiveOperation operation, ExclusiveOperationVoidCallback callback);
public <T> T executeInExclusive(ExclusiveOperation operation, ExclusiveOperationCallback<T> callback);
}
Import
import org.apache.shardingsphere.mode.exclusive.ExclusiveOperatorEngine;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| operation | ExclusiveOperation | Yes | Defines the operation scope and lock path |
| callback | ExclusiveOperationVoidCallback or ExclusiveOperationCallback<T> | Yes | The operation to execute under lock |
Outputs
| Name | Type | Description |
|---|---|---|
| void or T | — or generic type | Void for void callbacks; returns result for typed callbacks |
Usage Examples
ExclusiveOperatorEngine engine = new ExclusiveOperatorEngine(exclusiveOperatorContext);
// Void exclusive operation
engine.executeInExclusive(new RefreshStatisticsOperation(), () -> {
// Critical section: only one node executes at a time
statisticsManager.refreshAll();
});
// Exclusive operation with return value
boolean result = engine.executeInExclusive(new RefreshStatisticsOperation(), () -> {
return statisticsManager.tryRefresh();
});