]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add BucketLayout to RGWBucketInfo
authorCasey Bodley <cbodley@redhat.com>
Tue, 3 Mar 2020 20:42:54 +0000 (15:42 -0500)
committerShilpa Jagannath <smanjara@redhat.com>
Mon, 30 Mar 2020 11:01:24 +0000 (16:31 +0530)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/CMakeLists.txt
src/rgw/rgw_bucket_layout.cc [new file with mode: 0644]
src/rgw/rgw_bucket_layout.h [new file with mode: 0644]
src/rgw/rgw_common.cc
src/rgw/rgw_common.h

index bfacafc41e8652e377b31b816a15687b448c45c7..7cbd18da3bbadaa2bf97fd2494fe1829594ab395 100644 (file)
@@ -58,6 +58,7 @@ set(librgw_common_srcs
   rgw_arn.cc
   rgw_basic_types.cc
   rgw_bucket.cc
+  rgw_bucket_layout.cc
   rgw_bucket_sync.cc
   rgw_cache.cc
   rgw_common.cc
diff --git a/src/rgw/rgw_bucket_layout.cc b/src/rgw/rgw_bucket_layout.cc
new file mode 100644 (file)
index 0000000..942d113
--- /dev/null
@@ -0,0 +1,94 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab ft=cpp
+
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "rgw_bucket_layout.h"
+
+namespace rgw {
+
+void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f)
+{
+  ENCODE_START(1, 1, bl);
+  encode(l.num_shards, bl);
+  encode(l.hash_type, bl);
+  ENCODE_FINISH(bl);
+}
+void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl)
+{
+  DECODE_START(1, bl);
+  decode(l.num_shards, bl);
+  decode(l.hash_type, bl);
+  DECODE_FINISH(bl);
+}
+
+void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f)
+{
+  ENCODE_START(1, 1, bl);
+  encode(l.type, bl);
+  switch (l.type) {
+  case BucketIndexType::Normal:
+    encode(l.normal, bl);
+    break;
+  case BucketIndexType::Indexless:
+    break;
+  }
+  ENCODE_FINISH(bl);
+}
+void decode(bucket_index_layout& l, bufferlist::const_iterator& bl)
+{
+  DECODE_START(1, bl);
+  decode(l.type, bl);
+  switch (l.type) {
+  case BucketIndexType::Normal:
+    decode(l.normal, bl);
+    break;
+  case BucketIndexType::Indexless:
+    break;
+  }
+  DECODE_FINISH(bl);
+}
+
+void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f)
+{
+  ENCODE_START(1, 1, bl);
+  encode(l.gen, bl);
+  encode(l.layout, bl);
+  ENCODE_FINISH(bl);
+}
+void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl)
+{
+  DECODE_START(1, bl);
+  decode(l.gen, bl);
+  decode(l.layout, bl);
+  DECODE_FINISH(bl);
+}
+
+void encode(const BucketLayout& l, bufferlist& bl, uint64_t f)
+{
+  ENCODE_START(1, 1, bl);
+  encode(l.resharding, bl);
+  encode(l.current_index, bl);
+  encode(l.target_index, bl);
+  ENCODE_FINISH(bl);
+}
+void decode(BucketLayout& l, bufferlist::const_iterator& bl)
+{
+  DECODE_START(1, bl);
+  decode(l.resharding, bl);
+  decode(l.current_index, bl);
+  decode(l.target_index, bl);
+  DECODE_FINISH(bl);
+}
+
+} // namespace rgw
diff --git a/src/rgw/rgw_bucket_layout.h b/src/rgw/rgw_bucket_layout.h
new file mode 100644 (file)
index 0000000..5f9d156
--- /dev/null
@@ -0,0 +1,82 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab ft=cpp
+
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2020 Red Hat, Inc.
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#pragma once
+
+#include <optional>
+#include <string>
+#include "include/encoding.h"
+
+namespace rgw {
+
+enum class BucketIndexType : uint8_t {
+  Normal, // normal hash-based sharded index layout
+  Indexless, // no bucket index, so listing is unsupported
+};
+
+enum class BucketHashType : uint8_t {
+  Mod, // rjenkins hash of object name, modulo num_shards
+};
+
+struct bucket_index_normal_layout {
+  uint32_t num_shards = 1;
+
+  BucketHashType hash_type = BucketHashType::Mod;
+};
+
+void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f=0);
+void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl);
+
+
+struct bucket_index_layout {
+  BucketIndexType type = BucketIndexType::Normal;
+
+  // TODO: variant of layout types?
+  bucket_index_normal_layout normal;
+};
+
+void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f=0);
+void decode(bucket_index_layout& l, bufferlist::const_iterator& bl);
+
+
+struct bucket_index_layout_generation {
+  uint64_t gen = 0;
+  bucket_index_layout layout;
+};
+
+void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f=0);
+void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl);
+
+
+enum class BucketReshardState : uint8_t {
+  None,
+  InProgress,
+};
+
+// describes the layout of bucket index objects
+struct BucketLayout {
+  BucketReshardState resharding = BucketReshardState::None;
+
+  // current bucket index layout
+  bucket_index_layout_generation current_index;
+
+  // target index layout of a resharding operation
+  std::optional<bucket_index_layout_generation> target_index;
+};
+
+void encode(const BucketLayout& l, bufferlist& bl, uint64_t f=0);
+void decode(BucketLayout& l, bufferlist::const_iterator& bl);
+
+} // namespace rgw
index f440bb2261227bf699431c1060082adc487e4284..f3c08f8873c3fcba7d86984455e4852d153e5cc2 100644 (file)
@@ -1990,7 +1990,7 @@ RGWBucketInfo::~RGWBucketInfo()
 }
 
 void RGWBucketInfo::encode(bufferlist& bl) const {
-  ENCODE_START(21, 4, bl);
+  ENCODE_START(22, 4, bl);
   encode(bucket, bl);
   encode(owner.id, bl);
   encode(flags, bl);
@@ -2025,11 +2025,12 @@ void RGWBucketInfo::encode(bufferlist& bl) const {
   if (has_sync_policy) {
     encode(*sync_policy, bl);
   }
+  encode(layout, bl);
   ENCODE_FINISH(bl);
 }
 
 void RGWBucketInfo::decode(bufferlist::const_iterator& bl) {
-  DECODE_START_LEGACY_COMPAT_LEN_32(21, 4, 4, bl);
+  DECODE_START_LEGACY_COMPAT_LEN_32(22, 4, 4, bl);
   decode(bucket, bl);
   if (struct_v >= 2) {
     string s;
@@ -2099,6 +2100,9 @@ void RGWBucketInfo::decode(bufferlist::const_iterator& bl) {
   if (struct_v >= 21) {
     decode(sync_policy, bl);
   }
+  if (struct_v >= 22) {
+    decode(layout, bl);
+  }
   
   DECODE_FINISH(bl);
 }
index 8d840731fe07eca6a77647cbfc700f6992b2813f..34fb71b833b9f35796c899fc4e6eab535a6834ff 100644 (file)
@@ -24,6 +24,7 @@
 #include "common/ceph_crypto.h"
 #include "common/random_string.h"
 #include "rgw_acl.h"
+#include "rgw_bucket_layout.h"
 #include "rgw_cors.h"
 #include "rgw_iam_policy.h"
 #include "rgw_quota.h"
@@ -1124,6 +1125,9 @@ struct RGWBucketInfo {
   RGWObjVersionTracker objv_tracker; /* we don't need to serialize this, for runtime tracking */
   RGWQuotaInfo quota;
 
+  // layout of bucket index objects
+  rgw::BucketLayout layout;
+
   // Represents the number of bucket index object shards:
   //   - value of 0 indicates there is no sharding (this is by default
   //     before this feature is implemented).