forked from yliu634/smash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulations.cpp
More file actions
115 lines (98 loc) · 3.19 KB
/
simulations.cpp
File metadata and controls
115 lines (98 loc) · 3.19 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
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
#include "common.h"
#include "Smash/node.h"
#include "Smash/lookup_fn.h"
#include "Smash/storage_node.h"
#include "Smash/master_fn.h"
#include "Smash/client.h"
#include "Smash/name_server.h"
#include "Smash/commander.h"
#include "ycsb_workload.h"
void simulateClient() {
Client client;
this_thread::sleep_for(1s);
client.requestTopo();
vector<char> buffer;
buffer.resize(blockSize);
for (int i = 0; i < blockSize; ++i) {
buffer[i] = i;
}
for (int i = 0; i < 10; ++i) {
buffer[0] = i;
client.Insert("k" + to_string(i), buffer.data());
this_thread::sleep_for(1s);
vector<char> tmp = client.Read("k" + to_string(i));
if (tmp[0] != i) debug_break();
if (i >= 3) {
tmp = client.Read("k" + to_string(i - 2));
if (tmp[0] != i - 2) debug_break();
client.Remove("k" + to_string(i - 3));
}
}
// for (int i = 7; i < 10; ++i) {
// client.Remove("k" + to_string(i));
// }
cout << "done! " << endl;
}
int main(int argc, char **argv) {
commonInit();
if (argc <= 1) return -1;
if (argv[1] == string("ns")) {
ns_main(argc, argv);
} else if (argv[1] == string("master")) {
master_main(argc, argv);
} else if (argv[1] == string("lookup")) {
lookup_main(argc, argv);
} else if (argv[1] == string("storage")) {//fileName, port
if (argc <= 3) return -1;
storage_main(argc, argv);
} else if (argv[1] == string("client")) {
simulateClient();
} else if (argv[1] == string("loadC")) { // ycsb-like interface
int records = argc == 4 ? 1000 : atoi(argv[4]);
YCSB y(argv[2], atoi(argv[3]), records);
y.loadCeph();
} else if (argv[1] == string("loadS")) { // ycsb-like interface
int records = argc == 4 ? 1000 : atoi(argv[4]);
YCSB y(argv[2], atoi(argv[3]), records);
y.loadSmash();
} else if (argv[1] == string("runC")) { // ycsb-like interface
int records = argc == 4 ? 1000 : atoi(argv[4]);
YCSB y(argv[2], atoi(argv[3]), records);
y.runCeph();
} else if (argv[1] == string("runS")) { // ycsb-like interface
int records = argc == 4 ? 1000 : atoi(argv[4]);
YCSB y(argv[2], atoi(argv[3]), records);
y.runSmash();
} else if (argv[1] == string("cmd")) {
Commander c;
c.startRoutine();
} else if (argv[1] == string("all")) {
NameServer ns;
vector<Master *> masters; // no duplication for simulation
vector<Lookup *> lookups;
vector<Storage *> storages;
for (int i = 0; i < ns.nMasters; ++i) {
auto *node = new Master;
node->sendRegisterMsg();
masters.push_back(node);
}
for (int i = 0; i < ns.nLookups; ++i) {
auto *node = new Lookup;
node->sendRegisterMsg();
lookups.push_back(node);
}
for (int i = 0; i < ns.nStorages; ++i) {
auto *node = new Storage(10, "dist/store-" + to_string(i));
node->sendRegisterMsg();
storages.push_back(node);
}
thread([argc, argv]() {
prctl(PR_SET_NAME, "client main", 0, 0, 0);
simulateClient();
}).detach();
while (true) {
this_thread::sleep_for(1s);
}
}
return 0;
}