AntiTopQuark commented on code in PR #68226:
URL: https://github.com/apache/doris/pull/68226#discussion_r4228781724


##########
be/src/storage/tablet/tablet_meta.cpp:
##########
@@ -857,6 +858,9 @@ void TabletMeta::init_from_pb(const TabletMetaPB& 
tablet_meta_pb) {
     // init _schema
     TabletSchemaSPtr schema = std::make_shared<TabletSchema>();
     TabletSchemaPB schema_pb = tablet_meta_pb.schema();
+    _disable_auto_compaction.store(schema_pb.disable_auto_compaction());
+    // The switch belongs to this tablet, not to the immutable schema cache 
entry.
+    schema_pb.clear_disable_auto_compaction();

Review Comment:
   done, Read the configuration for this check from TabletMeta instead of 
TabletSchema, ensuring that compaction triggered when the version count 
approaches the limit also respects the tablet’s disable_auto_compaction setting.



##########
fe/fe-core/src/main/java/org/apache/doris/binlog/RowBinlogTtlDiscovery.java:
##########
@@ -0,0 +1,165 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.binlog;
+
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.MaterializedIndex;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.catalog.Tablet;
+import org.apache.doris.cloud.catalog.CloudReplica;
+import org.apache.doris.cloud.qe.ComputeGroupException;
+import org.apache.doris.cloud.system.CloudSystemInfoService;
+import org.apache.doris.common.Config;
+import org.apache.doris.proto.InternalService;
+import org.apache.doris.rpc.BackendServiceProxy;
+import org.apache.doris.rpc.RpcException;
+import org.apache.doris.system.Backend;
+import org.apache.doris.thrift.TStatusCode;
+
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/** Bounded catalog discovery for tablets absent from a BE's metadata cache. */
+public final class RowBinlogTtlDiscovery {
+    private static final Logger LOG = 
LogManager.getLogger(RowBinlogTtlDiscovery.class);
+    private Iterator<Database> databases = Collections.emptyIterator();
+    private Iterator<Table> tables = Collections.emptyIterator();
+    private Iterator<Partition> partitions = Collections.emptyIterator();
+    private Iterator<Tablet> tablets = Collections.emptyIterator();
+    private Iterator<MaterializedIndex> indexes = Collections.emptyIterator();
+    private OlapTable currentTable;
+
+    public void discover() {
+        if (!Config.isCloudMode() || !Config.enable_feature_binlog) {
+            return;
+        }
+        try {
+            CloudSystemInfoService info = (CloudSystemInfoService) 
Env.getCurrentSystemInfo();
+            Map<Long, List<Long>> targets = new HashMap<>();
+            long deadline = System.nanoTime() + 
TimeUnit.MILLISECONDS.toNanos(50);
+            if (!databases.hasNext() && !tables.hasNext() && 
!partitions.hasNext()
+                    && !indexes.hasNext() && !tablets.hasNext()) {
+                databases = 
Env.getCurrentInternalCatalog().getDbs().iterator();
+            }
+            for (int n = 0; n < 64 && System.nanoTime() < deadline; n++) {
+                Tablet tablet = nextTablet(deadline);
+                if (tablet == null) {
+                    break;
+                }
+                CloudReplica replica = (CloudReplica) 
tablet.getReplicas().get(0);
+                // One existing replica owner per compute group. BE read/write 
separation
+                // decides which group may compact; Meta Service arbitrates 
competing jobs.
+                for (String clusterId : info.getCloudClusterIds()) {
+                    long backendId;
+                    try {
+                        backendId = 
replica.getBackendIdWithClusterId(clusterId);
+                    } catch (ComputeGroupException e) {
+                        LOG.debug("ROW binlog TTL discovery skipped, compute 
group={}, tablet={}",
+                                clusterId, tablet.getId(), e);
+                        continue;
+                    }
+                    Backend backend = info.getBackend(backendId);
+                    if (backend != null && backend.isAlive()) {
+                        targets.computeIfAbsent(backendId, ignored -> new 
ArrayList<>()).add(tablet.getId());
+                    }
+                }
+            }
+            for (Map.Entry<Long, List<Long>> target : targets.entrySet()) {
+                Backend backend = info.getBackend(target.getKey());
+                if (backend == null || !backend.isAlive()) {
+                    continue;
+                }
+                InternalService.PSyncTabletMetaRequest request = 
InternalService.PSyncTabletMetaRequest.newBuilder()
+                        
.addAllTabletIds(target.getValue()).setDiscoverRowBinlogTtl(true).build();
+                
Futures.addCallback(BackendServiceProxy.getInstance().syncTabletMeta(backend.getBrpcAddress(),
 request),

Review Comment:
   Catch RpcException around each BE’s RPC call. If synchronous dispatch to one 
BE fails, log the error and continue sending requests to the remaining BEs.



##########
be/src/storage/row_binlog_ttl_scanner.cpp:
##########
@@ -0,0 +1,178 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <bvar/bvar.h>
+
+#include "cloud/cloud_cluster_info.h"
+#include "cloud/cloud_storage_engine.h"
+#include "cloud/cloud_tablet.h"
+#include "cloud/config.h"
+#include "common/config.h"
+#include "runtime/cluster_info.h"
+#include "runtime/exec_env.h"
+#include "runtime/thread_context.h"
+#include "storage/storage_engine.h"
+#include "storage/tablet/tablet.h"
+#include "util/defer_op.h"
+#include "util/thread.h"
+#include "util/threadpool.h"
+#include "util/time.h"
+
+namespace doris {
+namespace {
+bvar::Adder<int64_t> ttl_discovered("row_binlog_ttl_discovered");
+bvar::Adder<int64_t> ttl_submitted("row_binlog_ttl_submitted");
+bvar::Adder<int64_t> ttl_failed("row_binlog_ttl_failed");
+constexpr int kScanBatchSize = 64;
+
+Status prepare_row_binlog_ttl(BaseStorageEngine& engine, int64_t tablet_id, 
bool refresh_cloud_meta,
+                              bool is_cloud) {
+    // Cloud catalog discovery and already queued work must also honor runtime 
switches.
+    if (!config::enable_feature_binlog || config::disable_auto_compaction) {
+        return Status::OK();
+    }
+    auto tablet = DORIS_TRY(engine.get_tablet(tablet_id));
+    if (is_cloud && refresh_cloud_meta) {
+        auto cloud_tablet = std::static_pointer_cast<CloudTablet>(tablet);
+        RETURN_IF_ERROR(cloud_tablet->sync_meta());
+        RETURN_IF_ERROR(cloud_tablet->sync_rowsets());
+    }
+    if (tablet->tablet_state() != TABLET_RUNNING || 
!tablet->scan_expired_row_binlog_rowsets()) {
+        return Status::OK();
+    }
+    ttl_discovered << 1;
+    const auto last_failure =
+            is_cloud
+                    ? std::static_pointer_cast<CloudTablet>(tablet)
+                              ->last_cumu_compaction_failure_time()
+                    : 
std::static_pointer_cast<Tablet>(tablet)->last_cumu_compaction_failure_time();
+    if (UnixMillis() - last_failure < 
config::min_compaction_failure_interval_ms) {
+        return Status::OK();
+    }
+    if (is_cloud) {
+        auto cloud_tablet = std::static_pointer_cast<CloudTablet>(tablet);
+        auto* cluster = 
static_cast<CloudClusterInfo*>(ExecEnv::GetInstance()->cluster_info());
+        if (cluster->should_skip_compaction(cloud_tablet.get()) || 
cluster->is_in_standby()) {
+            return Status::OK();
+        }
+        RETURN_IF_ERROR(engine.to_cloud().submit_compaction_task(
+                cloud_tablet, CompactionType::CUMU_BINLOG_COMPACTION));
+    } else {
+        RETURN_IF_ERROR(engine.to_local().submit_compaction_task(
+                std::static_pointer_cast<Tablet>(tablet), 
CompactionType::CUMU_BINLOG_COMPACTION,
+                false));
+    }
+    ttl_submitted << 1;
+    return Status::OK();
+}
+} // namespace
+
+void BaseStorageEngine::register_row_binlog_tablet(const BaseTabletSPtr& 
tablet) {
+    if (tablet->is_row_binlog_tablet()) {
+        std::lock_guard lock(_row_binlog_ttl_mutex);
+        _row_binlog_ttl_tablets[tablet->tablet_id()] = tablet;
+    }
+}
+
+Status BaseStorageEngine::submit_row_binlog_ttl(int64_t tablet_id, bool 
refresh_cloud_meta) {
+    if (ExecEnv::GetInstance()->cluster_info()->row_binlog_ttl_reference_tso() 
<= 0) {
+        return Status::Error<ErrorCode::SERVICE_UNAVAILABLE>("No valid ROW 
binlog TTL reference");
+    }
+    std::lock_guard lock(_row_binlog_ttl_mutex);
+    if (!_row_binlog_ttl_prepare_pool || 
_stop_background_threads_latch.count() == 0) {
+        return Status::Error<ErrorCode::SERVICE_UNAVAILABLE>(
+                "ROW binlog TTL scanner is not running");
+    }
+    if (!_row_binlog_ttl_pending.insert(tablet_id).second) {
+        return Status::AlreadyExist("ROW binlog TTL task already queued for 
{}", tablet_id);
+    }
+    auto st = _row_binlog_ttl_prepare_pool->submit_func([this, tablet_id, 
refresh_cloud_meta]() {
+        SCOPED_INIT_THREAD_CONTEXT();
+        Defer clear_pending([this, tablet_id] {
+            std::lock_guard lock(_row_binlog_ttl_mutex);
+            _row_binlog_ttl_pending.erase(tablet_id);
+        });
+        auto result =
+                prepare_row_binlog_ttl(*this, tablet_id, refresh_cloud_meta, 
_type == Type::CLOUD);
+        if (!result.ok()) {
+            ttl_failed << 1;
+            LOG_EVERY_N(WARNING, 100)
+                    << "ROW binlog TTL task failed, tablet=" << tablet_id << 
", status=" << result;
+        }
+    });
+    if (!st.ok()) {
+        _row_binlog_ttl_pending.erase(tablet_id);
+    }
+    return st;
+}
+
+Status BaseStorageEngine::_start_row_binlog_ttl_scanner() {
+    RETURN_IF_ERROR(ThreadPoolBuilder("RowBinlogTtlPrepare")
+                            .set_min_threads(1)
+                            .set_max_threads(1)
+                            .set_max_queue_size(kScanBatchSize)
+                            .build(&_row_binlog_ttl_prepare_pool));
+    return Thread::create(
+            "StorageEngine", "row_binlog_ttl_scanner",
+            [this] {
+                SCOPED_INIT_THREAD_CONTEXT();
+                int64_t cursor = 0;

Review Comment:
   done



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to