hust-hhb commented on code in PR #40204: URL: https://github.com/apache/doris/pull/40204#discussion_r1766127293
########## be/src/cloud/cloud_delete_bitmap_action.cpp: ########## @@ -0,0 +1,123 @@ +// 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 "cloud_delete_bitmap_action.h" + +#include <rapidjson/document.h> +#include <rapidjson/encodings.h> +#include <rapidjson/prettywriter.h> +#include <rapidjson/rapidjson.h> +#include <rapidjson/stringbuffer.h> + +#include <chrono> // IWYU pragma: keep +#include <exception> +#include <future> +#include <memory> +#include <mutex> +#include <sstream> +#include <string> +#include <thread> +#include <utility> + +#include "cloud/cloud_tablet.h" +#include "cloud/cloud_tablet_mgr.h" +#include "common/logging.h" +#include "common/status.h" +#include "gutil/strings/substitute.h" +#include "http/http_channel.h" +#include "http/http_headers.h" +#include "http/http_request.h" +#include "http/http_status.h" +#include "olap/olap_define.h" +#include "olap/storage_engine.h" +#include "olap/tablet_manager.h" +#include "util/doris_metrics.h" +#include "util/stopwatch.hpp" + +namespace doris { +using namespace ErrorCode; + +namespace { + +constexpr std::string_view HEADER_JSON = "application/json"; + +} // namespace + +CloudDeleteBitmapAction::CloudDeleteBitmapAction(DeleteBitmapActionType ctype, ExecEnv* exec_env, + CloudStorageEngine& engine, + TPrivilegeHier::type hier, + TPrivilegeType::type ptype) + : HttpHandlerWithAuth(exec_env, hier, ptype), + _engine(engine), + _delete_bitmap_action_type(ctype) {} + +static Status _check_param(HttpRequest* req, uint64_t* tablet_id) { + const auto& req_tablet_id = req->param(TABLET_ID_KEY); + if (req_tablet_id.empty()) { + return Status::InternalError("tablet id is empty!"); + } + try { + *tablet_id = std::stoull(req_tablet_id); + } catch (const std::exception& e) { + return Status::InternalError("convert tablet_id failed, {}", e.what()); + } + return Status::OK(); +} + +Status CloudDeleteBitmapAction::_handle_show_delete_bitmap_count(HttpRequest* req, + std::string* json_result) { + uint64_t tablet_id = 0; + // check & retrieve tablet_id from req if it contains + RETURN_NOT_OK_STATUS_WITH_WARN(_check_param(req, &tablet_id), "check param failed"); + if (tablet_id == 0) { + return Status::InternalError("check param failed: missing tablet_id"); + } + + CloudTabletSPtr tablet = DORIS_TRY(_engine.tablet_mgr().get_tablet(tablet_id)); + if (tablet == nullptr) { + return Status::NotFound("Tablet not found. tablet_id={}", tablet_id); + } + + auto count = tablet->tablet_meta()->delete_bitmap().get_delete_bitmap_count(); + + rapidjson::Document root; + root.SetObject(); + root.AddMember("delete_bitmap_count", count, root.GetAllocator()); Review Comment: That right, already remove this check ########## cloud/src/meta-service/meta_service.cpp: ########## @@ -2080,6 +2080,154 @@ void MetaServiceImpl::get_delete_bitmap_update_lock(google::protobuf::RpcControl } } +void MetaServiceImpl::update_delete_bitmap_without_lock(google::protobuf::RpcController* controller, + const UpdateDeleteBitmapRequest* request, + UpdateDeleteBitmapResponse* response, + ::google::protobuf::Closure* done) { + RPC_PREPROCESS(update_delete_bitmap_without_lock); + std::string cloud_unique_id = request->has_cloud_unique_id() ? request->cloud_unique_id() : ""; + if (cloud_unique_id.empty()) { + code = MetaServiceCode::INVALID_ARGUMENT; + msg = "cloud unique id not set"; + return; + } + + instance_id = get_instance_id(resource_mgr_, cloud_unique_id); + if (instance_id.empty()) { + code = MetaServiceCode::INVALID_ARGUMENT; + msg = "empty instance_id"; + LOG(WARNING) << msg << ", cloud_unique_id=" << request->cloud_unique_id(); + return; + } + RPC_RATE_LIMIT(update_delete_bitmap_without_lock) + + uint32_t fdb_txn_size = 0; + auto table_id = request->table_id(); + auto tablet_id = request->tablet_id(); + + std::unique_ptr<Transaction> txn; + TxnErrorCode err = txn_kv_->create_txn(&txn); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as<ErrCategory::CREATE>(err); + msg = "failed to init txn"; + return; + } + + PendingDeleteBitmapPB delete_bitmap_keys; + for (size_t i = 0; i < request->rowset_ids_size(); ++i) { + MetaDeleteBitmapInfo key_info {instance_id, tablet_id, request->rowset_ids(i), + request->versions(i), request->segment_ids(i)}; + std::string key; + meta_delete_bitmap_key(key_info, &key); + delete_bitmap_keys.add_delete_bitmap_keys(key); + } + + // remove old delete bitmap + + // Update delete bitmap for curent txn + for (size_t i = 0; i < request->rowset_ids_size(); ++i) { + auto& key = delete_bitmap_keys.delete_bitmap_keys(i); + auto& val = request->segment_delete_bitmaps(i); + + // Split into multiple fdb transactions, because the size of one fdb + // transaction can't exceed 10MB. + if (fdb_txn_size + key.size() + val.size() > 9 * 1024 * 1024) { + LOG(INFO) << "fdb txn size more than 9MB, current size: " << fdb_txn_size + << " lock_id=" << request->lock_id(); + err = txn->commit(); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as<ErrCategory::COMMIT>(err); + ss << "failed to update delete bitmap, err=" << err; + msg = ss.str(); + return; + } + fdb_txn_size = 0; + TxnErrorCode err = txn_kv_->create_txn(&txn); + if (err != TxnErrorCode::TXN_OK) { + code = cast_as<ErrCategory::CREATE>(err); + msg = "failed to init txn"; + return; + } + if (!check_delete_bitmap_lock(code, msg, ss, txn, instance_id, table_id, Review Comment: That right, already remove this check -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org