0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LogReplayBarrier.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; either version 3
9  * of the 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 #include "LogReplayBarrier.h"
24 
25 #include <Hypertable/Lib/Key.h>
26 
27 using namespace Hypertable;
28 using namespace std;
29 
31  lock_guard<mutex> lock(m_mutex);
32  m_root_complete = true;
33  m_root_complete_cond.notify_all();
34 }
35 
37  lock_guard<mutex> lock(m_mutex);
38  m_metadata_complete = true;
39  m_metadata_complete_cond.notify_all();
40 }
41 
43  lock_guard<mutex> lock(m_mutex);
44  m_system_complete = true;
45  m_system_complete_cond.notify_all();
46 }
47 
49  lock_guard<mutex> lock(m_mutex);
50  m_user_complete = true;
51  m_user_complete_cond.notify_all();
52 }
53 
55  if (m_root_complete)
56  return true;
57  unique_lock<mutex> lock(m_mutex);
58  HT_INFO("Waiting for ROOT recovery to complete...");
59  return m_root_complete_cond.wait_until(lock, deadline,
60  [this](){ return m_root_complete; });
61 }
62 
64  if (m_metadata_complete)
65  return true;
66  unique_lock<mutex> lock(m_mutex);
67  HT_INFO("Waiting for METADATA recovery to complete...");
68  return m_metadata_complete_cond.wait_until(lock, deadline,
69  [this](){ return m_metadata_complete; });
70 }
71 
73  if (m_system_complete)
74  return true;
75  unique_lock<mutex> lock(m_mutex);
76  HT_INFO("Waiting for SYSTEM recovery to complete...");
77  return m_system_complete_cond.wait_until(lock, deadline,
78  [this](){ return m_system_complete; });
79 }
80 
82  if (m_user_complete)
83  return true;
84  unique_lock<mutex> lock(m_mutex);
85  HT_INFO("Waiting for USER recovery to complete...");
86  return m_user_complete_cond.wait_until(lock, deadline,
87  [this](){ return m_user_complete; });
88 }
89 
90 bool
92  const TableIdentifier &table,
93  const RangeSpec &range_spec) {
94  if (m_user_complete)
95  return true;
96  if (table.is_metadata()) {
97  if (!strcmp(range_spec.end_row, Key::END_ROOT_ROW))
98  return wait_for_root(deadline);
99  else
100  return wait_for_metadata(deadline);
101  }
102  else if (table.is_system())
103  return wait_for_system(deadline);
104  return wait_for_user(deadline);
105 }
106 
107 
109  const TableIdentifier &table) {
110  if (m_user_complete)
111  return true;
112  if (table.is_metadata())
113  return wait_for_metadata(deadline);
114  else if (table.is_system())
115  return wait_for_system(deadline);
116  return wait_for_user(deadline);
117 }
118 
120  lock_guard<mutex> lock(m_mutex);
121  return m_user_complete;
122 }
bool wait_for_root(ClockT::time_point deadline)
Waits for ROOT commit log replay to complete.
Declarations for LogReplayBarrier.
Range specification.
Definition: RangeSpec.h:40
chrono::time_point< fast_clock > time_point
Definition: fast_clock.h:42
void set_root_complete()
Signals ROOT commit log replay has been completed.
#define HT_INFO(msg)
Definition: Logger.h:271
STL namespace.
void set_user_complete()
Signals USER commit log replay has been completed.
bool wait_for_user(ClockT::time_point deadline)
Waits for USER commit log replay to complete.
const char * end_row
Definition: RangeSpec.h:60
Compatibility Macros for C/C++.
Hypertable definitions
bool wait_for_system(ClockT::time_point deadline)
Waits for SYSTEM commit log replay to complete.
void set_system_complete()
Signals SYSTEM commit log replay has been completed.
void set_metadata_complete()
Signals METADATA commit log replay has been completed.
static const char * END_ROOT_ROW
Definition: Key.h:50
bool user_complete()
Checks if replay of USER commit log is complete.
bool wait(ClockT::time_point deadline, const TableIdentifier &table, const RangeSpec &range)
Waits for commit log replay to complete for range class defined by a given range. ...
bool wait_for_metadata(ClockT::time_point deadline)
Waits for METADATA commit log replay to complete.