-
Notifications
You must be signed in to change notification settings - Fork 57
/
Server.cpp
156 lines (149 loc) · 4.71 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
150
151
152
153
154
155
156
#define GLOG_NO_ABBREVIATED_SEVERITIES
#include <startup.h>
#include <getopt.h>
#include <string>
// #include "Test/set_up_environment.h"
#include "./Test/TestMain.cpp"
#include "common/log/logging.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) {
using claims::common::Logging;
handle_parameters(argc, argv);
Config::getInstance();
handle_parameters(argc, argv);
Config::getInstance()->print_configure();
Logging claims_logging(argv[0]);
#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 (std::cin.get() != 'q') sleep(1);
// } else {
// Environment::getInstance(master);
// while (std::cin.get() != 'q') sleep(1);
// }
while (1) sleep(1);
} else {
Environment::getInstance(master);
while (1) 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
Environment::getInstance(true);
MainDebug(argc, argv);
Environment::getInstance(1)->~Environment();
return 0;
#endif
}