You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/03/24 11:13:40 UTC

[GitHub] [incubator-doris] acelyc111 commented on a change in pull request #5452: [Audit][Stream Load] Support audit function for stream load

acelyc111 commented on a change in pull request #5452:
URL: https://github.com/apache/incubator-doris/pull/5452#discussion_r600381383



##########
File path: be/src/common/config.h
##########
@@ -348,6 +348,12 @@ CONF_mInt32(streaming_load_rpc_max_alive_time_sec, "1200");
 CONF_Int32(tablet_writer_open_rpc_timeout_sec, "60");
 // You can ignore brpc error '[E1011]The server is overcrowded' when writing data.
 CONF_mBool(tablet_writer_ignore_eovercrowded, "false");
+// batch size of stream load record reported to FE
+CONF_mInt32(stream_load_record_batch_size, "50");
+// expire time of stream load record in rocksdb.
+CONF_mInt32(stream_load_record_expire_time_secs, "28800");

Review comment:
       stream_load_record_expire_time_secs is not configurable at runtime.

##########
File path: be/src/runtime/stream_load/stream_load_record.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 "runtime/stream_load/stream_load_record.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";
+
+StreamLoadRecord::StreamLoadRecord(const std::string& root_path)
+        : _root_path(root_path),
+          _db(nullptr),
+          _last_compaction_time(UnixMillis()) {
+}
+
+StreamLoadRecord::~StreamLoadRecord() {
+    if (_db != nullptr) {
+        for (auto handle : _handles) {
+            _db->DestroyColumnFamilyHandle(handle);
+            handle = nullptr;
+        }
+        delete _db;
+        _db= nullptr;
+    }
+}
+
+Status StreamLoadRecord::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");
+    }
+    return Status::OK();
+}
+
+Status StreamLoadRecord::put(const std::string& key, const std::string& value) {
+    rocksdb::ColumnFamilyHandle* handle = _handles[1];
+    rocksdb::WriteOptions write_options;
+    write_options.sync = false;
+    rocksdb::Status s = _db->Put(write_options, handle, rocksdb::Slice(key), rocksdb::Slice(value));
+    if (!s.ok()) {
+        LOG(WARNING) << "rocks db put key:" << key << " failed, reason:" << s.ToString();
+        return Status::InternalError("Stream load record rocksdb put failed");
+    }
+
+    if ((UnixMillis() - _last_compaction_time) / 1000 > config::clean_stream_load_record_interval_secs) {
+        rocksdb::CompactRangeOptions options;
+        s = _db->CompactRange(options, _handles[1], nullptr, nullptr);

Review comment:
       CompactRange may consume a long time, better to not invoke it on load path.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org