PragmaTwice commented on code in PR #882:
URL: https://github.com/apache/incubator-kvrocks/pull/882#discussion_r973670527


##########
src/redis_disk.cc:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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 <vector>
+#include <memory>
+#include <utility>
+#include <algorithm>
+#include <string>
+
+#include "db_util.h"
+#include "redis_metadata.h"
+#include "redis_sortedint.h"
+#include "rocksdb/status.h"
+#include "redis_zset.h"
+#include "redis_bitmap.h"
+#include "redis_disk.h"
+#include "status.h"
+
+namespace Redis {
+rocksdb::Status Disk::GetApproximateSizes(const Metadata &metadata, const 
Slice &ns_key,
+                                          rocksdb::ColumnFamilyHandle 
*column_family,
+                                          uint64_t *key_size, Slice subkeyleft,
+                                          Slice subkeyright) {
+  std::string prefix_key, next_version_prefix_key;
+  InternalKey(ns_key, subkeyleft, metadata.version,
+              storage_->IsSlotIdEncoded()).Encode(&prefix_key);
+  InternalKey(ns_key, subkeyright, metadata.version + 1,
+              storage_->IsSlotIdEncoded()).Encode(&next_version_prefix_key);
+  auto key_range = rocksdb::Range(prefix_key, next_version_prefix_key);
+  uint64_t tmp_size = 0;
+  rocksdb::Status s = db_->GetApproximateSizes(option_, column_family,
+                                               &key_range, 1, &tmp_size);
+  if (!s.ok()) return s;
+  *key_size += tmp_size;
+  return rocksdb::Status::OK();
+}
+rocksdb::Status Disk::GetKeySize(const Slice &user_key, RedisType type, 
uint64_t *key_size) {
+  *key_size = 0;
+  std::string ns_key;
+  rocksdb::Status s;
+  AppendNamespacePrefix(user_key, &ns_key);
+    switch (type) {
+      case RedisType::kRedisString:
+        s = GetStringSize(ns_key, key_size);

Review Comment:
   You can return the status directly. BTW the switch block is not aligned well.



-- 
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]

Reply via email to