xy720 commented on code in PR #47300:
URL: https://github.com/apache/doris/pull/47300#discussion_r2226883202


##########
be/src/cloud/cloud_snapshot_mgr.cpp:
##########
@@ -0,0 +1,291 @@
+// 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/cloud_snapshot_mgr.h"
+
+#include <fmt/format.h>
+#include <gen_cpp/olap_file.pb.h>
+
+#include <map>
+#include <unordered_map>
+
+#include "cloud/cloud_meta_mgr.h"
+#include "cloud/cloud_storage_engine.h"
+#include "cloud/cloud_tablet_mgr.h"
+#include "common/config.h"
+#include "common/logging.h"
+#include "common/status.h"
+#include "io/fs/local_file_system.h"
+#include "olap/data_dir.h"
+#include "olap/olap_common.h"
+#include "olap/olap_define.h"
+#include "olap/pb_helper.h"
+#include "olap/rowset/rowset.h"
+#include "olap/rowset/rowset_factory.h"
+#include "olap/rowset/rowset_meta.h"
+#include "olap/rowset/rowset_writer.h"
+#include "olap/rowset/rowset_writer_context.h"
+#include "olap/storage_policy.h"
+#include "olap/tablet_meta.h"
+#include "olap/tablet_schema.h"
+#include "olap/tablet_schema_cache.h"
+#include "olap/utils.h"
+#include "runtime/memory/mem_tracker_limiter.h"
+#include "runtime/thread_context.h"
+#include "util/slice.h"
+#include "util/uid_util.h"
+
+namespace doris {
+using namespace ErrorCode;
+
+CloudSnapshotMgr::CloudSnapshotMgr(CloudStorageEngine& engine) : 
_engine(engine) {
+    _mem_tracker =
+            MemTrackerLimiter::create_shared(MemTrackerLimiter::Type::OTHER, 
"CloudSnapshotMgr");
+}
+
+Status CloudSnapshotMgr::make_snapshot(int64_t target_tablet_id, 
StorageResource& storage_resource,
+                                       std::unordered_map<std::string, 
std::string>& file_mapping,
+                                       bool is_restore, const Slice* slice) {
+    SCOPED_ATTACH_TASK(_mem_tracker);
+    if (is_restore && slice == nullptr) {
+        return Status::Error<INVALID_ARGUMENT>("slice cannot be null in 
restore.");
+    }
+
+    CloudTabletSPtr target_tablet = 
DORIS_TRY(_engine.tablet_mgr().get_tablet(target_tablet_id));
+    if (target_tablet == nullptr) {
+        return Status::Error<TABLE_NOT_FOUND>("failed to get tablet. 
tablet={}", target_tablet_id);
+    }
+
+    TabletMeta tablet_meta;
+    if (is_restore) {
+        // 1. deserialize tablet meta from memory
+        RETURN_IF_ERROR(tablet_meta.create_from_buffer((const 
uint8_t*)slice->data, slice->size));
+        TabletMetaPB tablet_meta_pb;
+        tablet_meta.to_meta_pb(&tablet_meta_pb);
+
+        tablet_meta_pb.clear_rs_metas(); // copy the rs meta
+        if (tablet_meta.all_rs_metas().size() > 0) {
+            
tablet_meta_pb.mutable_inc_rs_metas()->Reserve(tablet_meta.all_rs_metas().size());
+            for (auto& rs : tablet_meta.all_rs_metas()) {
+                rs->to_rowset_pb(tablet_meta_pb.add_rs_metas());
+            }
+        }
+        tablet_meta_pb.clear_stale_rs_metas(); // copy the stale rs meta
+        if (tablet_meta.all_stale_rs_metas().size() > 0) {

Review Comment:
   不需要,已去除



##########
be/src/olap/tablet_meta.cpp:
##########
@@ -475,6 +475,22 @@ Status TabletMeta::load_from_file(const string& file_path, 
TabletMetaPB* tablet_
     return Status::OK();
 }
 
+Status TabletMeta::create_from_buffer(const uint8_t* buffer, size_t 
buffer_size) {
+    FileHeader<TabletMetaPB> file_header(""); // empty file path
+    RETURN_IF_ERROR(file_header.deserialize_from_memory(buffer, buffer_size));
+
+    TabletMetaPB tablet_meta_pb;
+    try {
+        tablet_meta_pb.CopyFrom(file_header.message());
+    } catch (...) {
+        return Status::Error<ErrorCode::PARSE_PROTOBUF_ERROR>(

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