From: Sage Weil Date: Wed, 13 May 2020 19:34:26 +0000 (-0500) Subject: common/FixedCDC: add 'fixed' chunker X-Git-Tag: wip-pdonnell-testing-20200918.022351~1167^2~21 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6c56629c2643a29c92ffeac9228422826d7b3088;p=ceph-ci.git common/FixedCDC: add 'fixed' chunker Signed-off-by: Sage Weil --- diff --git a/src/common/CDC.cc b/src/common/CDC.cc index d497308919b..bf455db8a44 100644 --- a/src/common/CDC.cc +++ b/src/common/CDC.cc @@ -5,6 +5,7 @@ #include "CDC.h" #include "FastCDC.h" +#include "FixedCDC.h" #include "rabin.h" std::unique_ptr CDC::create( @@ -20,5 +21,8 @@ std::unique_ptr CDC::create( if (type == "fastcdc") { return std::unique_ptr(new FastCDC(bits, windowbits)); } + if (type == "fixed") { + return std::unique_ptr(new FixedCDC(bits, windowbits)); + } return nullptr; } diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 90f7524b449..f3c248f290b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 index 00000000000..ff1355861b4 --- /dev/null +++ b/src/common/FixedCDC.cc @@ -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> *chunks) +{ + size_t len = bl.length(); + if (!len) { + return; + } + for (size_t pos = 0; pos < len; pos += chunk_size) { + chunks->push_back(std::pair(pos, std::min(chunk_size, + len - pos))); + } +} diff --git a/src/common/FixedCDC.h b/src/common/FixedCDC.h new file mode 100644 index 00000000000..e5559d77825 --- /dev/null +++ b/src/common/FixedCDC.h @@ -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> *chunks) override; +}; diff --git a/src/test/common/test_cdc.cc b/src/test/common/test_cdc.cc index 91ee96fa0b9..65385836b96 100644 --- a/src/test/common/test_cdc.cc +++ b/src/test/common/test_cdc.cc @@ -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} ));