You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2022/12/06 06:59:31 UTC

[kudu] branch master updated: KUDU-3371 [util] add NextOf method for ObjectIdGenerator

This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 25deb55af KUDU-3371 [util] add NextOf method for ObjectIdGenerator
25deb55af is described below

commit 25deb55af784234b088f6ed773c42737b58c7345
Author: Yingchun Lai <la...@apache.org>
AuthorDate: Sun Nov 20 18:46:26 2022 +0800

    KUDU-3371 [util] add NextOf method for ObjectIdGenerator
    
    When using RocksDB to store log block container's metadata, there are
    some use cases to scan all keys prefixed by the log block
    container's ID. This patch adds a new method to generate the input
    parameter plus 1: that's to provide an exclusive upper bound when
    scanning.
    
    Change-Id: I293baa379e8d64adc4ff93acdb0713aae2731c7d
    Reviewed-on: http://gerrit.cloudera.org:8080/19258
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <al...@apache.org>
---
 src/kudu/util/oid_generator-test.cc | 11 +++++++++++
 src/kudu/util/oid_generator.cc      |  8 ++++++++
 src/kudu/util/oid_generator.h       |  7 +++++++
 3 files changed, 26 insertions(+)

diff --git a/src/kudu/util/oid_generator-test.cc b/src/kudu/util/oid_generator-test.cc
index 174b2b8f5..8c6d3e090 100644
--- a/src/kudu/util/oid_generator-test.cc
+++ b/src/kudu/util/oid_generator-test.cc
@@ -49,4 +49,15 @@ TEST(ObjectIdGeneratorTest, TestCanoicalizeUuid) {
   ASSERT_EQ(kExpectedCanonicalized, canonicalized);
 }
 
+TEST(ObjectIdGeneratorTest, TestNextOf) {
+  const string uuid_prefix_31_bits = "0123456789abcdef0123456789abcde";
+  const string single_postfix = "0123456789abcdef";
+  for (char ch : single_postfix) {
+    string uuid = uuid_prefix_31_bits + ch;
+    ASSERT_LT(uuid, ObjectIdGenerator::NextOf(uuid));
+    ASSERT_EQ(uuid_prefix_31_bits + static_cast<char>(ch + 1),
+              ObjectIdGenerator::NextOf(uuid));
+  }
+}
+
 } // namespace kudu
diff --git a/src/kudu/util/oid_generator.cc b/src/kudu/util/oid_generator.cc
index eee731622..902aa65ca 100644
--- a/src/kudu/util/oid_generator.cc
+++ b/src/kudu/util/oid_generator.cc
@@ -23,6 +23,7 @@
 #include <string>
 
 #include <boost/uuid/uuid.hpp>
+#include <glog/logging.h>
 
 #include "kudu/gutil/stringprintf.h"
 #include "kudu/gutil/strings/substitute.h"
@@ -62,4 +63,11 @@ Status ObjectIdGenerator::Canonicalize(const string& input,
   }
 }
 
+string ObjectIdGenerator::NextOf(const string& id) {
+  DCHECK(!id.empty());
+  string next(id);
+  next[next.size() - 1] += 1;
+  return next;
+}
+
 } // namespace kudu
diff --git a/src/kudu/util/oid_generator.h b/src/kudu/util/oid_generator.h
index c1cc88f3a..c9015cbf5 100644
--- a/src/kudu/util/oid_generator.h
+++ b/src/kudu/util/oid_generator.h
@@ -18,6 +18,7 @@
 #ifndef KUDU_UTIL_OID_GENERATOR_H
 #define KUDU_UTIL_OID_GENERATOR_H
 
+#include <cstddef>
 #include <string>
 
 #include <boost/uuid/random_generator.hpp>
@@ -43,6 +44,12 @@ class ObjectIdGenerator {
   // (that is, 16 hexadecimal bytes without any dashes).
   Status Canonicalize(const std::string& input, std::string* output) const;
 
+  constexpr static size_t IdLength() { return 32; }
+
+  // The 'id' plus 1, maybe not a valid UUID, just used to compare memory,
+  // values, will not be persisted to disk.
+  static std::string NextOf(const std::string& id);
+
  private:
   DISALLOW_COPY_AND_ASSIGN(ObjectIdGenerator);