weizuo93 commented on a change in pull request #5452: URL: https://github.com/apache/incubator-doris/pull/5452#discussion_r608311135
########## File path: be/src/runtime/stream_load/stream_load_recorder.cpp ########## @@ -0,0 +1,124 @@ +// 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 "runtime/stream_load/stream_load_recorder.h" + +#include "common/config.h" +#include "common/status.h" +#include "rocksdb/db.h" + +#include "rocksdb/options.h" +#include "rocksdb/slice.h" +#include "rocksdb/slice_transform.h" +#include "rocksdb/utilities/db_ttl.h" +#include "util/time.h" + + +namespace doris { +const std::string STREAM_LOAD_POSTFIX = "/stream_load"; + +StreamLoadRecorder::StreamLoadRecorder(const std::string& root_path) + : _root_path(root_path), + _db(nullptr), + _last_compaction_time(UnixMillis()) { +} + +StreamLoadRecorder::~StreamLoadRecorder() { + if (_db != nullptr) { + for (auto handle : _handles) { + _db->DestroyColumnFamilyHandle(handle); + handle = nullptr; + } + delete _db; + _db= nullptr; + } +} + +Status StreamLoadRecorder::init() { + // init db + rocksdb::DBOptions options; + options.IncreaseParallelism(); + options.create_if_missing = true; + options.create_missing_column_families = true; + std::string db_path = _root_path + STREAM_LOAD_POSTFIX; + std::vector<rocksdb::ColumnFamilyDescriptor> column_families; + // default column family is required + column_families.emplace_back(DEFAULT_COLUMN_FAMILY, rocksdb::ColumnFamilyOptions()); + // stream load column family + column_families.emplace_back(STREAM_LOAD_COLUMN_FAMILY, rocksdb::ColumnFamilyOptions()); + std::vector<int32_t> ttls = {config::stream_load_record_expire_time_secs, config::stream_load_record_expire_time_secs}; + rocksdb::Status s = rocksdb::DBWithTTL::Open(options, db_path, column_families, &_handles, &_db, ttls); + + if (!s.ok() || _db == nullptr) { + LOG(WARNING) << "rocks db open failed, reason:" << s.ToString(); + return Status::InternalError("Stream load record rocksdb open failed"); Review comment: > You can append s.ToString() to the returned value, then the caller could know the error details, or he should grep the log to find the root cause. OK. -- 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. 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