0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HyperspaceMasterFile.cc
Go to the documentation of this file.
1 /* -*- c++ -*-
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 
26 
27 #include <Common/Compat.h>
28 
29 #include "HyperspaceMasterFile.h"
30 
31 #include <Common/Logger.h>
32 #include <Common/SystemInfo.h>
33 
34 #include <chrono>
35 
36 using namespace Hypertable;
37 using namespace Hypertable::Master;
38 using namespace std;
39 
41  unique_lock<mutex> lock(m_mutex);
42  if (m_handle) {
43  m_hyperspace->close_nowait(m_handle);
44  m_handle = 0;
45  }
46 }
47 
55  uint16_t port = m_props->get_i16("Hypertable.Master.Port");
56  InetAddr addr(System::net_info().primary_addr, port);
57  String addr_s = addr.format();
58  m_hyperspace->attr_set(m_handle, "address", addr_s.c_str(), addr_s.length());
59  HT_INFO("Successfully wrote master address to Hyperspace.");
60 }
61 
66  HT_ASSERT(m_handle);
67  return m_hyperspace->attr_incr(m_handle, "next_server_id");
68 }
69 
71  {
72  unique_lock<mutex> lock(m_mutex);
73  m_shutdown = true;
74  }
75  m_cond.notify_all();
76 }
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
#define HT_INFO(msg)
Definition: Logger.h:271
STL namespace.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Encapsulate an internet address.
Definition: InetAddr.h:66
Logging routines and macros.
Compatibility Macros for C/C++.
Declarations for HyperspaceMasterFile.
String format(int sep= ':') const
Returns a string with a dotted notation ("127.0.0.1:8080") including the port.
Definition: InetAddr.h:132
Hypertable definitions
uint64_t next_server_id()
Obtains next server ID.
void write_master_address()
Writes Master's listen address to Hyperspace.
void lock(ResponseCallbackLock *cb, uint64_t session_id, uint64_t handle, uint32_t mode, bool try_lock)
Definition: Master.cc:1203
System information and statistics based on libsigar.
static const NetInfo & net_info()
Retrieves updated Network information (see SystemInfo.h)
Definition: SystemInfo.cc:360