0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetaLogEntityRemoveOkLogs.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 
29 #include <Common/Compat.h>
30 
32 
33 #include <Common/Serialization.h>
34 
35 #include <boost/algorithm/string/predicate.hpp>
36 
37 using namespace Hypertable;
38 using namespace Hypertable::MetaLog;
39 using namespace std;
40 
42  : Entity(header_) {
43 }
44 
46  : Entity(EntityType::REMOVE_OK_LOGS) {
47  m_log_set = logs;
48 }
49 
51  : Entity(EntityType::REMOVE_OK_LOGS) {
52 }
53 
55  lock_guard<mutex> lock(m_mutex);
56  HT_ASSERT(!boost::ends_with(pathname, "/"));
57  m_log_set.insert(pathname);
58 }
59 
61  lock_guard<mutex> lock(m_mutex);
62  m_log_set.insert(logs.begin(), logs.end());
63 }
64 
66  lock_guard<mutex> lock(m_mutex);
67  for (const auto &path : logs)
68  m_log_set.erase(path);
69 }
70 
72  lock_guard<mutex> lock(m_mutex);
73  logs = m_log_set;
74 }
75 
76 void MetaLogEntityRemoveOkLogs::decode(const uint8_t **bufp, size_t *remainp,
77  uint16_t definition_version) {
78  if (definition_version < 3)
79  decode_old(bufp, remainp);
80  else
81  Entity::decode(bufp, remainp);
82 }
83 
85  return 1;
86 }
87 
89  size_t length = 4;
90  for (const auto &pathname : m_log_set)
91  length += Serialization::encoded_length_vstr(pathname);
92  return length;
93 }
94 
95 void MetaLogEntityRemoveOkLogs::encode_internal(uint8_t **bufp) const {
97  for (const auto &pathname : m_log_set)
98  Serialization::encode_vstr(bufp, pathname);
99 }
100 
101 void MetaLogEntityRemoveOkLogs::decode_internal(uint8_t version, const uint8_t **bufp,
102  size_t *remainp) {
103  int32_t count = Serialization::decode_i32(bufp, remainp);
104  for (int32_t i=0; i<count; i++)
105  m_log_set.insert(Serialization::decode_vstr(bufp, remainp));
106  m_decode_version = 2;
107 }
108 
109 void MetaLogEntityRemoveOkLogs::decode_old(const uint8_t **bufp, size_t *remainp) {
110  uint32_t val = (uint32_t)Serialization::decode_i32(bufp, remainp);
111  uint32_t count;
112  if (val == 123456789LL) {
113  m_decode_version = (uint32_t)Serialization::decode_i32(bufp, remainp);
114  count = (uint32_t)Serialization::decode_i32(bufp, remainp);
115  }
116  else {
117  m_decode_version = 1;
118  count = val;
119  }
120  for (uint32_t i=0; i<count; i++)
121  m_log_set.insert(Serialization::decode_vstr(bufp, remainp));
122 }
123 
124 
126  return "RemoveOkLogs";
127 }
128 
129 void MetaLogEntityRemoveOkLogs::display(std::ostream &os) {
130  lock_guard<mutex> lock(m_mutex);
131  bool first = true;
132  for (const auto &pathname : m_log_set) {
133  os << (first ? " " : ", ") << pathname;
134  first = false;
135  }
136 }
137 
std::set< String > StringSet
STL Set managing Strings.
Definition: StringExt.h:42
void insert(const String &pathname)
Inserts a log into the remove ok set.
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
size_t encoded_length_internal() const override
Returns internal serialized length.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
void remove(StringSet &logs)
Removes logs from the remove ok set.
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
const String name() override
Returns the entity name ("Range")
std::mutex m_mutex
Mutex for serializing access to members
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
void get(StringSet &logs)
Gets logs in the remove ok set.
Declarations for MetaLogEntityRemoveOkLogs.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Base class for MetaLog entities.
Definition: MetaLogEntity.h:62
StringSet m_log_set
Set of log pathnames that can be safely removed.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void decode_old(const uint8_t **bufp, size_t *remainp)
Functions to serialize/deserialize primitives to/from a memory buffer.
uint32_t m_decode_version
Version of serialized entity decoded.
void lock()
Locks the entity's mutex.
Definition: MetaLogEntity.h:97
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
uint8_t encoding_version() const override
Returns encoding version.
void decode(const uint8_t **bufp, size_t *remainp, uint16_t definition_version) override
Reads serialized encoding of the entity.
void display(std::ostream &os) override
Writes a human readable representation of the object state to an output stream.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
MetaLog framework.
Definition: MetaLog.h:44