This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 b70651d7d97 Add worker_id to the result set of `SHOW INSTANCE LIST` &
`SHOW INSTANCE INFO`. (#20067)
b70651d7d97 is described below
commit b70651d7d97d9b44568d985ae3be9ecb990dd896
Author: Raigor <[email protected]>
AuthorDate: Thu Aug 11 10:30:16 2022 +0800
Add worker_id to the result set of `SHOW INSTANCE LIST` & `SHOW INSTANCE
INFO`. (#20067)
* Add worker_id to the result of SHOW INSTANCE LIST & SHOW INSTANCE INFO.
* Update test case.
---
.../api/advice/CommandExecutorTaskAdviceTest.java | 2 +-
.../ral/queryable/ShowInstanceInfoHandler.java | 6 ++-
.../ral/queryable/ShowInstanceListHandler.java | 6 ++-
.../ral/queryable/ShowInstanceInfoHandlerTest.java | 8 +--
...rTest.java => ShowInstanceListHandlerTest.java} | 61 +++++++++++++++++-----
.../ral/queryable/ShowModeInfoHandlerTest.java | 2 +-
.../ShowSQLTranslatorRuleHandlerTest.java | 2 +-
.../queryable/ShowTableMetadataHandlerTest.java | 2 +-
.../queryable/ShowTransactionRuleHandlerTest.java | 4 +-
9 files changed, 68 insertions(+), 25 deletions(-)
diff --git
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
index 48683b0c582..39bacf5f5f7 100644
---
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
@@ -61,7 +61,7 @@ public final class CommandExecutorTaskAdviceTest extends
MetricsAdviceBaseTest {
}
@Test
- public void assertExecutorErrorTotal() {
+ public void assertExecuteErrorTotal() {
when(processException.getName()).thenReturn(CommandExecutorTaskAdvice.COMMAND_EXECUTOR_EXCEPTION);
MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
commandExecutorTaskAdvice.afterMethod(targetObject, processException,
new Object[]{}, new MethodInvocationResult());
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandler.java
index c3ddd18f46b..0278445c075 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandler.java
@@ -44,11 +44,13 @@ public final class ShowInstanceInfoHandler extends
QueryableRALBackendHandler<Sh
private static final String MODE_TYPE = "mode_type";
+ private static final String WORKER_ID = "worker_id";
+
private static final String LABELS = "labels";
@Override
protected Collection<String> getColumnNames() {
- return Arrays.asList(ID, HOST, PORT, STATUS, MODE_TYPE, LABELS);
+ return Arrays.asList(ID, HOST, PORT, STATUS, MODE_TYPE, WORKER_ID,
LABELS);
}
@Override
@@ -58,6 +60,6 @@ public final class ShowInstanceInfoHandler extends
QueryableRALBackendHandler<Sh
String modeType =
contextManager.getInstanceContext().getModeConfiguration().getType();
return Collections.singletonList(new
LocalDataQueryResultRow(instanceMetaData.getId(), instanceMetaData.getIp(),
instanceMetaData instanceof ProxyInstanceMetaData ?
((ProxyInstanceMetaData) instanceMetaData).getPort() : -1,
- instance.getState().getCurrentState().name(), modeType,
String.join(",", instance.getLabels())));
+ instance.getState().getCurrentState().name(), modeType,
instance.getWorkerId(), String.join(",", instance.getLabels())));
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandler.java
index d89a60f9a06..711d2e9b8ef 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandler.java
@@ -47,11 +47,13 @@ public final class ShowInstanceListHandler extends
QueryableRALBackendHandler<Sh
private static final String MODE_TYPE = "mode_type";
+ private static final String WORKER_ID = "worker_id";
+
private static final String LABELS = "labels";
@Override
protected Collection<String> getColumnNames() {
- return Arrays.asList(ID, HOST, PORT, STATUS, MODE_TYPE, LABELS);
+ return Arrays.asList(ID, HOST, PORT, STATUS, MODE_TYPE, WORKER_ID,
LABELS);
}
@Override
@@ -70,6 +72,6 @@ public final class ShowInstanceListHandler extends
QueryableRALBackendHandler<Sh
InstanceMetaData instanceMetaData = instance.getMetaData();
return new LocalDataQueryResultRow(instanceMetaData.getId(),
instanceMetaData.getIp(),
instanceMetaData instanceof ProxyInstanceMetaData ?
((ProxyInstanceMetaData) instanceMetaData).getPort() : -1,
- instance.getState().getCurrentState().name(), modeType,
labels);
+ instance.getState().getCurrentState().name(), modeType,
instance.getWorkerId(), labels);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
index 3c321ba0737..a9340ce1656 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
@@ -41,7 +41,7 @@ import static org.mockito.Mockito.when;
public final class ShowInstanceInfoHandlerTest extends ProxyContextRestorer {
@Test
- public void assertExecutor() throws SQLException {
+ public void assertExecute() throws SQLException {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
InstanceContext instanceContext = createInstanceContext();
when(contextManager.getInstanceContext()).thenReturn(instanceContext);
@@ -51,13 +51,14 @@ public final class ShowInstanceInfoHandlerTest extends
ProxyContextRestorer {
handler.execute();
handler.next();
List<Object> data = handler.getRowData().getData();
- assertThat(data.size(), is(6));
+ assertThat(data.size(), is(7));
assertThat(data.get(0), is("127.0.0.1@3309"));
assertThat(data.get(1), is("127.0.0.1"));
assertThat(data.get(2), is(3309));
assertThat(data.get(3), is("OK"));
assertThat(data.get(4), is("Standalone"));
- assertThat(data.get(5), is(""));
+ assertThat(data.get(5), is(0L));
+ assertThat(data.get(6), is(""));
}
private InstanceContext createInstanceContext() {
@@ -65,6 +66,7 @@ public final class ShowInstanceInfoHandlerTest extends
ProxyContextRestorer {
when(result.getInstance().getMetaData()).thenReturn(new
ProxyInstanceMetaData("127.0.0.1@3309", "127.0.0.1@3309"));
when(result.getInstance().getState()).thenReturn(new StateContext());
when(result.getModeConfiguration()).thenReturn(new
ModeConfiguration("Standalone", new
StandalonePersistRepositoryConfiguration("H2", new Properties()), true));
+ when(result.getInstance().getWorkerId()).thenReturn(0L);
return result;
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandlerTest.java
similarity index 51%
copy from
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
copy to
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandlerTest.java
index 3c321ba0737..b4d1e5ae597 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceInfoHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowInstanceListHandlerTest.java
@@ -17,8 +17,10 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceInfoStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceListStatement;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import
org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
+import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData;
import org.apache.shardingsphere.infra.state.StateContext;
@@ -29,6 +31,7 @@ import
org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
import org.junit.Test;
import java.sql.SQLException;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
@@ -38,33 +41,67 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class ShowInstanceInfoHandlerTest extends ProxyContextRestorer {
+public final class ShowInstanceListHandlerTest extends ProxyContextRestorer {
+
+ private final ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
@Test
- public void assertExecutor() throws SQLException {
- ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
- InstanceContext instanceContext = createInstanceContext();
+ public void assertExecuteWithStandaloneMode() throws SQLException {
+ InstanceContext instanceContext = createStandaloneInstanceContext();
when(contextManager.getInstanceContext()).thenReturn(instanceContext);
- ShowInstanceInfoHandler handler = new ShowInstanceInfoHandler();
- handler.init(new ShowInstanceInfoStatement(), null);
+ ShowInstanceListHandler handler = new ShowInstanceListHandler();
+ handler.init(new ShowInstanceListStatement(), null);
ProxyContext.init(contextManager);
handler.execute();
handler.next();
List<Object> data = handler.getRowData().getData();
- assertThat(data.size(), is(6));
+ assertThat(data.size(), is(7));
+ assertThat(data.get(0), is("127.0.0.1@3308"));
+ assertThat(data.get(1), is("127.0.0.1"));
+ assertThat(data.get(2), is(3308));
+ assertThat(data.get(3), is("OK"));
+ assertThat(data.get(4), is("Standalone"));
+ assertThat(data.get(5), is(0L));
+ assertThat(data.get(6), is(""));
+ }
+
+ @Test
+ public void assertExecuteWithClusterMode() throws SQLException {
+ InstanceContext instanceContext = createClusterInstanceContext();
+ when(contextManager.getInstanceContext()).thenReturn(instanceContext);
+ ShowInstanceListHandler handler = new ShowInstanceListHandler();
+ handler.init(new ShowInstanceListStatement(), null);
+ ProxyContext.init(contextManager);
+ handler.execute();
+ handler.next();
+ List<Object> data = handler.getRowData().getData();
+ assertThat(data.size(), is(7));
assertThat(data.get(0), is("127.0.0.1@3309"));
assertThat(data.get(1), is("127.0.0.1"));
assertThat(data.get(2), is(3309));
assertThat(data.get(3), is("OK"));
- assertThat(data.get(4), is("Standalone"));
- assertThat(data.get(5), is(""));
+ assertThat(data.get(4), is("Cluster"));
+ assertThat(data.get(5), is(1L));
+ assertThat(data.get(6), is(""));
}
- private InstanceContext createInstanceContext() {
+ private InstanceContext createStandaloneInstanceContext() {
InstanceContext result = mock(InstanceContext.class,
RETURNS_DEEP_STUBS);
- when(result.getInstance().getMetaData()).thenReturn(new
ProxyInstanceMetaData("127.0.0.1@3309", "127.0.0.1@3309"));
+ when(result.getInstance().getMetaData()).thenReturn(new
ProxyInstanceMetaData("127.0.0.1@3308", "127.0.0.1@3308"));
when(result.getInstance().getState()).thenReturn(new StateContext());
when(result.getModeConfiguration()).thenReturn(new
ModeConfiguration("Standalone", new
StandalonePersistRepositoryConfiguration("H2", new Properties()), true));
+ when(result.getInstance().getWorkerId()).thenReturn(0L);
+ return result;
+ }
+
+ private InstanceContext createClusterInstanceContext() {
+ InstanceContext result = mock(InstanceContext.class,
RETURNS_DEEP_STUBS);
+ when(result.getModeConfiguration()).thenReturn(new
ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), true));
+ ComputeNodeInstance computeNodeInstance =
mock(ComputeNodeInstance.class, RETURNS_DEEP_STUBS);
+ when(computeNodeInstance.getMetaData()).thenReturn(new
ProxyInstanceMetaData("127.0.0.1@3309", "127.0.0.1@3309"));
+ when(computeNodeInstance.getState()).thenReturn(new StateContext());
+ when(computeNodeInstance.getWorkerId()).thenReturn(1L);
+
when(result.getAllClusterInstances()).thenReturn(Collections.singleton(computeNodeInstance));
return result;
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowModeInfoHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowModeInfoHandlerTest.java
index ccf1ee00f2a..a878222b543 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowModeInfoHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowModeInfoHandlerTest.java
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.when;
public final class ShowModeInfoHandlerTest extends ProxyContextRestorer {
@Test
- public void assertExecutor() throws SQLException {
+ public void assertExecute() throws SQLException {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
InstanceContext instanceContext = createInstanceContext();
when(contextManager.getInstanceContext()).thenReturn(instanceContext);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLTranslatorRuleHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLTranslatorRuleHandlerTest.java
index c1f29815c64..dd362985340 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLTranslatorRuleHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLTranslatorRuleHandlerTest.java
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.when;
public final class ShowSQLTranslatorRuleHandlerTest extends
ProxyContextRestorer {
@Test
- public void assertExecutor() throws SQLException {
+ public void assertExecute() throws SQLException {
ShowSQLTranslatorRuleHandler handler = new
ShowSQLTranslatorRuleHandler();
handler.init(new ShowSQLTranslatorRuleStatement(), null);
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetadataHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetadataHandlerTest.java
index 5ff9665d1cb..618d2662377 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetadataHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTableMetadataHandlerTest.java
@@ -47,7 +47,7 @@ import static org.mockito.Mockito.when;
public final class ShowTableMetadataHandlerTest extends ProxyContextRestorer {
@Test
- public void assertExecutor() throws SQLException {
+ public void assertExecute() throws SQLException {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
when(database.getSchema("db_name")).thenReturn(new
ShardingSphereSchema(createTableMap()));
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
index 87199e2cc0e..904fe187532 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
@@ -42,7 +42,7 @@ import static org.mockito.Mockito.when;
public final class ShowTransactionRuleHandlerTest extends ProxyContextRestorer
{
@Test
- public void assertExecutorWithXA() throws SQLException {
+ public void assertExecuteWithXA() throws SQLException {
ShowTransactionRuleHandler handler = new ShowTransactionRuleHandler();
handler.init(new ShowTransactionRuleStatement(), null);
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
@@ -61,7 +61,7 @@ public final class ShowTransactionRuleHandlerTest extends
ProxyContextRestorer {
}
@Test
- public void assertExecutorWithLocal() throws SQLException {
+ public void assertExecuteWithLocal() throws SQLException {
ShowTransactionRuleHandler handler = new ShowTransactionRuleHandler();
handler.init(new ShowTransactionRuleStatement(), null);
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);