-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompactor.cpp
More file actions
60 lines (51 loc) · 2.03 KB
/
compactor.cpp
File metadata and controls
60 lines (51 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "compactor.h"
namespace compaction {
void NaiveCompactor::Compact(unique_ptr<DataChunk> &chunk) {
if (chunk->count_ == kBlockSize) return;
Profiler profiler;
profiler.Start();
{
// move
if (chunk->count_ <= kBlockSize - cached_chunk_->count_) {
cached_chunk_->Append(*chunk, chunk->count_);
double time = profiler.Elapsed();
BeeProfiler::Get().InsertStatRecord("[Naive Compact - Append] " + name_, time);
ZebraProfiler::Get().InsertRecord("[Naive Compact - Append] " + name_, chunk->count_, time);
chunk->Reset();
return;
}
size_t n_move = kBlockSize - cached_chunk_->count_;
cached_chunk_->Append(*chunk, n_move);
temp_chunk_->Append(*chunk, chunk->count_ - n_move, n_move);
}
double time = profiler.Elapsed();
BeeProfiler::Get().InsertStatRecord("[Naive Compact - Append] " + name_, time);
ZebraProfiler::Get().InsertRecord("[Naive Compact - Append] " + name_, chunk->count_, time);
// profiler.Start();
{
// swap
chunk.swap(cached_chunk_);
cached_chunk_.swap(temp_chunk_);
temp_chunk_->Reset();
// temp_chunk_ = std::make_unique<DataChunk>(chunk->types_);
}
time = profiler.Elapsed();
BeeProfiler::Get().InsertStatRecord("[Naive Compact - Fetch] " + name_, time);
ZebraProfiler::Get().InsertRecord("[Naive Compact - Fetch] " + name_, chunk->count_, time);
}
void DynamicCompactor::Compact(unique_ptr<DataChunk> &chunk) {
if (chunk->count_ >= compact_threshold_) return;
// Because the compaction threshold can be changed during execution, we must add this code.
if (chunk->count_ > kBlockSize - cached_chunk_->count_) return;
profiler_.Start();
cached_chunk_->Append(*chunk, chunk->count_);
chunk->count_ = 0;
if (cached_chunk_->count_ > kBlockSize - compact_threshold_) {
chunk = std::move(cached_chunk_);
cached_chunk_ = std::make_unique<DataChunk>(chunk->types_);
}
double time = profiler_.Elapsed();
BeeProfiler::Get().InsertStatRecord(name_, time);
ZebraProfiler::Get().InsertRecord(name_, chunk->count_, time);
}
}