-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStripeMap.cpp
More file actions
59 lines (45 loc) · 1.38 KB
/
StripeMap.cpp
File metadata and controls
59 lines (45 loc) · 1.38 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
#include "StripeMap.h"
using namespace std;
StripeMap::StripeMap(vector<string> disks, size_t chunkSize) {
this->diskPaths = disks;
this->chunkSize = chunkSize;
}
int StripeMap::fetchDiskId(size_t chunkIdx) {
if (chunkIdx >= stripeLayout.size()) {
cerr << "Error: Chunk index is out of bounds" << endl;
return -1;
}
return stripeLayout[chunkIdx];
}
string StripeMap::fetchDiskPath(int diskId) {
if (diskId >= diskPaths.size()) {
cerr << "Error: diskId index is out of bounds" << endl;
return NULL;
}
return diskPaths[diskId];
}
/*
* Simple build map function to map disks to our stripe layout
* TODO: eventually make a 'smarter' round robin algorithm
* to check for capacity for each drive
*/
void StripeMap::buildMap(size_t totalSize) {
stripeLayout.clear();
// ceils the # of chunks so we can fit the file
size_t totalChunks = (totalSize + chunkSize + 1) / chunkSize;
int totalDisks = diskPaths.size();
// reserve beforehand so vector doesn't need to recopy itself
stripeLayout.reserve(totalChunks);
for (size_t i = 0; i < totalChunks; i++) {
int targetDisk = i % totalDisks;
stripeLayout.push_back(targetDisk);
}
cout << "Finished building map with: " << totalChunks << " chunks for: "
<< totalDisks << " disks" << endl;
}
void StripeMap::setDiskPaths(const vector<string>& paths) {
diskPaths = paths;
}
size_t StripeMap::getChunkSize() {
return chunkSize;
}