-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_sink.h
123 lines (81 loc) · 2 KB
/
data_sink.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef _DATA_SINK_H_
#define _DATA_SINK_H_
#include <fstream>
#include "trace_types.h"
#include "disk_io.h"
#include <map>
#include "partition_index.h"
using namespace std;
// base class for data receiver
class DataSink
{
public:
DataSink();
virtual ~DataSink();
virtual void ProcessBuffer() = 0;
virtual void Stat() = 0;
public:
DataRecord* mRecord;
protected:
MsgHeader mHeader;
int mReadPos; // reading position of current buffer
char* mRecvBuf; // current receive buffer
char* mEndOfBuf; // end of the last receive buffer
int mBufSize;
int mRecordSize;
protected:
// after data processing, must be restored to initial state
void Reset();
// extract the next record from receive buffers, store in mRecord,
// return true on success, false if no record can be extracted.
bool GetRecord();
};
// save raw records into q partitions
class RawRecordAccumulator : public DataSink
{
public:
RawRecordAccumulator();
~RawRecordAccumulator();
void ProcessBuffer();
void Stat();
private:
RecordWriter<Block>** mWriterPtrs;
uint64_t mStatRecordCount;
};
// save new blocks by vm
class NewRecordAccumulator : public DataSink
{
public:
NewRecordAccumulator();
~NewRecordAccumulator();
void ProcessBuffer();
void Stat();
private:
map<int, RecordWriter<Block>*> mWriters;
uint64_t mStatRecordCount;
};
// save new refs by partition
class NewRefAccumulator : public DataSink
{
public:
NewRefAccumulator();
~NewRefAccumulator();
void ProcessBuffer();
void Stat();
private:
RecordWriter<IndexEntry>** mWriterPtrs;
uint64_t mStatRecordCount;
};
// save dup block meta by vm
class DupRecordAccumulator : public DataSink
{
public:
DupRecordAccumulator();
~DupRecordAccumulator();
void ProcessBuffer();
void Stat();
private:
map<int, RecordWriter<BlockMeta>*> mWriters;
uint64_t mStatRecordCount;
};
#endif