github-actions[bot] commented on code in PR #62476:
URL: https://github.com/apache/doris/pull/62476#discussion_r3122774665
##########
cloud/src/recycler/recycler.cpp:
##########
@@ -1855,90 +1856,244 @@ int
InstanceRecycler::abort_job_for_related_rowset(const RowsetMetaCloudPB& rows
}
template <typename T>
-int InstanceRecycler::abort_txn_or_job_for_recycle(T& rowset_meta_pb) {
- RowsetMetaCloudPB* rs_meta;
- RecycleRowsetPB::Type rowset_type = RecycleRowsetPB::PREPARE;
+RowsetMetaCloudPB* mutable_rowset_meta(T& rowset_meta_pb) {
+ if constexpr (std::is_same_v<T, RecycleRowsetPB>) {
+ return rowset_meta_pb.mutable_rowset_meta();
+ } else {
+ return &rowset_meta_pb;
+ }
+}
+template <typename T>
+const RowsetMetaCloudPB& rowset_meta(const T& rowset_meta_pb) {
if constexpr (std::is_same_v<T, RecycleRowsetPB>) {
- // For keys that are not in the RecycleRowsetPB::PREPARE state
- // we do not need to check the job or txn state
- // because tmp_rowset_key already exists when this key is generated.
- rowset_type = rowset_meta_pb.type();
- rs_meta = rowset_meta_pb.mutable_rowset_meta();
+ return rowset_meta_pb.rowset_meta();
} else {
- rs_meta = &rowset_meta_pb;
+ return rowset_meta_pb;
}
+}
- DCHECK(rs_meta != nullptr);
+struct DeferredRecycleAbortTask {
+ enum class Type : uint8_t {
+ TXN,
+ JOB,
+ };
- // compaction/sc will generate recycle_rowset_key for each input rowset
with load_id
- // we need skip them because the related txn has been finished
- // load_rowset1 load_rowset2 => pick for compaction => compact_rowset
- // compact_rowset1 compact_rowset2 => pick for compaction/sc job =>
new_rowset
- if (rowset_type == RecycleRowsetPB::PREPARE) {
- if (rs_meta->has_load_id()) {
- // load
- return abort_txn_for_related_rowset(rs_meta->txn_id());
- } else if (rs_meta->has_job_id()) {
- // compaction / schema change
- return abort_job_for_related_rowset(*rs_meta);
- }
- }
+ Type type = Type::TXN;
+ int64_t txn_id = 0;
+ int64_t tablet_id = 0;
+ int64_t start_version = 0;
+ int64_t end_version = 0;
+ std::string rowset_id;
+ std::string job_id;
+};
- return 0;
-}
+struct DeferredRecyclePrepareDeleteTask {
+ std::string key;
+ std::string resource_id;
+ std::string rowset_id;
+ int64_t tablet_id = 0;
+};
template <typename T>
-int mark_rowset_as_recycled(TxnKv* txn_kv, const std::string& instance_id,
std::string_view key,
- T& rowset_meta_pb) {
- RowsetMetaCloudPB* rs_meta;
-
+std::optional<DeferredRecycleAbortTask> make_deferred_abort_task(const T&
rowset_meta_pb) {
if constexpr (std::is_same_v<T, RecycleRowsetPB>) {
- rs_meta = rowset_meta_pb.mutable_rowset_meta();
- } else {
- rs_meta = &rowset_meta_pb;
+ if (rowset_meta_pb.type() != RecycleRowsetPB::PREPARE) {
+ return std::nullopt;
+ }
}
- bool need_write_back = false;
- if ((!rs_meta->has_is_recycled() || !rs_meta->is_recycled())) {
- need_write_back = true;
- rs_meta->set_is_recycled(true);
+ const auto& rs_meta = rowset_meta(rowset_meta_pb);
+ DeferredRecycleAbortTask task;
+ task.tablet_id = rs_meta.tablet_id();
+ task.start_version = rs_meta.start_version();
+ task.end_version = rs_meta.end_version();
+ if (rs_meta.has_load_id()) {
+ task.type = DeferredRecycleAbortTask::Type::TXN;
+ task.txn_id = rs_meta.txn_id();
+ return task;
}
+ if (rs_meta.has_job_id()) {
+ task.type = DeferredRecycleAbortTask::Type::JOB;
+ task.rowset_id = rs_meta.rowset_id_v2();
+ task.job_id = rs_meta.job_id();
+ return task;
+ }
+ return std::nullopt;
+}
+
+template <typename T>
+bool need_mark_rowset_as_recycled(const T& rowset_meta_pb) {
+ const auto& rs_meta = rowset_meta(rowset_meta_pb);
+ return !rs_meta.has_is_recycled() || !rs_meta.is_recycled();
+}
- if (need_write_back) {
+template <typename T>
+int batch_mark_rowsets_as_recycled(TxnKv* txn_kv, const std::string&
instance_id,
+ const std::vector<std::string>& keys) {
+ constexpr size_t kMarkBatchSize = 256;
Review Comment:
This fixed count-based batch does not respect TxnKv's byte limit. Each
update rewrites the full serialized `RecycleRowsetPB` / `RowsetMetaCloudPB`,
and `TxnKv` can return `TXN_BYTES_TOO_LARGE` on commit
(`cloud/src/meta-store/txn_kv.cpp:351-352`). The old implementation used one
transaction per rowset, so a page of large rowset metas can now fail only
because of batching. Please split by accumulated bytes or shrink/retry on
`TXN_BYTES_TOO_LARGE` instead of assuming 256 entries is always safe.
##########
cloud/src/recycler/recycler.cpp:
##########
@@ -4931,13 +5073,63 @@ int InstanceRecycler::recycle_rowsets() {
auto loop_done = [&]() -> int {
std::vector<std::string> rowset_keys_to_delete;
+ std::vector<std::string> mark_keys_to_process;
+ std::vector<std::string> abort_keys_to_process;
+ std::vector<std::string> prepare_keys_to_process;
// rowset_id -> rowset_meta
// store rowset id and meta for statistics rs size when delete
std::map<std::string, doris::RowsetMetaCloudPB> rowsets_to_delete;
rowset_keys_to_delete.swap(rowset_keys);
+ mark_keys_to_process.swap(rowset_keys_to_mark_recycled);
+ abort_keys_to_process.swap(rowset_keys_to_abort);
+ prepare_keys_to_process.swap(prepare_rowset_keys_to_delete);
rowsets_to_delete.swap(rowsets);
worker_pool->submit([&, rowset_keys_to_delete =
std::move(rowset_keys_to_delete),
- rowsets_to_delete =
std::move(rowsets_to_delete)]() {
+ rowsets_to_delete = std::move(rowsets_to_delete),
+ prepare_keys_to_process =
std::move(prepare_keys_to_process),
+ mark_keys_to_process =
std::move(mark_keys_to_process),
+ abort_keys_to_process =
std::move(abort_keys_to_process)]() mutable {
+ if (!mark_keys_to_process.empty() &&
Review Comment:
Moving mark/abort into this worker lambda changes their failure mode from
"fail the recycle pass" to "log and continue". If
`batch_mark_rowsets_as_recycled()` / `batch_abort_txn_or_job_for_recycle()`
hits `create_txn`, `TXN_CONFLICT`, or `TXN_BYTES_TOO_LARGE`, the lambda just
returns here, but `loop_done()` has already returned 0 and `recycle_rowsets()`
still reports success after `worker_pool->stop()`. Before this patch, those
mark/abort failures were synchronous and aborted the pass immediately. That
means the instance recycle job can now be recorded as successful even though
this whole batch was never marked/aborted. The same issue exists in
`recycle_tmp_rowsets()` below.
##########
cloud/src/recycler/recycler.cpp:
##########
@@ -4856,38 +5014,26 @@ int InstanceRecycler::recycle_rowsets() {
auto* rowset_meta = rowset.mutable_rowset_meta();
if (config::enable_mark_delete_rowset_before_recycle) {
- int mark_ret = mark_rowset_as_recycled(txn_kv_.get(),
instance_id_, k, rowset);
- if (mark_ret == -1) {
- LOG(WARNING) << "failed to mark rowset as recycled,
instance_id=" << instance_id_
- << " tablet_id=" << rowset_meta->tablet_id() << "
version=["
- << rowset_meta->start_version() << '-' <<
rowset_meta->end_version()
- << "]";
- return -1;
- } else if (mark_ret == 1) {
- LOG(INFO)
- << "rowset already marked as recycled, recycler will
delete data and kv at "
- "next turn, instance_id="
- << instance_id_ << " tablet_id=" <<
rowset_meta->tablet_id() << " version=["
- << rowset_meta->start_version() << '-' <<
rowset_meta->end_version() << "]";
+ if (need_mark_rowset_as_recycled(rowset)) {
Review Comment:
This changes the two-phase recycle contract from "mark immediately when the
rowset is selected" to "mark later, after the whole range-get page finishes and
the worker runs". `scan_and_recycle()` only calls `loop_done()` after one
`RangeGetIterator` page, and the default page size is 10,000 keys
(`cloud/src/meta-store/txn_kv.h:59`,
`cloud/src/recycler/recycler.cpp:5952-6006`). Until then `commit_rowset()` /
`finish_job()` / `commit_txn()` still observe `is_recycled = false`
(`cloud/src/meta-service/meta_service.cpp:2635-2649`,
`cloud/src/meta-service/meta_service_job.cpp:1223-1228,1816-1822`,
`cloud/src/meta-service/meta_service_txn.cpp:1169-1173`) and can move this
expired rowset forward successfully. If that happens, the later worker re-read
just gets `TXN_KEY_NOT_FOUND` and skips both marking and aborting, which
re-opens the race fixed by #58459. The tmp-rowset path below has the same
problem.
--
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]