swuferhong commented on code in PR #1452:
URL: https://github.com/apache/fluss/pull/1452#discussion_r2664940868
##########
fluss-flink/fluss-flink-common/src/test/java/org/apache/fluss/flink/procedure/FlinkProcedureITCase.java:
##########
@@ -460,6 +492,124 @@ void testAddAndRemoveServerTag(boolean upperCase) throws
Exception {
}
}
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void testRebalance(boolean upperCase) throws Exception {
+ // first create some unbalance assignment table.
+ for (int i = 0; i < 10; i++) {
+ String tableName = "reblance_test_tab_" + i;
+ tEnv.executeSql(
+ String.format(
+ "create table %s (a int, b varchar, c bigint, d
int ) "
+ + "with ('connector' = 'fluss',
'table.generate-unbalance-table-assignment'='true')",
+ tableName));
+ long tableId =
+ admin.getTableInfo(TablePath.of(DEFAULT_DB,
tableName)).get().getTableId();
+ FLUSS_CLUSTER_EXTENSION.waitUntilTableReady(tableId);
+ }
+
+ String rebalance =
+ String.format(
+ upperCase
+ ? "Call
%s.sys.rebalance('REPLICA_DISTRIBUTION_GOAL;LEADER_DISTRIBUTION_GOAL', true)"
+ : "Call
%s.sys.rebalance('replica_distribution_goal;leader_distribution_goal', true)",
+ CATALOG_NAME);
+ try (CloseableIterator<Row> rows =
tEnv.executeSql(rebalance).collect()) {
+ List<String> actual =
+ CollectionUtil.iteratorToList(rows).stream()
+ .map(Row::toString)
+ .collect(Collectors.toList());
+ assertThat(actual.size()).isGreaterThan(1);
+ }
+
+ // test cancel rebalance.
+ try (CloseableIterator<Row> listProceduresIterator =
+ tEnv.executeSql(String.format("Call
%s.sys.cancel_rebalance()", CATALOG_NAME))
+ .collect()) {
+ assertCallResult(listProceduresIterator, new String[]
{"+I[success]"});
+ }
+
+ // test cancel an un-existed rebalance.
+ try (CloseableIterator<Row> listProceduresIterator =
+ tEnv.executeSql(
+ String.format(
+ "Call
%s.sys.cancel_rebalance('not-exist-id')",
+ CATALOG_NAME))
+ .collect()) {
+ assertCallResult(listProceduresIterator, new String[]
{"+I[success]"});
+ }
+
+ // delete rebalance plan to avoid conflict with other tests.
+ FLUSS_CLUSTER_EXTENSION.getZooKeeperClient().deleteRebalancePlan();
+ }
+
+ @Test
+ void testListRebalanceProgress() throws Exception {
+ try (CloseableIterator<Row> listProceduresIterator =
+ tEnv.executeSql(
+ String.format(
+ "Call
%s.sys.list_rebalance_progress()", CATALOG_NAME))
+ .collect()) {
+ assertCallResult(
+ listProceduresIterator,
+ new String[] {
+ "+I[Reblance total status: NO_TASK]",
+ "+I[Rebalance progress: NONE]",
+ "+I[Rebalance detail progress for bucket:]"
+ });
+ }
+
+ // first create some unbalance assignment table.
+ for (int i = 0; i < 10; i++) {
+ String tableName = "reblance_test_tab_" + i;
+ tEnv.executeSql(
+ String.format(
+ "create table %s (a int, b varchar, c bigint, d
int ) "
+ + "with ('connector' = 'fluss',
'table.generate-unbalance-table-assignment'='true')",
+ tableName));
+ long tableId =
+ admin.getTableInfo(TablePath.of(DEFAULT_DB,
tableName)).get().getTableId();
+ FLUSS_CLUSTER_EXTENSION.waitUntilTableReady(tableId);
+ }
+
+ String rebalance =
+ String.format(
+ "Call
%s.sys.rebalance('REPLICA_DISTRIBUTION_GOAL;LEADER_DISTRIBUTION_GOAL', false)",
+ CATALOG_NAME);
+ List<String> plan;
+ try (CloseableIterator<Row> rows =
tEnv.executeSql(rebalance).collect()) {
+ plan =
+ CollectionUtil.iteratorToList(rows).stream()
+ .map(Row::toString)
+ .collect(Collectors.toList());
+ assertThat(plan.size()).isGreaterThan(1);
+ }
+
+ retry(
+ Duration.ofMinutes(2),
+ () -> {
+ try (CloseableIterator<Row> rows =
+ tEnv.executeSql(
+ String.format(
+ "Call
%s.sys.list_rebalance_progress()",
+ CATALOG_NAME))
+ .collect()) {
+ List<String> listProgressResult =
+ CollectionUtil.iteratorToList(rows).stream()
+ .map(Row::toString)
+ .collect(Collectors.toList());
+
assertThat(listProgressResult.size()).isEqualTo(plan.size() + 2);
+
assertThat(listProgressResult.get(0)).startsWith("+I[Rebalance id:");
+ assertThat(listProgressResult.get(1))
+ .isEqualTo("+I[Reblance total status:
COMPLETED]");
+ assertThat(listProgressResult.get(2))
+ .isEqualTo("+I[Rebalance progress: 100%]");
Review Comment:
'the number of completed buckets out of the total' can be calculated by the
detail result. the progress will be more useful for these user doesn't care the
detail rebalance plan.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]