0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
main.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 
24 #include "Config.h"
25 #include "ConnectionHandler.h"
26 #include "Global.h"
28 #include "RangeServer.h"
29 #include "IndexUpdater.h"
30 
32 
34 #include <AsyncComm/Comm.h>
38 
39 #include <Common/FailureInducer.h>
40 #include <Common/Init.h>
41 #include <Common/InetAddr.h>
42 #include <Common/Logger.h>
43 #include <Common/System.h>
44 #include <Common/Usage.h>
45 
46 #include <cstdlib>
47 #include <cstring>
48 #include <iostream>
49 #include <string>
50 
51 using namespace Hypertable;
52 using namespace Config;
53 using namespace std;
54 
57 
58 int main(int argc, char **argv) {
59 
61 
62  init_with_policies<Policies>(argc, argv);
63 
64  try {
65 
66  Global::verbose = get_bool("verbose");
67 
68  if (has("induce-failure")) {
69  if (FailureInducer::instance == 0)
71  FailureInducer::instance->parse_option(get_str("induce-failure"));
72  }
73 
74  // issue 851: don't start if config files are missing
75  if (!FileUtils::exists(System::install_dir + "/conf/METADATA.xml"))
76  HT_FATALF("%s/conf/METADATA.xml is missing, aborting...",
77  System::install_dir.c_str());
78  if (!FileUtils::exists(System::install_dir + "/conf/RS_METRICS.xml"))
79  HT_FATALF("%s/conf/RS_METRICS.xml is missing, aborting...",
80  System::install_dir.c_str());
81 
82  Comm *comm = Comm::instance();
83  ConnectionManagerPtr conn_manager = make_shared<ConnectionManager>(comm);
84  Global::conn_manager = conn_manager;
85 
86  int worker_count = get_i32("Hypertable.RangeServer.Workers");
87  Global::app_queue = make_shared<ApplicationQueue>(worker_count);
88 
92  HyperspaceSessionHandler hs_handler;
93  Global::hyperspace = make_shared<Hyperspace::Session>(comm, properties);
94  Global::hyperspace->add_callback(&hs_handler);
95  int hyperspace_timeout = get_i32("Hyperspace.Timeout");
96 
97  if (!Global::hyperspace->wait_for_connection(hyperspace_timeout)) {
98  HT_ERROR("Unable to connect to hyperspace, exiting...");
99  quick_exit(EXIT_FAILURE);
100  }
101 
102  // Initialize cluster ID from Hyperspace, enabling ClusterId::get()
103  ClusterId cluster_id(Global::hyperspace);
104 
105  Apps::RangeServerPtr range_server
106  = std::make_shared<Apps::RangeServer>(properties, conn_manager,
108 
109  Global::app_queue->join();
110 
112 
113  range_server = 0;
114 
115  if (has("pidfile"))
116  FileUtils::unlink(get_str("pidfile"));
117 
118  HT_ERROR("Exiting RangeServer.");
119  }
120  catch (Exception &e) {
121  HT_ERROR_OUT << e << HT_END;
122  quick_exit(EXIT_FAILURE);
123  }
124  quick_exit(EXIT_SUCCESS);
125 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
Retrieves system information (hardware, installation directory, etc)
Meta::list< AppPolicy, FsBrokerPolicy, DefaultCommPolicy > Policies
Definition: main.cc:69
The FailureInducer simulates errors.
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
static bool unlink(const String &fname)
Unlinks (deletes) a file or directory.
Definition: FileUtils.cc:427
static ConnectionManagerPtr conn_manager
Definition: Global.h:113
Helper class for printing usage banners on the command line.
Declarations for ReactorRunner.
static bool exists(const String &fname)
Checks if a file or directory exists.
Definition: FileUtils.cc:420
STL namespace.
static FailureInducer * instance
This is a singleton class.
Declarations for RangeServer.
static void close()
Cleanup function; called before leaving main()
int main(int argc, char **argv)
Definition: main.cc:71
Provides access to the cluster ID.
Definition: ClusterId.h:45
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
static bool record_arrival_time
If set to true arrival time is recorded and passed into IOHandler::handle.
Definition: ReactorRunner.h:67
static Hyperspace::SessionPtr hyperspace
Definition: Global.h:63
Helpers to compose init policies; allow to combine two policies into one.
Definition: Config.h:174
Logging routines and macros.
Compatibility Macros for C/C++.
void parse_option(String spec)
Parses a spec string (as explained above) and stores it in an internal structure. ...
Initialization helper for applications.
#define HT_END
Definition: Logger.h:220
Declarations for IndexUpdater.
#define HT_ERROR_OUT
Definition: Logger.h:301
static bool verbose
Definition: Global.h:74
Hypertable definitions
#define HT_FATALF(msg,...)
Definition: Logger.h:343
Entry point to AsyncComm service.
Definition: Comm.h:61
#define HT_ERROR(msg)
Definition: Logger.h:299
Declarations for ConnectionManager.
Declarations for Comm.
Internet address wrapper classes and utility functions.
Declarations for ReactorFactory.
static String install_dir
The installation directory.
Definition: System.h:114
This is a generic exception class for Hypertable.
Definition: Error.h:314
std::shared_ptr< RangeServer > RangeServerPtr
Shared smart pointer to RangeServer.
Definition: RangeServer.h:355
Declarations for ApplicationQueue.
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
static Hypertable::ApplicationQueuePtr app_queue
Definition: Global.h:66
Declarations for ClusterId.