This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new d710c2029e4 Remove ComputeNodeInstance.getCurrentInstanceId() (#31291)
d710c2029e4 is described below
commit d710c2029e427e26d35c548dd61117c4db8a49d2
Author: Liang Zhang <[email protected]>
AuthorDate: Sun May 19 15:28:05 2024 +0800
Remove ComputeNodeInstance.getCurrentInstanceId() (#31291)
---
.../org/apache/shardingsphere/infra/instance/InstanceContext.java | 2 +-
.../mode/manager/cluster/ClusterContextManagerBuilder.java | 4 ++--
.../zookeeper/listener/SessionConnectionReconnectListener.java | 2 +-
.../backend/handler/distsql/ral/queryable/ExportMetaDataExecutor.java | 4 ++--
.../handler/distsql/ral/queryable/ExportStorageNodesExecutor.java | 4 ++--
.../handler/distsql/ral/updatable/SetInstanceStatusExecutor.java | 2 +-
.../handler/distsql/ral/updatable/SetInstanceStatusExecutorTest.java | 4 ++--
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index a79f690b1b9..7bd7c3be30e 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -169,7 +169,7 @@ public final class InstanceContext {
* @return compute node instance
*/
public Optional<ComputeNodeInstance> getComputeNodeInstanceById(final
String instanceId) {
- return allClusterInstances.stream().filter(each ->
instanceId.equals(each.getCurrentInstanceId())).findFirst();
+ return allClusterInstances.stream().filter(each ->
instanceId.equals(each.getMetaData().getId())).findFirst();
}
/**
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 8485b119ea6..bc27480d83e 100644
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -116,8 +116,8 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
final ClusterPersistRepository repository,
final ContextManagerBuilderParameter param, final ContextManager
contextManager) {
ComputeNodeStatusService computeNodeStatusService = new
ComputeNodeStatusService(repository);
computeNodeStatusService.registerOnline(instanceContext.getInstance().getMetaData());
-
computeNodeStatusService.persistInstanceLabels(instanceContext.getInstance().getCurrentInstanceId(),
instanceContext.getInstance().getLabels());
-
computeNodeStatusService.persistInstanceState(instanceContext.getInstance().getCurrentInstanceId(),
instanceContext.getInstance().getState());
+
computeNodeStatusService.persistInstanceLabels(instanceContext.getInstance().getMetaData().getId(),
instanceContext.getInstance().getLabels());
+
computeNodeStatusService.persistInstanceState(instanceContext.getInstance().getMetaData().getId(),
instanceContext.getInstance().getState());
new GovernanceWatcherFactory(repository,
eventBusContext, param.getInstanceMetaData() instanceof
JDBCInstanceMetaData ? param.getDatabaseConfigs().keySet() :
Collections.emptyList()).watchListeners();
contextManager.getInstanceContext().getInstance().setLabels(param.getLabels());
diff --git
a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionReconnectListener.java
b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionReconnectListener.java
index 092d2058323..bbba6569415 100644
---
a/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionReconnectListener.java
+++
b/mode/type/cluster/repository/provider/zookeeper/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionReconnectListener.java
@@ -54,7 +54,7 @@ public final class SessionConnectionReconnectListener
implements ConnectionState
do {
isReconnectFailed = !reconnect(client);
} while (isReconnectFailed);
- log.info("Instance reconnect success, instance ID: {}",
instanceContext.getInstance().getCurrentInstanceId());
+ log.info("Instance reconnect success, instance ID: {}",
instanceContext.getInstance().getMetaData().getId());
}
private boolean reconnect(final CuratorFramework client) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutor.java
index bd7cbeb1805..32e5e1eb12d 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportMetaDataExecutor.java
@@ -63,11 +63,11 @@ public final class ExportMetaDataExecutor implements
DistSQLQueryExecutor<Export
if (sqlStatement.getFilePath().isPresent()) {
String filePath = sqlStatement.getFilePath().get();
ExportUtils.exportToFile(filePath, exportedData);
- return Collections.singleton(new
LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getCurrentInstanceId(),
LocalDateTime.now(),
+ return Collections.singleton(new
LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getMetaData().getId(),
LocalDateTime.now(),
String.format("Successfully exported to:'%s'", filePath)));
}
return Collections.singleton(new LocalDataQueryResultRow(
-
contextManager.getInstanceContext().getInstance().getCurrentInstanceId(),
LocalDateTime.now(), Base64.encodeBase64String(exportedData.getBytes())));
+
contextManager.getInstanceContext().getInstance().getMetaData().getId(),
LocalDateTime.now(), Base64.encodeBase64String(exportedData.getBytes())));
}
private String generateExportData(final ShardingSphereMetaData metaData) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java
index 195056c402a..6748091fc70 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportStorageNodesExecutor.java
@@ -57,11 +57,11 @@ public final class ExportStorageNodesExecutor implements
DistSQLQueryExecutor<Ex
if (sqlStatement.getFilePath().isPresent()) {
String filePath = sqlStatement.getFilePath().get();
ExportUtils.exportToFile(filePath, exportedData);
- return Collections.singleton(new
LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getCurrentInstanceId(),
LocalDateTime.now(),
+ return Collections.singleton(new
LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getMetaData().getId(),
LocalDateTime.now(),
String.format("Successfully exported to:'%s'", filePath)));
}
return Collections.singleton(
- new
LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getCurrentInstanceId(),
LocalDateTime.now(), exportedData));
+ new
LocalDataQueryResultRow(contextManager.getInstanceContext().getInstance().getMetaData().getId(),
LocalDateTime.now(), exportedData));
}
private void checkSQLStatement(final ShardingSphereMetaData metaData,
final ExportStorageNodesStatement sqlStatement) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutor.java
index 6549ab5c780..29aa777cd86 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutor.java
@@ -49,7 +49,7 @@ public final class SetInstanceStatusExecutor implements
DistSQLUpdateExecutor<Se
}
private void checkDisablingIsValid(final ContextManager contextManager,
final String instanceId) {
-
ShardingSpherePreconditions.checkState(!contextManager.getInstanceContext().getInstance().getCurrentInstanceId().equals(instanceId),
+
ShardingSpherePreconditions.checkState(!contextManager.getInstanceContext().getInstance().getMetaData().getId().equals(instanceId),
() -> new UnsupportedSQLOperationException(String.format("`%s`
is the currently in use instance and cannot be disabled", instanceId)));
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().getComputeNodeInstanceById(instanceId).isPresent(),
() -> new UnsupportedSQLOperationException(String.format("`%s`
does not exist", instanceId)));
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutorTest.java
index cdc1832adfe..5e9b2f53e65 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/SetInstanceStatusExecutorTest.java
@@ -40,14 +40,14 @@ class SetInstanceStatusExecutorTest {
@Test
void assertExecuteUpdateWithCurrentUsingInstance() {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
-
when(contextManager.getInstanceContext().getInstance().getCurrentInstanceId()).thenReturn("instanceID");
+
when(contextManager.getInstanceContext().getInstance().getMetaData().getId()).thenReturn("instanceID");
assertThrows(UnsupportedSQLOperationException.class, () ->
executor.executeUpdate(new SetInstanceStatusStatement("DISABLE", "instanceID"),
contextManager));
}
@Test
void assertExecuteUpdateWithAlreadyDisableInstance() {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
-
when(contextManager.getInstanceContext().getInstance().getCurrentInstanceId()).thenReturn("currentInstance");
+
when(contextManager.getInstanceContext().getInstance().getMetaData().getId()).thenReturn("currentInstance");
when(contextManager.getInstanceContext().getComputeNodeInstanceById("instanceID").isPresent()).thenReturn(true);
when(contextManager.getInstanceContext().getComputeNodeInstanceById("instanceID").get().getState().getCurrentState()).thenReturn(InstanceState.CIRCUIT_BREAK);
assertThrows(UnsupportedSQLOperationException.class, () ->
executor.executeUpdate(new SetInstanceStatusStatement("DISABLE", "instanceID"),
contextManager));