Skip to content

Commit fbf6ba7

Browse files
macvincentfacebook-github-bot
authored andcommitted
Clean Up Nimble Flush Policy Code (#235)
Summary: As preparation for our [Nimble chunked encoding](https://fburl.com/gdoc/zjck7lo6) work, we decided to clean up the previous contract to remove unused methods and attributes. Should be a no-op since these methods and attributes were not used. We also clarified the naming of some attributes. Reviewed By: sdruzkin, helfman Differential Revision: D81514657
1 parent 49cb464 commit fbf6ba7

File tree

6 files changed

+26
-47
lines changed

6 files changed

+26
-47
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
repos:
1818
- repo: https://github.com/pre-commit/mirrors-clang-format
19-
rev: v18.1.3
19+
rev: v21.1.0
2020
hooks:
2121
- id: clang-format
2222
- repo: https://github.com/BlankSpruce/gersemi

dwio/nimble/velox/FlushPolicy.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717

1818
namespace facebook::nimble {
1919

20-
FlushDecision RawStripeSizeFlushPolicy::shouldFlush(
20+
FlushDecision StripeRawSizeFlushPolicy::shouldFlush(
2121
const StripeProgress& stripeProgress) {
22-
return stripeProgress.rawStripeSize >= rawStripeSize_ ? FlushDecision::Stripe
22+
return stripeProgress.stripeRawSize >= stripeRawSize_ ? FlushDecision::Stripe
2323
: FlushDecision::None;
2424
}
2525

26-
void RawStripeSizeFlushPolicy::onClose() {
27-
// No-op
28-
}
29-
3026
} // namespace facebook::nimble

dwio/nimble/velox/FlushPolicy.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ namespace facebook::nimble {
2222

2323
struct StripeProgress {
2424
// Size of the stripe data when it's fully decompressed and decoded
25-
const uint64_t rawStripeSize;
25+
const uint64_t stripeRawSize;
2626
// Size of the stripe after buffered data is encoded and optionally compressed
27-
const uint64_t stripeSize;
28-
// Size of the allocated buffer in the writer
29-
const uint64_t bufferSize;
27+
const uint64_t stripeEncodedSize;
3028
};
3129

3230
enum class FlushDecision : uint8_t {
@@ -39,38 +37,29 @@ class FlushPolicy {
3937
public:
4038
virtual ~FlushPolicy() = default;
4139
virtual FlushDecision shouldFlush(const StripeProgress& stripeProgress) = 0;
42-
// Required for memory pressure coordination for now. Will remove in the
43-
// future.
44-
virtual void onClose() = 0;
4540
};
4641

47-
class RawStripeSizeFlushPolicy final : public FlushPolicy {
42+
class StripeRawSizeFlushPolicy final : public FlushPolicy {
4843
public:
49-
explicit RawStripeSizeFlushPolicy(uint64_t rawStripeSize)
50-
: rawStripeSize_{rawStripeSize} {}
44+
explicit StripeRawSizeFlushPolicy(uint64_t stripeRawSize)
45+
: stripeRawSize_{stripeRawSize} {}
5146

5247
FlushDecision shouldFlush(const StripeProgress& stripeProgress) override;
5348

54-
void onClose() override;
55-
5649
private:
57-
const uint64_t rawStripeSize_;
50+
const uint64_t stripeRawSize_;
5851
};
5952

6053
class LambdaFlushPolicy : public FlushPolicy {
6154
public:
6255
explicit LambdaFlushPolicy(
6356
std::function<FlushDecision(const StripeProgress&)> lambda)
64-
: lambda_{lambda} {}
57+
: lambda_{std::move(lambda)} {}
6558

6659
FlushDecision shouldFlush(const StripeProgress& stripeProgress) override {
6760
return lambda_(stripeProgress);
6861
}
6962

70-
void onClose() override {
71-
// No-op
72-
}
73-
7463
private:
7564
std::function<FlushDecision(const StripeProgress&)> lambda_;
7665
};

dwio/nimble/velox/VeloxWriter.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "dwio/nimble/velox/SchemaSerialization.h"
3434
#include "dwio/nimble/velox/SchemaTypes.h"
3535
#include "dwio/nimble/velox/StatsGenerated.h"
36-
#include "folly/ScopeGuard.h"
3736
#include "velox/common/time/CpuWallTimer.h"
3837
#include "velox/dwio/common/ExecutorBarrier.h"
3938
#include "velox/type/Type.h"
@@ -552,8 +551,6 @@ void VeloxWriter::close() {
552551

553552
if (file_) {
554553
try {
555-
auto exitGuard =
556-
folly::makeGuard([this]() { context_->flushPolicy->onClose(); });
557554
flush();
558555
root_->close();
559556

@@ -847,11 +844,8 @@ bool VeloxWriter::tryWriteStripe(bool force) {
847844
auto shouldFlush = [&]() {
848845
return context_->flushPolicy->shouldFlush(
849846
StripeProgress{
850-
.rawStripeSize = context_->memoryUsed,
851-
.stripeSize = context_->stripeSize,
852-
.bufferSize =
853-
static_cast<uint64_t>(context_->bufferMemoryPool->usedBytes()),
854-
});
847+
.stripeRawSize = context_->memoryUsed,
848+
.stripeEncodedSize = context_->stripeSize});
855849
};
856850

857851
auto decision = force ? FlushDecision::Stripe : shouldFlush();

dwio/nimble/velox/VeloxWriterOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct VeloxWriterOptions {
109109
// Provides policy that controls stripe sizes and memory footprint.
110110
std::function<std::unique_ptr<FlushPolicy>()> flushPolicyFactory = []() {
111111
// Buffering 256MB data before encoding stripes.
112-
return std::make_unique<RawStripeSizeFlushPolicy>(256 << 20);
112+
return std::make_unique<StripeRawSizeFlushPolicy>(256 << 20);
113113
};
114114

115115
// When the writer needs to buffer data, and internal buffers don't have

dwio/nimble/velox/tests/VeloxWriterTests.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,21 @@ std::vector<velox::RowVectorPtr> generateBatches(
297297
}
298298
} // namespace
299299

300-
struct RawStripeSizeFlushPolicyTestCase {
300+
struct StripeRawSizeFlushPolicyTestCase {
301301
const size_t batchCount;
302302
const uint32_t rawStripeSize;
303303
const uint32_t stripeCount;
304304
};
305305

306-
class RawStripeSizeFlushPolicyTest
306+
class StripeRawSizeFlushPolicyTest
307307
: public VeloxWriterTests,
308-
public ::testing::WithParamInterface<RawStripeSizeFlushPolicyTestCase> {};
308+
public ::testing::WithParamInterface<StripeRawSizeFlushPolicyTestCase> {};
309309

310-
TEST_P(RawStripeSizeFlushPolicyTest, RawStripeSizeFlushPolicy) {
310+
TEST_P(StripeRawSizeFlushPolicyTest, StripeRawSizeFlushPolicy) {
311311
auto type = velox::ROW({{"simple", velox::INTEGER()}});
312312
nimble::VeloxWriterOptions writerOptions{.flushPolicyFactory = []() {
313313
// Buffering 256MB data before encoding stripes.
314-
return std::make_unique<nimble::RawStripeSizeFlushPolicy>(
314+
return std::make_unique<nimble::StripeRawSizeFlushPolicy>(
315315
GetParam().rawStripeSize);
316316
}};
317317

@@ -385,7 +385,7 @@ TEST_F(VeloxWriterTests, MemoryReclaimPath) {
385385

386386
TEST_F(VeloxWriterTests, FlushHugeStrings) {
387387
nimble::VeloxWriterOptions writerOptions{.flushPolicyFactory = []() {
388-
return std::make_unique<nimble::RawStripeSizeFlushPolicy>(1 * 1024 * 1024);
388+
return std::make_unique<nimble::StripeRawSizeFlushPolicy>(1 * 1024 * 1024);
389389
}};
390390

391391
velox::test::VectorMaker vectorMaker{leafPool_.get()};
@@ -1953,26 +1953,26 @@ TEST_F(VeloxWriterTests, RawSizeWritten) {
19531953
}
19541954

19551955
INSTANTIATE_TEST_CASE_P(
1956-
RawStripeSizeFlushPolicyTestSuite,
1957-
RawStripeSizeFlushPolicyTest,
1956+
StripeRawSizeFlushPolicyTestSuite,
1957+
StripeRawSizeFlushPolicyTest,
19581958
::testing::Values(
1959-
RawStripeSizeFlushPolicyTestCase{
1959+
StripeRawSizeFlushPolicyTestCase{
19601960
.batchCount = 50,
19611961
.rawStripeSize = 256 << 10,
19621962
.stripeCount = 4},
1963-
RawStripeSizeFlushPolicyTestCase{
1963+
StripeRawSizeFlushPolicyTestCase{
19641964
.batchCount = 100,
19651965
.rawStripeSize = 256 << 10,
19661966
.stripeCount = 7},
1967-
RawStripeSizeFlushPolicyTestCase{
1967+
StripeRawSizeFlushPolicyTestCase{
19681968
.batchCount = 100,
19691969
.rawStripeSize = 256 << 11,
19701970
.stripeCount = 4},
1971-
RawStripeSizeFlushPolicyTestCase{
1971+
StripeRawSizeFlushPolicyTestCase{
19721972
.batchCount = 100,
19731973
.rawStripeSize = 256 << 12,
19741974
.stripeCount = 2},
1975-
RawStripeSizeFlushPolicyTestCase{
1975+
StripeRawSizeFlushPolicyTestCase{
19761976
.batchCount = 100,
19771977
.rawStripeSize = 256 << 20,
19781978
.stripeCount = 1}));

0 commit comments

Comments
 (0)