torwig commented on code in PR #1798:
URL: https://github.com/apache/kvrocks/pull/1798#discussion_r1354860606
##########
src/commands/cmd_server.cc:
##########
@@ -1072,6 +1074,46 @@ class CommandRestore : public Commander {
uint64_t ttl_ms_ = 0;
};
+// command format: rdb load <path> [NX] [DB index]
+class CommandRdb : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 3);
+ std::string_view ttl_flag, set_flag;
+ while (parser.Good()) {
+ if (parser.EatEqICase("NX")) {
+ is_nx_ = true;
+ } else if (parser.EatEqICase("DB")) {
+ db_index_ = GET_OR_RET(parser.TakeInt<uint32_t>());
+ } else {
+ return {Status::RedisParseErr, errInvalidSyntax};
+ }
+ }
+
+ return Status::OK();
+ }
+
+ Status Execute(Server *svr, Connection *conn, std::string *output) override {
+ rocksdb::Status db_status;
+ redis::Database redis(svr->storage, conn->GetNamespace());
+ auto type = args_[1];
+ auto path = args_[2];
+
+ auto stream_ptr = std::make_shared<RdbFileStream>(path);
+ GET_OR_RET(stream_ptr->Open());
+
+ RDB rdb(svr->storage, conn->GetNamespace(), stream_ptr);
+ GET_OR_RET(rdb.LoadRdb(db_index_, is_nx_));
+
+ *output = redis::SimpleString("OK");
+ return Status::OK();
+ }
+
+ private:
+ bool is_nx_ = false;
Review Comment:
I'm wondering if we can rename this parameter to `overwrite_existing` that
will be `true` by default if I understood the meaning of the `is_nx` parameter.
##########
src/common/rdb_stream.h:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ *
+ */
+
+#pragma once
+
+#include <stdint.h>
Review Comment:
I guess we can use `<cstdint>` here as a C++-header instead of C-like
`<stdint.h>`.
--
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]