0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeServerHyperspaceCallback.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 
28 #ifndef Hypertable_Master_RangeServerHyperspaceCallback_h
29 #define Hypertable_Master_RangeServerHyperspaceCallback_h
30 
31 #include "Context.h"
32 #include "OperationProcessor.h"
33 #include "OperationRecover.h"
34 #include "OperationTimedBarrier.h"
36 #include "RangeServerConnection.h"
37 
38 #include "Hyperspace/Session.h"
39 
40 #include <chrono>
41 #include <condition_variable>
42 #include <mutex>
43 
44 namespace Hypertable {
45 
58  public:
59 
69  m_context(context), m_rsc(rsc), m_lock_held(false) { }
70 
85  virtual void lock_released() {
86  HT_INFOF("%s hyperspace lock file released", m_rsc->location().c_str());
87  {
88  std::lock_guard<std::mutex> lock(m_mutex);
89  m_lock_held = false;
90  m_context->remove_available_server(m_rsc->location());
91  m_cond.notify_all();
92  }
93  if (m_rsc->connected()) {
94  uint32_t millis = m_context->props->get_i32("Hypertable.Failover.GracePeriod");
95  m_context->recovery_barrier_op->advance_into_future(millis);
96  OperationPtr operation = std::make_shared<OperationRecover>(m_context, m_rsc);
97  try {
98  m_context->op->add_operation(operation);
99  }
100  catch (Exception &e) {
101  HT_INFOF("%s - %s", Error::get_text(e.code()), e.what());
102  }
103  }
104  m_context->op->unblock(String("RegisterServerBlocker ") + m_rsc->location());
105  }
106 
113  virtual void lock_acquired(uint32_t mode) {
114  std::lock_guard<std::mutex> lock(m_mutex);
115  HT_INFOF("%s hyperspace lock file acquired", m_rsc->location().c_str());
116  m_lock_held = true;
117  m_cond.notify_all();
118  }
119 
127  bool wait_for_lock_acquisition(std::chrono::milliseconds max_wait) {
128  std::unique_lock<std::mutex> lock(m_mutex);
129  return m_cond.wait_for(lock, max_wait, [this](){ return m_lock_held; });
130  }
131 
132  private:
133 
136 
138  std::condition_variable m_cond;
139 
142 
145 
148  };
149 
151 }
152 
153 #endif // Hypertable_Master_RangeServerHyperspaceCallback_h
RangeServerConnectionPtr m_rsc
Range server connection
static std::mutex mutex
Definition: Logger.cc:43
std::shared_ptr< RangeServerConnection > RangeServerConnectionPtr
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Declarations for OperationProcessor.
bool m_lock_held
Flag indicating if lock is currently held.
virtual void lock_released()
Responds to lock release event.
virtual void lock_acquired(uint32_t mode)
Responds to lock acquired event.
bool wait_for_lock_acquisition(std::chrono::milliseconds max_wait)
Waits for m_lock_held to become true.
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
Hyperspace definitions
Callback class for range server lock files.
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
std::mutex m_mutex
Mutex for serializing concurrent access
Declarations for OperationRegisterServerBlocker.
Hypertable definitions
#define HT_INFOF(msg,...)
Definition: Logger.h:272
This is a generic exception class for Hypertable.
Definition: Error.h:314
RangeServerHyperspaceCallback(ContextPtr &context, RangeServerConnectionPtr &rsc)
Constructor.
std::condition_variable m_cond
Condition variable used to wait for completion.
std::shared_ptr< Operation > OperationPtr
Smart pointer to Operation.
Definition: Operation.h:609
Declarations for Context.
int code() const
Returns the error code.
Definition: Error.h:391