-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
237 lines (206 loc) · 8.9 KB
/
main.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright (c) Xiangyu Zou, 2020. All rights reserved.
// This source code is licensed under the GPLv2
#include <iostream>
#include "DedupPipeline/ReadFilePipeline.h"
#include "RestorePipeline/RestoreReadPipeline.h"
#include "DedupPipeline/Eliminator.h"
#include "gflags/gflags.h"
#include "Utility/Config.h"
#include "Utility/Manifest.h"
#include "ArrangementPipeline/ArrangementReadPipeline.h"
DEFINE_string(RestorePath,
"", "restore path");
DEFINE_uint64(RestoreRecipe,
1, "restore recipe");
DEFINE_string(task,
"", "task type");
DEFINE_string(BatchFilePath,
"", "batch process file path");
DEFINE_string(ConfigFile,
"", "config path");
DEFINE_string(InputFile,
"", "input path");
DEFINE_bool(ApplyArrangement,
true, "Whether apply arrangement");
std::string LogicFilePath;
std::string ClassFilePath;
std::string VersionFilePath;
std::string ManifestPath;
std::string HomePath;
std::string ClassFileAppendPath;
uint64_t TotalVersion;
uint64_t RetentionTime;
std::string KVPath;
uint64_t do_backup(const std::string& path){
StorageTask storageTask;
CountdownLatch countdownLatch(5); // there are 5 pipelines in the workflow of write.
storageTask.path = path;
storageTask.countdownLatch = &countdownLatch;
storageTask.fileID = TotalVersion;
GlobalReadPipelinePtr->addTask(&storageTask);
countdownLatch.wait();
return storageTask.length;
}
int do_restore(uint64_t version, uint64_t fallBehind){
struct timeval t0, t1;
char recipePath[256];
sprintf(recipePath, LogicFilePath.data(), version);
CountdownLatch countdownLatch(1);
RestoreTask restoreTask = {
TotalVersion,
version,
fallBehind
};
GlobalRestoreReadPipelinePtr = new RestoreReadPipeline();
GlobalRestoreWritePipelinePtr = new RestoreWritePipeline(FLAGS_RestorePath, &countdownLatch); // order is important.
GlobalRestoreParserPipelinePtr = new RestoreParserPipeline(version, recipePath); // order is important.
gettimeofday(&t0, NULL);
GlobalRestoreReadPipelinePtr->addTask(&restoreTask);
countdownLatch.wait();
gettimeofday(&t1, NULL);
uint64_t duration = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
printf("Total duration : %lu, speed : %f MB/s\n", duration, (float)GlobalRestoreWritePipelinePtr->getTotalSize() / duration);
delete GlobalRestoreReadPipelinePtr;
delete GlobalRestoreParserPipelinePtr;
delete GlobalRestoreWritePipelinePtr;
return 0;
}
int do_arrangement(){
printf("Arrangement Task: Version %lu\n", TotalVersion-1);
CountdownLatch arrangementLatch(1);
ArrangementTask arrangementTask = {
TotalVersion - 1, &arrangementLatch,
};
GlobalArrangementReadPipelinePtr->addTask(&arrangementTask);
arrangementLatch.wait();
}
int do_delete(){
printf("------------------------Deleting----------------------\n");
printf("%lu versions exist, delete the earliest version\n", TotalVersion);
printf("Delete Task..\n");
Eliminator eliminator;
eliminator.run(TotalVersion);
TotalVersion--;
}
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
std::string statusStr("status");
std::string restoreStr("restore");
std::string writeStr("write");
std::string batchStr("batch");
std::string eliminateStr("delete");
Manifest manifest;
{
ConfigReader configReader(FLAGS_ConfigFile);
ManifestReader manifestReader(&manifest);
TotalVersion = manifest.TotalVersion;
}
if (FLAGS_task == writeStr) {
// pipelines init
//------------------------------------------------------
GlobalReadPipelinePtr = new ReadFilePipeline();
GlobalChunkingPipelinePtr = new ChunkingPipeline();
GlobalHashingPipelinePtr = new HashingPipeline();
GlobalDeduplicationPipelinePtr = new DeduplicationPipeline();
GlobalWriteFilePipelinePtr = new WriteFilePipeline();
GlobalMetadataManagerPtr = new MetadataManager();
GlobalArrangementReadPipelinePtr = new ArrangementReadPipeline();
GlobalArrangementFilterPipelinePtr = new ArrangementFilterPipeline();
GlobalArrangementWritePipelinePtr = new ArrangementWritePipeline();
//------------------------------------------------------
if(TotalVersion != 0)
GlobalMetadataManagerPtr->load();
uint64_t dedupDuration = 0, arrDuration = 0;
std::string workloadPath = FLAGS_InputFile;
uint64_t taskLength = 0;
{
TotalVersion++;
printf("-----------------------Backing up-----------------------\n");
printf("Dedup Task: %s\n", workloadPath.data());
struct timeval t0, t1;
gettimeofday(&t0, NULL);
taskLength = do_backup(workloadPath);
gettimeofday(&t1, NULL);
uint64_t singleDedup = (t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec;
dedupDuration += singleDedup;
printf("Backup duration:%lu us, Backup Size:%lu, Speed:%fMB/s\n", singleDedup, taskLength,
(float) taskLength / singleDedup);
GlobalReadPipelinePtr->getStatistics();
GlobalChunkingPipelinePtr->getStatistics();
GlobalHashingPipelinePtr->getStatistics();
GlobalDeduplicationPipelinePtr->getStatistics();
GlobalWriteFilePipelinePtr->getStatistics();
printf("----------------------Arrangement------------------------\n");
if (FLAGS_ApplyArrangement){
gettimeofday(&t0, NULL);
do_arrangement();
gettimeofday(&t1, NULL);
uint64_t singleArr = (t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec;
arrDuration += singleArr;
printf("Arrangement duration : %lu\n", singleArr);
}else{
printf("Arrangement is disabled by user.\n");
manifest.ArrangementFallBehind++;
}
printf("------------------------Retention----------------------\n");
if(TotalVersion > RetentionTime){
do_delete();
}else{
printf("Only %lu versions exist, and the retention is %lu, deletion is not required.\n", TotalVersion, RetentionTime);
}
}
{
manifest.TotalVersion = TotalVersion;
ManifestWriter manifestWriter(manifest);
GlobalMetadataManagerPtr->save();
}
printf("==============================================\n");
printf("writing duration:%lu, arrange duration:%lu\n", dedupDuration, arrDuration);
printf("Total deduplication duration:%lu us, Total Size:%lu, Speed:%fMB/s\n", dedupDuration, taskLength,
(float) taskLength / dedupDuration);
GlobalDeduplicationPipelinePtr->getStatistics();
printf("done\n");
printf("==============================================\n");
// pipelines release
//------------------------------------------------------
delete GlobalReadPipelinePtr;
delete GlobalChunkingPipelinePtr;
delete GlobalHashingPipelinePtr;
delete GlobalDeduplicationPipelinePtr;
delete GlobalWriteFilePipelinePtr;
delete GlobalMetadataManagerPtr;
delete GlobalArrangementReadPipelinePtr;
delete GlobalArrangementFilterPipelinePtr;
delete GlobalArrangementWritePipelinePtr;
//------------------------------------------------------
}
else if (FLAGS_task == restoreStr) {
do_restore(FLAGS_RestoreRecipe, manifest.ArrangementFallBehind);
}
else if (FLAGS_task == eliminateStr) {
Eliminator eliminator;
eliminator.run(TotalVersion);
TotalVersion--;
{
manifest.TotalVersion = TotalVersion;
ManifestWriter manifestWriter(manifest);
}
}
else if (FLAGS_task == statusStr) {
printf("Totally %lu versions stored.\n", manifest.TotalVersion);
printf("Arrangement fall %lu versions behind.\n", manifest.ArrangementFallBehind);
}
else {
printf("=================================================\n");
printf("Usage: MFDedup [args..]\n");
printf("1. Write a series of versions into system\n");
printf("./MFDedup --ConfigFile=[config file] --task=write --InputFile=[backup workload]\n");
printf("2. Restore a version of from the system\n");
printf("./MFDedup --ConfigFile=config.toml --task=restore --RestorePath=[where the restored file is to locate] --RestoreRecipe=[which version to restore(1 ~ no. of the last retained version)]\n");
printf("3. Check status of the system\n");
printf("./MFDedup --task=status\n");
printf("--------------------------------------------------\n");
printf("more information with --help\n");
printf("=================================================\n");
}
}