Skip to content

Commit e85575e

Browse files
authored
[fix](binlog) Preserve row binlog compaction policy (apache#68033)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: Changing a cloud table compaction policy sent the same policy to every visible index, including hidden row-binlog tablets. Those tablets require the dedicated binlog policy, so the ALTER persisted and synchronized an incompatible policy. Exclude row-binlog indexes from compaction-policy updates while preserving their inclusion for other tablet metadata updates. ### Release note Preserve the dedicated binlog compaction policy on hidden row-binlog tablets when altering a cloud table compaction policy. ### Check List (For Author) - Test: Unit Test - FE_UT_PARALLEL=1 bash run-fe-ut.sh --run CloudSchemaChangeHandlerTest - Behavior changed: Yes. Cloud compaction-policy ALTER no longer updates hidden row-binlog tablets. - Does this need documentation: No
1 parent 64d2911 commit e85575e

2 files changed

Lines changed: 92 additions & 1 deletion

File tree

‎fe/fe-core/src/main/java/org/apache/doris/cloud/alter/CloudSchemaChangeHandler.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ public void updateCloudPartitionMeta(Database db,
476476
throw new DdlException(
477477
"Partition[" + partitionName + "] does not exist in table[" + olapTable.getName() + "]");
478478
}
479-
for (MaterializedIndex index : partition.getMaterializedIndices(IndexExtState.VISIBLE, true)) {
479+
boolean includeRowBinlog = param.type != UpdatePartitionMetaParam.TabletMetaType.COMPACTION_POLICY;
480+
for (MaterializedIndex index
481+
: partition.getMaterializedIndices(IndexExtState.VISIBLE, includeRowBinlog)) {
480482
for (Tablet tablet : index.getTablets()) {
481483
tabletIds.add(tablet.getId());
482484
}

‎fe/fe-core/src/test/java/org/apache/doris/cloud/alter/CloudSchemaChangeHandlerTest.java‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,66 @@ public void testUpdateTablePropertiesNotifiesAllAliveBackendsInBatches() throws
155155
Assertions.assertEquals(Arrays.asList(103L), syncRequests.get(3).getTabletIdsList());
156156
}
157157

158+
@Test
159+
public void testUpdateCompactionPolicyExcludesRowBinlogTablets() throws Exception {
160+
CloudSchemaChangeHandler handler = new CloudSchemaChangeHandler();
161+
Database db = createMockDatabaseWithRowBinlogTablet();
162+
Env env = Mockito.mock(Env.class);
163+
MetaServiceProxy metaServiceProxy = Mockito.mock(MetaServiceProxy.class);
164+
Mockito.when(metaServiceProxy.updateTablet(Mockito.any())).thenReturn(okUpdateTabletResponse());
165+
166+
Config.enable_debug_points = true;
167+
DebugPointUtil.addDebugPoint("CloudSchemaChangeHandler.notifyBackendsToSyncTabletMeta.skip");
168+
try (MockedStatic<Env> envMock = Mockito.mockStatic(Env.class);
169+
MockedStatic<MetaServiceProxy> metaProxyMock = Mockito.mockStatic(MetaServiceProxy.class)) {
170+
envMock.when(Env::getCurrentEnv).thenReturn(env);
171+
metaProxyMock.when(MetaServiceProxy::getInstance).thenReturn(metaServiceProxy);
172+
173+
Map<String, String> properties = new HashMap<>();
174+
properties.put(PropertyAnalyzer.PROPERTIES_COMPACTION_POLICY,
175+
PropertyAnalyzer.TIME_SERIES_COMPACTION_POLICY);
176+
handler.updateTableProperties(db, "tbl", properties);
177+
}
178+
179+
ArgumentCaptor<Cloud.UpdateTabletRequest> updateCaptor =
180+
ArgumentCaptor.forClass(Cloud.UpdateTabletRequest.class);
181+
Mockito.verify(metaServiceProxy).updateTablet(updateCaptor.capture());
182+
List<Cloud.TabletMetaInfoPB> tabletMetaInfos = updateCaptor.getValue().getTabletMetaInfosList();
183+
Assertions.assertEquals(Arrays.asList(101L), tabletMetaInfos.stream()
184+
.map(Cloud.TabletMetaInfoPB::getTabletId).collect(Collectors.toList()));
185+
Assertions.assertTrue(tabletMetaInfos.stream().allMatch(info ->
186+
PropertyAnalyzer.TIME_SERIES_COMPACTION_POLICY.equals(info.getCompactionPolicy())));
187+
}
188+
189+
@Test
190+
public void testUpdateTtlIncludesRowBinlogTablets() throws Exception {
191+
CloudSchemaChangeHandler handler = new CloudSchemaChangeHandler();
192+
Database db = createMockDatabaseWithRowBinlogTablet();
193+
Env env = Mockito.mock(Env.class);
194+
MetaServiceProxy metaServiceProxy = Mockito.mock(MetaServiceProxy.class);
195+
Mockito.when(metaServiceProxy.updateTablet(Mockito.any())).thenReturn(okUpdateTabletResponse());
196+
197+
Config.enable_debug_points = true;
198+
DebugPointUtil.addDebugPoint("CloudSchemaChangeHandler.notifyBackendsToSyncTabletMeta.skip");
199+
try (MockedStatic<Env> envMock = Mockito.mockStatic(Env.class);
200+
MockedStatic<MetaServiceProxy> metaProxyMock = Mockito.mockStatic(MetaServiceProxy.class)) {
201+
envMock.when(Env::getCurrentEnv).thenReturn(env);
202+
metaProxyMock.when(MetaServiceProxy::getInstance).thenReturn(metaServiceProxy);
203+
204+
Map<String, String> properties = new HashMap<>();
205+
properties.put(PropertyAnalyzer.PROPERTIES_FILE_CACHE_TTL_SECONDS, "300");
206+
handler.updateTableProperties(db, "tbl", properties);
207+
}
208+
209+
ArgumentCaptor<Cloud.UpdateTabletRequest> updateCaptor =
210+
ArgumentCaptor.forClass(Cloud.UpdateTabletRequest.class);
211+
Mockito.verify(metaServiceProxy).updateTablet(updateCaptor.capture());
212+
List<Cloud.TabletMetaInfoPB> tabletMetaInfos = updateCaptor.getValue().getTabletMetaInfosList();
213+
Assertions.assertEquals(Arrays.asList(101L, 201L), tabletMetaInfos.stream()
214+
.map(Cloud.TabletMetaInfoPB::getTabletId).collect(Collectors.toList()));
215+
Assertions.assertTrue(tabletMetaInfos.stream().allMatch(info -> info.getTtlSeconds() == 300));
216+
}
217+
158218
@Test
159219
public void testUpdateTablePropertiesThrowsWhenUpdateTabletFails() throws Exception {
160220
CloudSchemaChangeHandler handler = new CloudSchemaChangeHandler();
@@ -552,13 +612,42 @@ private Database createMockDatabaseWithThreeTablets() throws Exception {
552612
Mockito.when(partition.getName()).thenReturn("p1");
553613
Mockito.when(partition.getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE, true))
554614
.thenReturn(Arrays.asList(index));
615+
Mockito.when(partition.getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE, false))
616+
.thenReturn(Arrays.asList(index));
555617
Mockito.when(index.getTablets()).thenReturn(Arrays.asList(tablet1, tablet2, tablet3));
556618
Mockito.when(tablet1.getId()).thenReturn(101L);
557619
Mockito.when(tablet2.getId()).thenReturn(102L);
558620
Mockito.when(tablet3.getId()).thenReturn(103L);
559621
return db;
560622
}
561623

624+
private Database createMockDatabaseWithRowBinlogTablet() throws Exception {
625+
Database db = Mockito.mock(Database.class);
626+
OlapTable table = Mockito.mock(OlapTable.class);
627+
Partition partition = Mockito.mock(Partition.class);
628+
MaterializedIndex baseIndex = Mockito.mock(MaterializedIndex.class);
629+
MaterializedIndex rowBinlogIndex = Mockito.mock(MaterializedIndex.class);
630+
org.apache.doris.catalog.Tablet baseTablet = Mockito.mock(org.apache.doris.catalog.Tablet.class);
631+
org.apache.doris.catalog.Tablet rowBinlogTablet = Mockito.mock(org.apache.doris.catalog.Tablet.class);
632+
633+
Mockito.when(db.getTableOrMetaException("tbl", Table.TableType.OLAP)).thenReturn(table);
634+
Mockito.when(table.getName()).thenReturn("tbl");
635+
Mockito.when(table.getCompactionPolicy()).thenReturn(PropertyAnalyzer.SIZE_BASED_COMPACTION_POLICY);
636+
Mockito.when(table.getKeysType()).thenReturn(KeysType.DUP_KEYS);
637+
Mockito.when(table.getPartitions()).thenReturn(Arrays.asList(partition));
638+
Mockito.when(table.getPartition("p1")).thenReturn(partition);
639+
Mockito.when(partition.getName()).thenReturn("p1");
640+
Mockito.when(partition.getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE, true))
641+
.thenReturn(Arrays.asList(baseIndex, rowBinlogIndex));
642+
Mockito.when(partition.getMaterializedIndices(MaterializedIndex.IndexExtState.VISIBLE, false))
643+
.thenReturn(Arrays.asList(baseIndex));
644+
Mockito.when(baseIndex.getTablets()).thenReturn(Arrays.asList(baseTablet));
645+
Mockito.when(rowBinlogIndex.getTablets()).thenReturn(Arrays.asList(rowBinlogTablet));
646+
Mockito.when(baseTablet.getId()).thenReturn(101L);
647+
Mockito.when(rowBinlogTablet.getId()).thenReturn(201L);
648+
return db;
649+
}
650+
562651
private InternalService.PSyncTabletMetaResponse okSyncTabletMetaResponse() {
563652
return InternalService.PSyncTabletMetaResponse.newBuilder()
564653
.setStatus(org.apache.doris.proto.Types.PStatus.newBuilder()

0 commit comments

Comments
 (0)