0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OperationRecoveryBlocker.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 
22 #include "Common/Compat.h"
23 #include "Common/Error.h"
24 
25 #include "OperationProcessor.h"
27 #include "OperationTimedBarrier.h"
28 
29 using namespace Hypertable;
30 
32  : OperationEphemeral(context, MetaLog::EntityType::OPERATION_RECOVERY_BLOCKER) {
34 }
35 
37 
38  HT_INFOF("Entering RecoveryBlocker-%lld", (Lld)header.id);
39 
40  size_t total_servers = m_context->rsc_manager->server_count();
41  size_t connected_servers = m_context->available_server_count();
42  size_t failover_pct
43  = m_context->props->get_i32("Hypertable.Failover.Quorum.Percentage");
44  size_t quorum = ((total_servers * failover_pct) + 99) / 100;
45 
46  HT_INFOF("total_servers=%d connected_servers=%d quorum=%d",
47  (int)total_servers, (int)connected_servers, (int)quorum);
48 
49  if (connected_servers < quorum || connected_servers == 0) {
50  block();
51  HT_INFOF("Only %d servers ready, total servers=%d quorum=%d,"
52  " waiting for servers ...", (int)connected_servers,
53  (int)total_servers, (int)quorum);
54  HT_INFOF("Leaving RecoveryBlocker-%lld state=%s-BLOCKED", (Lld)header.id,
56  return;
57  }
58 
67  if (!m_context->quorum_reached) {
68  uint32_t millis = 2 * m_context->props->get_i32("Hypertable.Failover.GracePeriod");
69  m_context->recovery_barrier_op->advance_into_future(millis);
70  OperationPtr operation(m_context->recovery_barrier_op);
71  m_context->op->add_operation(operation);
72  m_context->quorum_reached = true;
73  }
74 
76 
77  HT_INFOF("Leaving RecoveryBlocker-%lld state=%s", (Lld)header.id,
79 }
80 
82  return "OperationRecoveryBlocker";
83 }
84 
86  return "RecoveryBlocker";
87 }
88 
virtual const String label()
Human readable label for operation.
ContextPtr m_context
Pointer to Master context.
Definition: Operation.h:553
Abstract base class for ephemeral operations.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
int64_t id
Unique ID of entity.
Declarations for OperationProcessor.
EntityHeader header
Entity header
const char * get_text(int32_t state)
Definition: Operation.cc:609
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
void set_state(int32_t state)
Definition: Operation.h:473
Compatibility Macros for C/C++.
virtual const String name()
Name of operation used for exclusivity.
virtual void execute()
Executes (carries out) the operation.
const char * RECOVERY_BLOCKER
Definition: Operation.cc:52
Hypertable definitions
long long int Lld
Shortcut for printf formats.
Definition: String.h:53
DependencySet m_obstructions
Set of obstructions.
Definition: Operation.h:598
#define HT_INFOF(msg,...)
Definition: Logger.h:272
std::shared_ptr< Operation > OperationPtr
Smart pointer to Operation.
Definition: Operation.h:609
Error codes, Exception handling, error logging.