Skip to content

Commit 04aa5a1

Browse files
authored
[fix](binlog) Persist row binlog config updates in cloud mode (#68094)
### What problem does this PR solve? Issue Number: None Related PR: None Problem Summary: Updating ROW binlog retention properties in cloud mode used the shared-nothing UPDATE_TABLET_META_INFO agent task. Cloud backends do not register that task because tablet metadata is owned by MetaService, so every backend rejected it and the FE timed out. Route cloud binlog config changes through the existing update-tablet MetaService API, persist the config, and refresh cached CloudTablet metadata on backends. ### Release note Fix updating ROW binlog retention properties in cloud mode. ### Check List (For Author) - Test: Unit Test - CloudSchemaChangeHandlerTest - MetaServiceTest.UpdateTablet - CloudTabletSyncMetaTest.TestSyncMetaMultipleProperties - Behavior changed: Yes (ROW binlog property updates in cloud mode now use the cloud metadata path.) - Does this need documentation: No
1 parent b0f266a commit 04aa5a1

10 files changed

Lines changed: 139 additions & 6 deletions

File tree

‎be/src/cloud/cloud_tablet.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,7 @@ Result<std::unique_ptr<RowsetWriter>> CloudTablet::create_rowset_writer(
846846
context.enable_unique_key_merge_on_write = enable_unique_key_merge_on_write();
847847
context.encrypt_algorithm = tablet_meta()->encryption_algorithm();
848848
if (context.write_binlog_opt().enable) {
849-
context.write_binlog_opt().set_need_before(
850-
tablet_meta()->binlog_config().need_historical_value());
849+
context.write_binlog_opt().set_need_before(binlog_config().need_historical_value());
851850
}
852851
context.inverted_index_storage_format = tablet_meta()->inverted_index_storage_format();
853852
context.persist_inverted_index_storage_format =
@@ -891,8 +890,7 @@ Result<std::unique_ptr<RowsetWriter>> CloudTablet::create_transient_rowset_write
891890
context.is_transient_rowset_writer = true;
892891
if (rowset.rowset_meta() != nullptr && rowset.rowset_meta()->is_row_binlog()) {
893892
context.write_binlog_opt().enable = true;
894-
context.write_binlog_opt().set_need_before(
895-
tablet_meta()->binlog_config().need_historical_value());
893+
context.write_binlog_opt().set_need_before(binlog_config().need_historical_value());
896894
}
897895
context.rowset_id = rowset.rowset_id();
898896
context.tablet_id = tablet_id();
@@ -1577,6 +1575,7 @@ Status CloudTablet::sync_meta() {
15771575
auto new_disable_auto_compaction = tablet_meta->tablet_schema()->disable_auto_compaction();
15781576
auto new_vertical_compaction_num_columns_per_group =
15791577
tablet_meta->vertical_compaction_num_columns_per_group();
1578+
auto new_binlog_config = tablet_meta->binlog_config();
15801579

15811580
{
15821581
std::unique_lock wlock(_meta_lock);
@@ -1621,6 +1620,9 @@ Status CloudTablet::sync_meta() {
16211620
_tablet_meta->set_vertical_compaction_num_columns_per_group(
16221621
new_vertical_compaction_num_columns_per_group);
16231622
}
1623+
if (_tablet_meta->binlog_config() != new_binlog_config) {
1624+
_tablet_meta->set_binlog_config(new_binlog_config);
1625+
}
16241626
}
16251627

16261628
last_sync_tablet_meta_time_s = ::time(nullptr);

‎be/src/storage/binlog_config.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class BinlogConfig {
4646
BinlogConfig& operator=(BinlogConfig&&) = default;
4747
~BinlogConfig() = default;
4848

49+
bool operator==(const BinlogConfig&) const = default;
50+
4951
bool is_enable() const { return _enable; }
5052
void set_enable(bool enable) { _enable = enable; }
5153

‎be/src/storage/tablet/base_tablet.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,9 +1581,9 @@ Status BaseTablet::update_delete_bitmap(const BaseTabletSPtr& self, TabletTxnInf
15811581
binlog_rs->rowset_meta()->is_row_binlog()) {
15821582
DCHECK(txn_info->attach_row_binlog.tablet != nullptr);
15831583
row_binlog_rowset = binlog_rs;
1584-
const auto& binlog_tablet_meta = txn_info->attach_row_binlog.tablet->tablet_meta();
15851584
build_row_binlog =
1586-
is_partial_update || binlog_tablet_meta->binlog_config().need_historical_value();
1585+
is_partial_update ||
1586+
txn_info->attach_row_binlog.tablet->binlog_config().need_historical_value();
15871587
}
15881588

15891589
// rewrite conflict only when partial update or need before

‎be/src/storage/tablet/base_tablet.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ class BaseTablet : public std::enable_shared_from_this<BaseTablet> {
103103
// Property encapsulated in TabletMeta
104104
const TabletMetaSharedPtr& tablet_meta() const { return _tablet_meta; }
105105

106+
BinlogConfig binlog_config() const {
107+
std::shared_lock rlock(_meta_lock);
108+
return _tablet_meta->binlog_config();
109+
}
110+
106111
int32_t max_version_config();
107112

108113
// FIXME(plat1ko): It is not appropriate to expose this lock

‎be/test/cloud/cloud_tablet_test.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <chrono>
2626
#include <cstdint>
27+
#include <future>
28+
#include <mutex>
2729

2830
#include "cloud/cloud_meta_mgr.h"
2931
#include "cloud/cloud_storage_engine.h"
@@ -1004,6 +1006,8 @@ TEST_F(CloudTabletSyncMetaTest, TestSyncMetaMultipleProperties) {
10041006
mock_tablet_meta->set_time_series_compaction_empty_rowsets_threshold(9);
10051007
mock_tablet_meta->set_time_series_compaction_level_threshold(7);
10061008
mock_tablet_meta->set_vertical_compaction_num_columns_per_group(13);
1009+
mock_tablet_meta->set_binlog_config(
1010+
BinlogConfig(true, 3600, 4096, 7, BinlogFormatPB::ROW, true));
10071011

10081012
// Mock get_tablet_meta to return tablet_meta with updated properties
10091013
sp->set_call_back("CloudMetaMgr::get_tablet_meta", [mock_tablet_meta](auto&& args) {
@@ -1027,11 +1031,37 @@ TEST_F(CloudTabletSyncMetaTest, TestSyncMetaMultipleProperties) {
10271031
EXPECT_EQ(_tablet->tablet_meta()->time_series_compaction_empty_rowsets_threshold(), 9);
10281032
EXPECT_EQ(_tablet->tablet_meta()->time_series_compaction_level_threshold(), 7);
10291033
EXPECT_EQ(_tablet->tablet_meta()->vertical_compaction_num_columns_per_group(), 13);
1034+
auto binlog_config = _tablet->binlog_config();
1035+
EXPECT_TRUE(binlog_config.is_enable());
1036+
EXPECT_EQ(binlog_config.ttl_seconds(), 3600);
1037+
EXPECT_EQ(binlog_config.max_bytes(), 4096);
1038+
EXPECT_EQ(binlog_config.max_history_nums(), 7);
1039+
EXPECT_EQ(binlog_config.binlog_format(), BinlogFormatPB::ROW);
1040+
EXPECT_TRUE(binlog_config.need_historical_value());
10301041

10311042
sp->disable_processing();
10321043
sp->clear_all_call_backs();
10331044
}
10341045

1046+
TEST_F(CloudTabletSyncMetaTest, TestBinlogConfigReadUsesMetaLock) {
1047+
std::unique_lock meta_lock(_tablet->get_header_lock());
1048+
std::promise<void> reader_started;
1049+
auto reader_started_future = reader_started.get_future();
1050+
auto read_future = std::async(std::launch::async, [&]() {
1051+
reader_started.set_value();
1052+
return _tablet->binlog_config();
1053+
});
1054+
1055+
auto reader_started_status = reader_started_future.wait_for(seconds(5));
1056+
auto read_blocked_status = read_future.wait_for(milliseconds(100));
1057+
meta_lock.unlock();
1058+
1059+
EXPECT_EQ(reader_started_status, std::future_status::ready);
1060+
EXPECT_EQ(read_blocked_status, std::future_status::timeout);
1061+
ASSERT_EQ(read_future.wait_for(seconds(5)), std::future_status::ready);
1062+
EXPECT_EQ(read_future.get(), _tablet->binlog_config());
1063+
}
1064+
10351065
TEST_F(CloudTabletSyncMetaTest, TestSyncMetaSyncsTtlWithoutChangingInMemory) {
10361066
EXPECT_EQ(0, _tablet->tablet_meta()->ttl_seconds());
10371067
EXPECT_FALSE(_tablet->tablet_meta()->tablet_schema()->is_in_memory());

‎cloud/src/meta-service/meta_service.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,8 @@ void MetaServiceImpl::update_tablet(::google::protobuf::RpcController* controlle
12041204
tablet_meta.set_is_persistent(tablet_meta_info.is_persistent());
12051205
} else if (tablet_meta_info.has_ttl_seconds()) {
12061206
tablet_meta.set_ttl_seconds(tablet_meta_info.ttl_seconds());
1207+
} else if (tablet_meta_info.has_binlog_config()) {
1208+
tablet_meta.mutable_binlog_config()->CopyFrom(tablet_meta_info.binlog_config());
12071209
} else if (tablet_meta_info.has_compaction_policy()) {
12081210
tablet_meta.set_compaction_policy(tablet_meta_info.compaction_policy());
12091211
} else if (tablet_meta_info.has_time_series_compaction_goal_size_mbytes()) {

‎cloud/test/meta_service_test.cpp‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5360,6 +5360,40 @@ TEST(MetaServiceTest, UpdateTablet) {
53605360
ASSERT_EQ(resp.status().code(), MetaServiceCode::OK);
53615361
}
53625362
get_and_check_tablet_meta(tablet_id1, 300, true, true);
5363+
{
5364+
brpc::Controller cntl;
5365+
UpdateTabletRequest req;
5366+
UpdateTabletResponse resp;
5367+
req.set_cloud_unique_id(cloud_unique_id);
5368+
TabletMetaInfoPB* tablet_meta_info = req.add_tablet_meta_infos();
5369+
tablet_meta_info->set_tablet_id(tablet_id1);
5370+
auto* binlog_config = tablet_meta_info->mutable_binlog_config();
5371+
binlog_config->set_enable(true);
5372+
binlog_config->set_ttl_seconds(3600);
5373+
binlog_config->set_max_bytes(4096);
5374+
binlog_config->set_max_history_nums(7);
5375+
binlog_config->set_binlog_format(BinlogFormatPB::ROW);
5376+
binlog_config->set_need_historical_value(true);
5377+
meta_service->update_tablet(&cntl, &req, &resp, nullptr);
5378+
ASSERT_EQ(resp.status().code(), MetaServiceCode::OK);
5379+
}
5380+
{
5381+
brpc::Controller cntl;
5382+
GetTabletRequest req;
5383+
req.set_cloud_unique_id(cloud_unique_id);
5384+
req.set_tablet_id(tablet_id1);
5385+
GetTabletResponse resp;
5386+
meta_service->get_tablet(&cntl, &req, &resp, nullptr);
5387+
ASSERT_EQ(resp.status().code(), MetaServiceCode::OK);
5388+
ASSERT_TRUE(resp.tablet_meta().has_binlog_config());
5389+
const auto& binlog_config = resp.tablet_meta().binlog_config();
5390+
EXPECT_TRUE(binlog_config.enable());
5391+
EXPECT_EQ(binlog_config.ttl_seconds(), 3600);
5392+
EXPECT_EQ(binlog_config.max_bytes(), 4096);
5393+
EXPECT_EQ(binlog_config.max_history_nums(), 7);
5394+
EXPECT_EQ(binlog_config.binlog_format(), BinlogFormatPB::ROW);
5395+
EXPECT_TRUE(binlog_config.need_historical_value());
5396+
}
53635397
}
53645398

53655399
TEST(MetaServiceTest, GetTabletStatsTest) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.doris.cloud.alter;
1919

2020
import org.apache.doris.alter.SchemaChangeHandler;
21+
import org.apache.doris.catalog.BinlogConfig;
2122
import org.apache.doris.catalog.Database;
2223
import org.apache.doris.catalog.Env;
2324
import org.apache.doris.catalog.KeysType;
@@ -426,6 +427,18 @@ public void updateTableProperties(Database db, String tableName, Map<String, Str
426427
DynamicPartitionUtil.registerOrRemoveDynamicPartitionTable(db.getId(), olapTable, false);
427428
}
428429

430+
@Override
431+
public void updatePartitionProperties(Database db, String tableName, String partitionName,
432+
long storagePolicyId, int isInMemory, BinlogConfig binlogConfig, String compactionPolicy,
433+
Map<String, Long> timeSeriesCompactionConfig, int skipWriteIndexOnLoad,
434+
int disableAutoCompaction, int verticalCompactionNumColumnsPerGroup) throws UserException {
435+
Preconditions.checkNotNull(binlogConfig);
436+
UpdatePartitionMetaParam param = new UpdatePartitionMetaParam();
437+
param.binlogConfig = binlogConfig;
438+
param.type = UpdatePartitionMetaParam.TabletMetaType.BINLOG_CONFIG;
439+
updateCloudPartitionMeta(db, tableName, partitionName, param);
440+
}
441+
429442
private static class UpdatePartitionMetaParam {
430443
public enum TabletMetaType {
431444
INMEMORY,
@@ -443,6 +456,7 @@ public enum TabletMetaType {
443456
DISABLE_AUTO_COMPACTION,
444457
ENABLE_MOW_LIGHT_DELETE,
445458
VERTICAL_COMPACTION_NUM_COLUMNS_PER_GROUP,
459+
BINLOG_CONFIG,
446460
}
447461

448462
TabletMetaType type;
@@ -461,6 +475,7 @@ public enum TabletMetaType {
461475
boolean disableAutoCompaction = false;
462476
boolean enableMowLightDelete = false;
463477
int verticalCompactionNumColumnsPerGroup = 5;
478+
BinlogConfig binlogConfig;
464479
}
465480

466481
public void updateCloudPartitionMeta(Database db,
@@ -550,6 +565,9 @@ public void updateCloudPartitionMeta(Database db,
550565
infoBuilder.setVerticalCompactionNumColumnsPerGroup(
551566
param.verticalCompactionNumColumnsPerGroup);
552567
break;
568+
case BINLOG_CONFIG:
569+
infoBuilder.setBinlogConfig(param.binlogConfig.toProtobuf());
570+
break;
553571
default:
554572
throw new UserException("Unknown TabletMetaType");
555573
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.doris.cloud.alter;
1919

20+
import org.apache.doris.catalog.BinlogConfig;
2021
import org.apache.doris.catalog.Database;
2122
import org.apache.doris.catalog.Env;
2223
import org.apache.doris.catalog.KeysType;
@@ -155,6 +156,44 @@ public void testUpdateTablePropertiesNotifiesAllAliveBackendsInBatches() throws
155156
Assertions.assertEquals(Arrays.asList(103L), syncRequests.get(3).getTabletIdsList());
156157
}
157158

159+
@Test
160+
public void testUpdateBinlogConfigUsesCloudTabletMeta() throws Exception {
161+
CloudSchemaChangeHandler handler = new CloudSchemaChangeHandler();
162+
Database db = createMockDatabaseWithThreeTablets();
163+
BinlogConfig binlogConfig = new BinlogConfig(true, 3600L, 4096L, 7L,
164+
BinlogConfig.BinlogFormat.ROW, true);
165+
166+
MetaServiceProxy metaServiceProxy = Mockito.mock(MetaServiceProxy.class);
167+
Mockito.when(metaServiceProxy.updateTablet(Mockito.any())).thenReturn(okUpdateTabletResponse());
168+
Config.enable_debug_points = true;
169+
DebugPointUtil.addDebugPoint("CloudSchemaChangeHandler.notifyBackendsToSyncTabletMeta.skip");
170+
171+
try (MockedStatic<MetaServiceProxy> metaProxyMock = Mockito.mockStatic(MetaServiceProxy.class)) {
172+
metaProxyMock.when(MetaServiceProxy::getInstance).thenReturn(metaServiceProxy);
173+
handler.updatePartitionProperties(db, "tbl", "p1", -1, -1, binlogConfig,
174+
null, null, -1, -1, -1);
175+
}
176+
177+
ArgumentCaptor<Cloud.UpdateTabletRequest> updateCaptor =
178+
ArgumentCaptor.forClass(Cloud.UpdateTabletRequest.class);
179+
Mockito.verify(metaServiceProxy, Mockito.times(2)).updateTablet(updateCaptor.capture());
180+
List<Cloud.TabletMetaInfoPB> tabletMetaInfos = updateCaptor.getAllValues().stream()
181+
.flatMap(request -> request.getTabletMetaInfosList().stream())
182+
.collect(Collectors.toList());
183+
Assertions.assertEquals(Arrays.asList(101L, 102L, 103L), tabletMetaInfos.stream()
184+
.map(Cloud.TabletMetaInfoPB::getTabletId).collect(Collectors.toList()));
185+
for (Cloud.TabletMetaInfoPB tabletMetaInfo : tabletMetaInfos) {
186+
Assertions.assertTrue(tabletMetaInfo.hasBinlogConfig());
187+
Assertions.assertTrue(tabletMetaInfo.getBinlogConfig().getEnable());
188+
Assertions.assertEquals(3600L, tabletMetaInfo.getBinlogConfig().getTtlSeconds());
189+
Assertions.assertEquals(4096L, tabletMetaInfo.getBinlogConfig().getMaxBytes());
190+
Assertions.assertEquals(7L, tabletMetaInfo.getBinlogConfig().getMaxHistoryNums());
191+
Assertions.assertEquals(org.apache.doris.proto.OlapFile.BinlogFormatPB.ROW,
192+
tabletMetaInfo.getBinlogConfig().getBinlogFormat());
193+
Assertions.assertTrue(tabletMetaInfo.getBinlogConfig().getNeedHistoricalValue());
194+
}
195+
}
196+
158197
@Test
159198
public void testUpdateCompactionPolicyExcludesRowBinlogTablets() throws Exception {
160199
CloudSchemaChangeHandler handler = new CloudSchemaChangeHandler();

‎gensrc/proto/cloud.proto‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ message TabletMetaInfoPB { // For update tablet meta
736736
optional bool enable_mow_light_delete = 14;
737737
optional int32 vertical_compaction_num_columns_per_group = 15;
738738
optional string group_commit_mode = 16;
739+
optional doris.BinlogConfigPB binlog_config = 17;
739740
}
740741

741742
message TabletCompactionJobPB {

0 commit comments

Comments
 (0)