forked from dase/CLAIMS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnvironment.cpp
More file actions
executable file
·221 lines (189 loc) · 5.62 KB
/
Environment.cpp
File metadata and controls
executable file
·221 lines (189 loc) · 5.62 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Environment.cpp
*
* Created on: Aug 10, 2013
* Author: wangli
*/
#include "Environment.h"
#include <libconfig.h++>
#include <iostream>
#include <sstream>
#include <string>
#include "Debug.h"
#include "Config.h"
#include "common/Logging.h"
#include "common/TypePromotionMap.h"
#include "common/TypeCast.h"
#include "common/Expression/queryfunc.h"
#include "codegen/CodeGenerator.h"
Environment* Environment::_instance=0;
Environment::Environment(bool ismaster):ismaster_(ismaster) {
_instance=this;
Config::getInstance();
CodeGenerator::getInstance();
logging_=new EnvironmentLogging();
readConfigFile();
initializeExpressionSystem();
portManager=PortManager::getInstance();
if(ismaster){
logging_->log("Initializing the Coordinator...");
initializeCoordinator();
catalog_=Catalog::getInstance();
catalog_->restoreCatalog();
}
if (true == g_thread_pool_used){
logging_->log("Initializing the ThreadPool...");
if (false == initializeThreadPool()) {
logging_->elog("initialize ThreadPool failed");
}
}
logging_->log("Initializing the AdaptiveEndPoint...");
initializeEndPoint();
/**
* TODO:
* DO something in AdaptiveEndPoint such that the construction function does
not return until the connection is completed. If so, the following sleep()
dose not needed.
This is done in Aug.18 by Li :)
*/
/*Before initializing Resource Manager, the instance ip and port should be decided.*/
initializeResourceManager();
// return;
initializeStorage();
initializeBufferManager();
logging_->log("Initializing the ExecutorMaster...");
iteratorExecutorMaster=new IteratorExecutorMaster();
logging_->log("Initializing the ExecutorSlave...");
iteratorExecutorSlave=new IteratorExecutorSlave();
exchangeTracker =new ExchangeTracker();
expander_tracker_=ExpanderTracker::getInstance();
if(ismaster){
initializeClientListener();
}
}
Environment::~Environment() {
_instance=0;
delete expander_tracker_;
delete logging_;
delete portManager;
delete catalog_;
delete coordinator;
if(ismaster_){
delete iteratorExecutorMaster;
delete resourceManagerMaster_;
delete blockManagerMaster_;
destoryClientListener();
}
delete iteratorExecutorSlave;
delete exchangeTracker;
delete resourceManagerSlave_;
delete blockManager_;
delete bufferManager_;
delete endpoint;
}
Environment* Environment::getInstance(bool ismaster){
if(_instance==0){
new Environment(ismaster);
}
return _instance;
}
std::string Environment::getIp(){
return ip;
}
unsigned Environment::getPort(){
return port;
}
ThreadPool* Environment::getThreadPool() const{
return thread_pool_;
}
void Environment::readConfigFile(){
libconfig::Config cfg;
cfg.readFile(Config::config_file.c_str());
ip=(const char*)cfg.lookup("ip");
}
void Environment::initializeEndPoint(){
// libconfig::Config cfg;
// cfg.readFile("/home/claims/config/wangli/config");
// std::string endpoint_ip=(const char*)cfg.lookup("ip");
// std::string endpoint_port=(const char*)cfg.lookup("port");
std::string endpoint_ip=ip;
int endpoint_port;
if((endpoint_port=portManager->applyPort())==-1){
logging_->elog("The ports in the PortManager is exhausted!");
}
port=endpoint_port;
logging_->log("Initializing the AdaptiveEndPoint as EndPoint://%s:%d.",endpoint_ip.c_str(),endpoint_port);
std::ostringstream name,port_str;
port_str<<endpoint_port;
name<<"EndPoint://"<<endpoint_ip<<":"<<endpoint_port;
endpoint=new AdaptiveEndPoint(name.str().c_str(),endpoint_ip,port_str.str());
}
void Environment::initializeCoordinator(){
coordinator=new Coordinator();
}
void Environment::initializeStorage(){
if(ismaster_){
blockManagerMaster_=BlockManagerMaster::getInstance();
blockManagerMaster_->initialize();
}
/*both master and slave node run the BlockManager.*/
// BlockManagerId *bmid=new BlockManagerId();
// string actorname="blockManagerWorkerActor_"+bmid->blockManagerId;
// cout<<actorname.c_str()<<endl;
// BlockManager::BlockManagerWorkerActor *blockManagerWorkerActor=new BlockManager::BlockManagerWorkerActor(endpoint,framework_storage,actorname.c_str());
blockManager_=BlockManager::getInstance();
blockManager_->initialize();
}
void Environment::initializeResourceManager(){
if(ismaster_){
resourceManagerMaster_=new ResourceManagerMaster();
}
resourceManagerSlave_=new InstanceResourceManager();
nodeid=resourceManagerSlave_->Register();
}
void Environment::initializeBufferManager(){
bufferManager_=BufferManager::getInstance();
}
void Environment::initializeIndexManager()
{
indexManager_ = IndexManager::getInstance();
}
AdaptiveEndPoint* Environment::getEndPoint(){
return endpoint;
}
ExchangeTracker* Environment::getExchangeTracker(){
return exchangeTracker;
}
ResourceManagerMaster* Environment::getResourceManagerMaster(){
return resourceManagerMaster_;
}
InstanceResourceManager* Environment::getResourceManagerSlave(){
return resourceManagerSlave_;
}
NodeID Environment::getNodeID()const{
return nodeid;
}
Catalog* Environment::getCatalog()const{
return catalog_;
}
void Environment::initializeClientListener() {
listener_=new ClientListener(Config::client_listener_port);
listener_->configure();
}
void Environment::initializeExpressionSystem() {
initialize_arithmetic_type_promotion_matrix();
initialize_type_cast_functions();
initialize_operator_function();
}
void Environment::destoryClientListener() {
listener_->shutdown();
delete listener_;
}
bool Environment::initializeThreadPool() {
thread_pool_ = new ThreadPool();
// return thread_pool_->Thread_Pool_init(2*sysconf(_SC_NPROCESSORS_CONF));
return thread_pool_->Thread_Pool_init(100);
}
IteratorExecutorSlave* Environment::getIteratorExecutorSlave() const {
return iteratorExecutorSlave;
}