Skip to content

Commit 48457b7

Browse files
authored
[Hotfix] Fix optimizer group not updated on table refresh (#4076)
* [Hotfix] Fix optimizer group not updated on table refresh Signed-off-by: j1wonpark <jpark92@outlook.kr> * Remove unused configChanged variable in DefaultTableRuntime.refresh() Signed-off-by: jpark92@outlook.kr Signed-off-by: Jiwon Park <jpark92@outlook.kr> --------- Signed-off-by: j1wonpark <jpark92@outlook.kr> Signed-off-by: jpark92@outlook.kr Signed-off-by: Jiwon Park <jpark92@outlook.kr>
1 parent ef4f5cf commit 48457b7

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

‎amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultTableRuntime.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,9 @@ public void setTableSummary(AbstractOptimizingEvaluator.PendingInput tableSummar
309309
public DefaultTableRuntime refresh(AmoroTable<?> table) {
310310
Map<String, String> tableConfig = table.properties();
311311
TableConfiguration newConfiguration = TableConfigurations.parseTableConfig(tableConfig);
312-
TableConfiguration oldConfiguration = getTableConfiguration();
313-
boolean configChanged = !newConfiguration.equals(oldConfiguration);
312+
String newGroupName = newConfiguration.getOptimizingConfig().getOptimizerGroup();
314313

315-
if (!Objects.equals(
316-
getGroupName(), newConfiguration.getOptimizingConfig().getOptimizerGroup())) {
314+
if (!Objects.equals(getGroupName(), newGroupName)) {
317315
if (optimizingProcess != null) {
318316
optimizingProcess.close(false);
319317
}
@@ -327,6 +325,7 @@ public DefaultTableRuntime refresh(AmoroTable<?> table) {
327325
config.clear();
328326
config.putAll(tableConfig);
329327
})
328+
.updateGroup(g -> newGroupName)
330329
.updateState(
331330
OPTIMIZING_STATE_KEY,
332331
s -> {

‎amoro-ams/src/test/java/org/apache/amoro/server/table/TestDefaultTableRuntimeHandler.java‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,49 @@ public void testInitialize() throws Exception {
130130
tableService = null;
131131
}
132132

133+
@Test
134+
public void testRefreshUpdatesOptimizerGroup() throws Exception {
135+
tableService =
136+
new DefaultTableService(new Configurations(), CATALOG_MANAGER, runtimeFactoryManager);
137+
TestHandler handler = new TestHandler();
138+
tableService.addHandlerChain(handler);
139+
tableService.initialize();
140+
if (!(catalogTestHelper().tableFormat().equals(TableFormat.MIXED_HIVE)
141+
&& TEST_HMS.getHiveClient().getDatabase(TableTestHelper.TEST_DB_NAME) != null)) {
142+
createDatabase();
143+
}
144+
createTable();
145+
146+
ServerTableIdentifier tableId = tableManager().listManagedTables().get(0);
147+
DefaultTableRuntime runtime = getDefaultTableRuntime(tableId.getId());
148+
149+
// Verify initial group name is "default"
150+
String initialGroup = runtime.getGroupName();
151+
Assert.assertEquals(TableProperties.SELF_OPTIMIZING_GROUP_DEFAULT, initialGroup);
152+
153+
// Change optimizer group property
154+
String newGroupName = "new-optimizer-group";
155+
MixedTable mixedTable = (MixedTable) tableService().loadTable(tableId).originalTable();
156+
mixedTable.updateProperties().set(TableProperties.SELF_OPTIMIZING_GROUP, newGroupName).commit();
157+
158+
// Refresh the runtime
159+
runtime.refresh(tableService.loadTable(tableId));
160+
161+
// Verify that getGroupName() returns the new group name
162+
Assert.assertEquals(newGroupName, runtime.getGroupName());
163+
164+
// Verify config changed handler was called
165+
Assert.assertEquals(1, handler.getConfigChangedTables().size());
166+
167+
// Cleanup
168+
dropTable();
169+
dropDatabase();
170+
tableService.dispose();
171+
MetricManager.dispose();
172+
EventsManager.dispose();
173+
tableService = null;
174+
}
175+
133176
protected DefaultTableService tableService() {
134177
if (tableService != null) {
135178
return tableService;

0 commit comments

Comments
 (0)