Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
statestored-main.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //
16 // This file contains the main() function for the state store process,
17 // which exports the Thrift service StatestoreService.
18 
19 #include <iostream>
20 #include <string>
21 
22 #include "common/init.h"
23 #include "common/logging.h"
24 #include "common/status.h"
25 #include "rpc/rpc-trace.h"
26 #include "runtime/mem-tracker.h"
27 #include "statestore/statestore.h"
28 #include "util/debug-util.h"
29 #include "util/metrics.h"
30 #include "util/memory-metrics.h"
31 #include "util/webserver.h"
33 
34 DECLARE_int32(state_store_port);
35 DECLARE_int32(webserver_port);
36 DECLARE_bool(enable_webserver);
37 DECLARE_string(principal);
38 
39 #include "common/names.h"
40 
41 using namespace impala;
42 using namespace apache::thrift;
43 
44 int main(int argc, char** argv) {
45  // Override default for webserver port
46  FLAGS_webserver_port = 25010;
47  InitCommonRuntime(argc, argv, false);
48 
49  MemTracker mem_tracker;
50  scoped_ptr<Webserver> webserver(new Webserver());
51 
52  if (FLAGS_enable_webserver) {
53  AddDefaultUrlCallbacks(webserver.get(), &mem_tracker);
54  EXIT_IF_ERROR(webserver->Start());
55  } else {
56  LOG(INFO) << "Not starting webserver";
57  }
58 
59  scoped_ptr<MetricGroup> metrics(new MetricGroup("statestore"));
60  metrics->Init(FLAGS_enable_webserver ? webserver.get() : NULL);
61  EXIT_IF_ERROR(RegisterMemoryMetrics(metrics.get(), false));
62  StartThreadInstrumentation(metrics.get(), webserver.get());
63  InitRpcEventTracing(webserver.get());
64  // TODO: Add a 'common metrics' method to add standard metrics to
65  // both statestored and impalad
66  metrics->AddProperty<string>("statestore.version", GetVersionString(true));
67 
68  Statestore statestore(metrics.get());
69  statestore.RegisterWebpages(webserver.get());
70  shared_ptr<TProcessor> processor(
71  new StatestoreServiceProcessor(statestore.thrift_iface()));
72  shared_ptr<TProcessorEventHandler> event_handler(
73  new RpcEventHandler("statestore", metrics.get()));
74  processor->setEventHandler(event_handler);
75 
76  ThriftServer* server = new ThriftServer("StatestoreService", processor,
77  FLAGS_state_store_port, NULL, metrics.get(), 5);
78  EXIT_IF_ERROR(server->Start());
79 
80  statestore.MainLoop();
81 }
void RegisterWebpages(Webserver *webserver)
Definition: statestore.cc:253
void AddDefaultUrlCallbacks(Webserver *webserver, MemTracker *process_mem_tracker=NULL)
string GetVersionString(bool compact)
Returns "<program short name> version <GetBuildVersion(compact)>".
Definition: debug-util.cc:239
int main(int argc, char **argv)
Status RegisterMemoryMetrics(MetricGroup *metrics, bool register_jvm_metrics)
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
Definition: init.cc:122
MetricGroups may be organised hierarchically as a tree.
Definition: metrics.h:200
DECLARE_string(principal)
Status StartThreadInstrumentation(MetricGroup *metrics, Webserver *webserver)
Definition: thread.cc:266
DECLARE_int32(state_store_port)
void InitRpcEventTracing(Webserver *webserver)
Initialises rpc event tracing, must be called before any RpcEventHandlers are created.
Definition: rpc-trace.cc:67
#define EXIT_IF_ERROR(stmt)
Definition: status.h:248
This class is thread-safe.
Definition: mem-tracker.h:61
DECLARE_bool(enable_webserver)