-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminigfs_client1.cpp
97 lines (70 loc) · 4.67 KB
/
minigfs_client1.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
// ecs251 miniGFS
#include <iostream>
#include "Shadow_Directory.h"
#include "Shadow_Replica.h"
#include <thread>
#include <chrono>
using namespace std;
using namespace std::chrono_literals;
int
main()
{
Shadow_Directory gfs_master
{ "http://127.0.0.1:8384", "1234567890", "Directory", "00000002" };
Json::Value result, result_P, result_A, result_B;
std::cout<<" **************************************************************************"<<std::endl;
std::cout<<" ******* Step 1 of GFS Paper Call from Client to Master for 3 URLs ********"<<std::endl;
std::cout<<" **************************************************************************"<<std::endl;
result = gfs_master.ObtainChunkURL("my_ecs251_file", "00000002", "0");
std::cout<<" *****************************************************************************************"<<std::endl;
std::cout<<" ******** Step 1 & 2 of GFS Diagram Complete URLs Obtained *******************************"<<std::endl;
std::cout<<" ******************************************************************************************"<<std::endl;
std::string url_primary = (result["primary"]).asString();
Shadow_Replica gfs_primary
{ url_primary, "1234567890", "Replica", "00000002" };
std::string url_secondary_A = (result["secondary_A"]).asString();
Shadow_Replica gfs_secondary_A
{ url_secondary_A, "1234567890", "Replica", "00000002" };
std::string url_secondary_B = (result["secondary_B"]).asString();
Shadow_Replica gfs_secondary_B
{ url_secondary_B, "1234567890", "Replica", "00000002" };
// client-data
std::string my_chunk_data = { "c0-100-ecs251 data" };
std::cout<<" ***********************************************************************************************************************************************************"<<std::endl;
std::cout<<" **** Step 3 of GFS Paper Call from Client to Primary, Secondary A, Secondary B for PushChunk2Replica to push the chunks and get acknowledgment from all ****"<<std::endl;
std::cout<<" ***********************************************************************************************************************************************************"<<std::endl;
std::cout<<" ----------------------------------------------- " <<std::endl;
std::cout<<"******* Acknowlegment Vote from Primary ***********" << std::endl;
result_P = gfs_primary.PushChunk2Replica("my_ecs251_file", "00000002", "0", my_chunk_data);
std::cout<<" VOTE = " << result_P["status"]<<std::endl;
std::cout<<" ----------------------------------------------- " <<std::endl;
// std::cout<<"******* Acknowlegment Vote from Secondary A ***********" << std::endl;
// result_A = gfs_secondary_A.PushChunk2Replica("my_ecs251_file", "00000002", "0", my_chunk_data);
// std::cout<<" VOTE = " << result_A["vote"]<<std::endl;
// std::cout<<" ----------------------------------------------- " <<std::endl;
// std::cout<<"******* Acknowlegment Vote from Secondary B ***********" << std::endl;
// result_B = gfs_secondary_B.PushChunk2Replica("my_ecs251_file", "00000002", "0", my_chunk_data);
// std::cout<<" VOTE = " << result_B["vote"]<<std::endl;
// std::cout<<" ----------------------------------------------- " <<std::endl;
std::cout<<" **************************************"<<std::endl;
std::cout<<" **** Step 3 of GFS Paper Complete ****"<<std::endl;
std::cout<<" **************************************"<<std::endl;
std::cout<<" ----------------------------------------------- " <<std::endl;
std::cout<<" ***********************************************************************************************************************************************************"<<std::endl;
std::cout<<" ******** Step 4,5,6,7 of GFS Paper Call from Client to Primary, Secondary A, Secondary B for CommitAbort to commit the data based on the result of the votes ****"<<std::endl;
std::cout<<" ***********************************************************************************************************************************************************"<<std::endl;
if (((result_P["status"]).asString() == "success"))
{
std::this_thread::sleep_for(1500ms);
result_P = gfs_primary.CommitAbort("my_ecs251_file", "00000002", "0", "commit");
// result_A = gfs_secondary_A.CommitAbort("my_ecs251_file", "00000002", "0", "commit");
// result_B = gfs_secondary_B.CommitAbort("my_ecs251_file", "00000002", "0", "commit");
}
else
{
result_P = gfs_primary.CommitAbort("my_ecs251_file", "00000002", "0", "abort");
// result_A = gfs_secondary_A.CommitAbort("my_ecs251_file", "00000002", "0", "abort");
// result_B = gfs_secondary_B.CommitAbort("my_ecs251_file", "00000002", "0", "abort");
}
return 0;
}