0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OperationRelinquishAcknowledge.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; 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 
24 #include "OperationMoveRange.h"
25 #include "OperationProcessor.h"
27 #include "ReferenceManager.h"
28 #include "Utility.h"
29 
30 #include <Common/Error.h>
31 #include <Common/FailureInducer.h>
32 #include <Common/ScopeGuard.h>
33 #include <Common/Serialization.h>
34 #include <Common/StringExt.h>
35 #include <Common/System.h>
36 #include <Common/md5.h>
37 
38 using namespace Hypertable;
39 
42  int64_t range_id, TableIdentifier &table,
43  RangeSpec &range)
44  : OperationEphemeral(ctx, MetaLog::EntityType::OPERATION_RELINQUISH_ACKNOWLEDGE),
45  m_params(source, range_id, table, range) {
46 }
47 
49  : OperationEphemeral(context, event,
50  MetaLog::EntityType::OPERATION_RELINQUISH_ACKNOWLEDGE) {
51  const uint8_t *ptr = event->payload;
52  size_t remaining = event->payload_len;
53  m_params.decode(&ptr, &remaining);
55 }
56 
58 
59  HT_INFOF("Entering RelinquishAcknowledge-%lld %s[%s..%s] (id=%lld) "
60  "source=%s state=%s", (Lld)header.id, m_params.table().id,
62  (Lld)m_params.range_id(), m_params.source().c_str(),
63  OperationState::get_text(m_state));
64 
65  HT_MAYBE_FAIL("relinquish-acknowledge-INITIAL-a");
66  HT_MAYBE_FAIL("relinquish-acknowledge-INITIAL-b");
67 
68  int64_t hash_code =
71 
72  OperationPtr operation = m_context->get_move_operation(hash_code);
73  if (operation) {
74  if (operation->remove_approval_add(0x01)) {
75  operation->record_state();
76  m_context->remove_move_operation(operation);
77  }
78  }
79  else
80  HT_WARNF("Skipping relinquish_acknowledge(%s %s[%s..%s] "
81  "because correspoing MoveRange does not exist",
82  m_params.source().c_str(), m_params.table().id,
84 
85  complete_ok();
86 
87  HT_INFOF("Leaving RelinquishAcknowledge-%lld %s[%s..%s] (id=%lld) "
88  "from %s (state=%s)", (Lld)header.id, m_params.table().id,
90  (Lld)m_params.range_id(), m_params.source().c_str(),
91  OperationState::get_text(m_state));
92 }
93 
95  os << " " << m_params.table() << " " << m_params.range_spec()
96  << " source=" << m_params.source();
97 }
98 
100  return "OperationRelinquishAcknowledge";
101 }
102 
104  return format("RelinquishAcknowledge %s[%s..%s]", m_params.table().id,
106 }
107 
109  String start_row = m_params.range_spec().start_row;
110  String end_row = m_params.range_spec().end_row;
111 
112  if (start_row.length() > 20)
113  start_row = start_row.substr(0, 10) + ".." +
114  start_row.substr(start_row.length()-10, 10);
115 
116  if (end_row.length() > 20)
117  end_row = end_row.substr(0, 10) + ".." +
118  end_row.substr(end_row.length()-10, 10);
119 
120  return format("RelinquishAcknowledge %s\\n%s\\n%s",
121  m_params.table().id, start_row.c_str(), end_row.c_str());
122 }
Retrieves system information (hardware, installation directory, etc)
virtual void execute()
Executes (carries out) the operation.
#define HT_WARNF(msg,...)
Definition: Logger.h:290
The FailureInducer simulates errors.
ContextPtr m_context
Pointer to Master context.
Definition: Operation.h:553
Range specification.
Definition: RangeSpec.h:40
Abstract base class for ephemeral operations.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
int64_t id
Unique ID of entity.
Declarations for OperationProcessor.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
virtual int64_t hash_code() const
Definition: Operation.h:455
Lib::Master::Request::Parameters::RelinquishAcknowledge m_params
Request parmaeters.
EntityHeader header
Entity header
const char * get_text(int32_t state)
Definition: Operation.cc:609
Declarations for ReferenceManager.
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
const string & source() const
Gets name of source RangeServer.
const char * end_row
Definition: RangeSpec.h:60
virtual const String name()
Name of operation used for exclusivity.
const char * INIT
Definition: Operation.cc:45
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
virtual void display_state(std::ostream &os)
Write human readable operation state to output stream.
Hypertable definitions
long long int Lld
Shortcut for printf formats.
Definition: String.h:53
int64_t range_id() const
Gets range MetaLog entry identifier.
Declarations for general-purpose utility functions.
const char * start_row
Definition: RangeSpec.h:59
DependencySet m_dependencies
Set of dependencies.
Definition: Operation.h:595
#define HT_INFOF(msg,...)
Definition: Logger.h:272
OperationRelinquishAcknowledge(ContextPtr &context, EventPtr &event)
virtual const String label()
Human readable label for operation.
#define HT_MAYBE_FAIL(_label_)
void complete_ok(std::vector< MetaLog::EntityPtr > &additional)
Definition: Operation.cc:436
std::shared_ptr< Operation > OperationPtr
Smart pointer to Operation.
Definition: Operation.h:609
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
md5 digest routines.
virtual const String graphviz_label()
Human readable operation label used in graphviz output.
Executes user-defined functions when leaving the current scope.