forked from dase/CLAIMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.cpp
executable file
·149 lines (140 loc) · 3.82 KB
/
Server.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
#include <Test/TestMain.cpp>
#include <startup.h>
#include "Parsetree/ExecuteLogicalQueryPlan.h"
#include "/usr/include/assert.h"
#include "Test/set_up_environment.h"
#include <getopt.h>
#define AUTU_MASTER
//#define FORK
//#define DEBUG_MODE
struct option long_options[] = {
{"config-file", required_argument, 0, 'c'},
{"help", no_argument, 0, 'h'},
{"disable-codegen",no_argument,0,'d'},
{"catalog",required_argument,0,256},
{"elastic",no_argument,0,'e'},
{"init-dop",required_argument,0,257},
{"max-dop",required_argument,0,258},
{"datadir",required_argument,0,259},
{"scheduler_cycle",required_argument,0,260},
{nullptr,0,0,0}
};
std::string help_info=std::string("-c --config-file FILE_NAME\n\t\t Specify the configure file\n")+
"-h --help\n\t\t Print the help info\n"+
"-d --disable-codegen\n\t\t disable code generation feature\n"+
"-e --elastic \n\t\t enable elasticity feature\n"+
" --catalog CATALOG_FILE\n\t\t specified the catalog file\n"+
" --init-dop VALUE\n\t\t specified the initial degree of parallelism for each segment\n"+
" --max-dop VALUE\n\t\t specified the max degree of parallelism for each segment\n"+
" --datadir VALUE\n\t\t specified the data directory.\n"+
" --scheduler_cycle VALUE\n\t\t specified the cycle(in us) for the elastic scheduler\n";
void handle_parameters(int argc, char** argv){
optind=0;
int opt;
while ((opt = getopt_long(argc, argv, "c:h", long_options, NULL)) != -1) {
switch (opt) {
case 'c':
Config::config_file = std::string(optarg);
break;
case 'h':
printf("%s",help_info.c_str());
exit(1);
break;
case 'd':
Config::enable_codegen=false;
break;
case 'e':
Config::enable_expander_adaptivity = true;
break;
case 256:
Config::catalog_file=std::string(optarg);
break;
case 257:
Config::initial_degree_of_parallelism=atoi(optarg);
break;
case 258:
Config::max_degree_of_parallelism=atoi(optarg);
break;
case 259:
Config::data_dir=std::string(optarg);
break;
case 260:
Config::expander_adaptivity_check_frequency=atoi(optarg);
break;
default:
printf("Invalid parameters! Try -h/--help\n");
exit(1);
break;
}
}
}
int main(int argc, char** argv){
handle_parameters(argc,argv);
Config::getInstance();
handle_parameters(argc,argv);
Config::getInstance()->print_configure();
#ifndef DEBUG_MODE
bool master;
#ifndef AUTU_MASTER
printf("If Master, please print 1!\n");
int master=0;
scanf("%d",&master);
#else
master=Config::master;
#endif
std::string actor;
if(master)
actor="master";
else
actor="slave";
#ifndef FORK
if(master){
Environment::getInstance(master);
// create_poc_data_four_partitions();
// create_poc_data_one_partitions();
// print_welcome();
// ExecuteLogicalQueryPlan();
while(true)
sleep(1);
}
else {
sleep(1); //wait for server init...
Environment::getInstance(master);
while(true)
sleep(1);
}
#else
int pid=fork();
if(pid!=0){
printf("Daemon process id is %d\n",pid);
sleep(1);
return 0;
}
Config::getInstance();
printf("Creating %s daemon...\n",actor.c_str());
Environment::getInstance(master);
printf("The %s daemon is successfully created.!\n",actor.c_str());
printf("Logs are redirected to %s\n",Config::logfile.c_str());
FILE *file;
if((file=freopen(Config::logfile.c_str(),"a",stdout))==NULL){
printf("output redirection fails!\n");
}
freopen(Config::logfile.c_str(),"a",stderr);
fflush(stdout);
fclose(stdout);
//redirect back to console
freopen("/dev/tty","a",stdout);
printf("The Slave daemon is successfully created!\n");
//redirect again to the log file.
if((file=freopen(Config::logfile.c_str(),"a",stdout))==NULL){
printf("output redirection fails!\n");
}
freopen(Config::logfile.c_str(),"a",stderr);
while(true)
sleep(1);
#endif
#else
maina(argc, argv);
return 0;
#endif
}