]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/FixedCDC: add 'fixed' chunker
authorSage Weil <sage@newdream.net>
Wed, 13 May 2020 19:34:26 +0000 (14:34 -0500)
committerSage Weil <sage@newdream.net>
Wed, 27 May 2020 12:47:28 +0000 (07:47 -0500)
Signed-off-by: Sage Weil <sage@newdream.net>
src/common/CDC.cc
src/common/CMakeLists.txt
src/common/FixedCDC.cc [new file with mode: 0644]
src/common/FixedCDC.h [new file with mode: 0644]
src/test/common/test_cdc.cc

index d497308919b28b06af83f35d412686fc49f488a1..bf455db8a44ae18507302d284343ec5ad9088eba 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "CDC.h"
 #include "FastCDC.h"
+#include "FixedCDC.h"
 #include "rabin.h"
 
 std::unique_ptr<CDC> CDC::create(
@@ -20,5 +21,8 @@ std::unique_ptr<CDC> CDC::create(
   if (type == "fastcdc") {
     return std::unique_ptr<CDC>(new FastCDC(bits, windowbits));
   }
+  if (type == "fixed") {
+    return std::unique_ptr<CDC>(new FixedCDC(bits, windowbits));
+  }
   return nullptr;
 }
index 90f7524b449309b4e1cc39e121d028bc449fc0ab..f3c248f290bda908942984d320e6c5bbecc90f2c 100644 (file)
@@ -20,6 +20,7 @@ set(common_srcs
   DecayCounter.cc
   FastCDC.cc
   Finisher.cc
+  FixedCDC.cc
   Formatter.cc
   Graylog.cc
   HTMLFormatter.cc
diff --git a/src/common/FixedCDC.cc b/src/common/FixedCDC.cc
new file mode 100644 (file)
index 0000000..ff13558
--- /dev/null
@@ -0,0 +1,20 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma
+
+#include "FixedCDC.h"
+
+void FixedCDC::calc_chunks(
+  bufferlist& bl,
+  std::vector<std::pair<uint64_t, uint64_t>> *chunks)
+{
+  size_t len = bl.length();
+  if (!len) {
+    return;
+  }
+  for (size_t pos = 0; pos < len; pos += chunk_size) {
+    chunks->push_back(std::pair<uint64_t,uint64_t>(pos, std::min(chunk_size,
+                                                                len - pos)));
+  }
+}
diff --git a/src/common/FixedCDC.h b/src/common/FixedCDC.h
new file mode 100644 (file)
index 0000000..e5559d7
--- /dev/null
@@ -0,0 +1,23 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include "CDC.h"
+
+class FixedCDC : public CDC {
+private:
+  size_t chunk_size;
+
+public:
+  FixedCDC(int target = 18, int window_bits = 0) {
+    set_target_bits(target, window_bits);
+  };
+
+  void set_target_bits(int target, int window_bits) override {
+    chunk_size = 1ul << target;
+  }
+  void calc_chunks(
+    bufferlist& bl,
+    std::vector<std::pair<uint64_t, uint64_t>> *chunks) override;
+};
index 91ee96fa0b92cb5f47ba5ff5d8b4087e888d1147..65385836b962cbc38d1abb9c64bbbe94e6f537a5 100644 (file)
@@ -35,6 +35,7 @@ public:
 
 TEST_P(CDCTest, insert_front)
 {
+  if (GetParam() == "fixed"s) return;
   for (int frontlen = 1; frontlen < 163840; frontlen *= 3) {
     bufferlist bl1, bl2;
     generate_buffer(4*1024*1024, &bl1);
@@ -63,6 +64,7 @@ TEST_P(CDCTest, insert_front)
 
 TEST_P(CDCTest, insert_middle)
 {
+  if (GetParam() == "fixed"s) return;
   for (int frontlen = 1; frontlen < 163840; frontlen *= 3) {
     bufferlist bl1, bl2;
     generate_buffer(4*1024*1024, &bl1);
@@ -141,5 +143,7 @@ INSTANTIATE_TEST_SUITE_P(
   CDC,
   CDCTest,
   ::testing::Values(
+    "fixed",   // note: we skip most tests bc this is not content-based
     "fastcdc"
+    //, "rabin" // rabin fails insert_{front,middle}
     ));