0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeLocator.h
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 
22 #ifndef Hypertable_Lib_RangeLocator_h
23 #define Hypertable_Lib_RangeLocator_h
24 
25 #include <Hypertable/Lib/Key.h>
30 #include <Hypertable/Lib/Schema.h>
32 
33 #include <Hyperspace/Session.h>
34 
36 
37 #include <Common/Error.h>
38 #include <Common/Timer.h>
39 #include <Common/Properties.h>
40 
41 #include <deque>
42 #include <memory>
43 #include <mutex>
44 #include <vector>
45 
46 namespace Hypertable {
47 
48  class RangeLocator;
50  public:
53  void safe() {}
54  void expired() {}
55  void jeopardy() {}
56  void disconnected();
57  void reconnected();
58 
59  private:
60  friend class RangeLocator;
62  };
63 
67  class RangeLocator {
68 
69  public:
70 
81  Hyperspace::SessionPtr &hyperspace, uint32_t timeout_ms);
82 
84  ~RangeLocator();
85 
94  void find_loop(const TableIdentifier *table, const char *row_key,
95  RangeLocationInfo *range_loc_infop, Timer &timer, bool hard);
96 
106  int find(const TableIdentifier *table, const char *row_key,
107  RangeLocationInfo *range_loc_infop, Timer &timer, bool hard);
108 
116  bool invalidate(const TableIdentifier *table, const char *row_key) {
117  if (table->is_metadata() && (row_key == 0 || strcmp(row_key, Key::END_ROOT_ROW) <= 0))
118  m_root_stale = true;
119  return m_cache->invalidate(table->id, row_key);
120  }
121 
122  void invalidate_host(const std::string &hostname) {
123  std::lock_guard<std::mutex> lock(m_mutex);
124  CommAddress addr;
125  addr.set_proxy(hostname);
126  if (addr == m_root_range_info.addr)
127  m_root_stale = true;
128  m_cache->invalidate_host(hostname);
129  }
130 
134  void set_root_stale() { m_root_stale=true; }
135 
140  return m_cache;
141  }
142 
147  std::lock_guard<std::mutex> lock(m_mutex);
148  m_last_errors.clear();
149  }
150 
155  std::lock_guard<std::mutex> lock(m_mutex);
156  for (auto &e : m_last_errors)
157  HT_ERROR_OUT << e << HT_END;
158  m_last_errors.clear();
159  }
160 
161  private:
163 
164  void initialize(Timer &timer);
166  void hyperspace_reconnected();
167  int process_metadata_scanblocks(std::vector<ScanBlock> &scan_blocks, Timer &timer);
168  int read_root_location(Timer &timer);
169  void initialize();
170  int connect(CommAddress &addr, Timer &timer);
171 
181  uint8_t m_startrow_cid;
182  uint8_t m_location_cid;
184  std::deque<Exception> m_last_errors;
188  uint32_t m_timeout_ms;
190  std::string m_toplevel_dir;
195  };
196 
198  typedef std::shared_ptr<RangeLocator> RangeLocatorPtr;
199 
200 }
201 
202 #endif // Hypertable_Lib_RangeLocator_h
RangeLocationInfo m_root_range_info
Definition: RangeLocator.h:179
static std::mutex mutex
Definition: Logger.cc:43
LocationCachePtr m_cache
Definition: RangeLocator.h:175
int process_metadata_scanblocks(std::vector< ScanBlock > &scan_blocks, Timer &timer)
A callback object derived from this class gets passed into the constructor of Hyperspace.
Definition: Session.h:94
uint32_t m_metadata_retry_interval
Definition: RangeLocator.h:193
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
Declarations for TableIdentifier and TableIdentifierManaged.
int connect(CommAddress &addr, Timer &timer)
Program options handling.
Holds range start and end row plus location.
void dump_error_history()
Displays the error history.
Definition: RangeLocator.h:154
bool invalidate(const TableIdentifier *table, const char *row_key)
Invalidates the cached entry for the given row key.
Definition: RangeLocator.h:116
Declarations for RangeServerClient.
std::shared_ptr< LocationCache > LocationCachePtr
Smart pointer to LocationCache.
Declarations for Schema.
Lib::RangeServer::Client m_range_server
Definition: RangeLocator.h:180
LocationCachePtr location_cache()
Returns the location cache.
Definition: RangeLocator.h:139
TableIdentifier m_metadata_table
Definition: RangeLocator.h:183
RangeLocator(PropertiesPtr &cfg, ConnectionManagerPtr &conn_mgr, Hyperspace::SessionPtr &hyperspace, uint32_t timeout_ms)
Constructor.
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
uint32_t m_metadata_readahead_count
Definition: RangeLocator.h:191
void invalidate_host(const std::string &hostname)
Definition: RangeLocator.h:122
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
A timer class to keep timeout states across AsyncComm related calls.
void set_proxy(const String &str)
Sets address type to CommAddress::PROXY and proxy name to p.
Definition: CommAddress.h:76
std::deque< Exception > m_last_errors
Definition: RangeLocator.h:184
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
Hyperspace::HandleCallbackPtr m_root_handler
Definition: RangeLocator.h:177
std::shared_ptr< HandleCallback > HandleCallbackPtr
Hypertable definitions
Hyperspace::SessionPtr m_hyperspace
Definition: RangeLocator.h:174
void initialize()
Assumes access is serialized via m_hyperspace_mutex.
Declarations for ConnectionManager.
int read_root_location(Timer &timer)
Client interface to RangeServer.
Definition: Client.h:63
uint32_t m_root_metadata_retry_interval
Definition: RangeLocator.h:194
Locates containing range given a key.
Definition: RangeLocator.h:67
ConnectionManagerPtr m_conn_manager
Definition: RangeLocator.h:173
int find(const TableIdentifier *table, const char *row_key, RangeLocationInfo *range_loc_infop, Timer &timer, bool hard)
Locates the range that contains the given row key.
A timer class to keep timeout states across AsyncComm related calls.
Definition: Timer.h:44
~RangeLocator()
Destructor.
void set_root_stale()
Sets the "root stale" flag.
Definition: RangeLocator.h:134
Declarations for ScanBlock.
static const char * END_ROOT_ROW
Definition: Key.h:50
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
void find_loop(const TableIdentifier *table, const char *row_key, RangeLocationInfo *range_loc_infop, Timer &timer, bool hard)
Locates the range that contains the given row key.
Error codes, Exception handling, error logging.
void clear_error_history()
Clears the error history.
Definition: RangeLocator.h:146
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52
RangeLocatorHyperspaceSessionCallback m_hyperspace_session_callback
Definition: RangeLocator.h:189