43 #include <boost/tokenizer.hpp>
45 #define HINTS_FILE_VERSION 3
64 char md5DigestStr[33];
72 const char *ag_hint_format =
" %s: {\n"
73 " LatestStoredRevision: %lld,\n"
80 bool first_try =
true;
90 format(
"Version: %d\nStart Row: %s\nEnd Row: %s\nLocation: %s\n"
94 contents +=
format(ag_hint_format, h.ag_name.c_str(),
95 (
Llu)h.latest_stored_revision,
96 (
Lld)h.disk_usage, h.files.c_str());
111 memcpy(sbuf.base, contents.c_str(), contents.length());
116 HT_INFOF(
"Exception caught writing hints file %s/hints - %s",
122 HT_ERRORF(
"Problem writing hints file %s/hints - %s",
148 dbuf.
base[nread] = 0;
152 const char *ptr = base;
155 while ((ptr = strchr(base,
':')) != 0) {
161 while (*base && isspace(*base))
165 ptr = strchr(base,
'}');
170 boost::char_separator<char> sep(
",");
171 boost::tokenizer< boost::char_separator<char> > tokens(text, sep);
172 for (
const auto &mapping : tokens) {
174 const char *ptr2 = strchr(mapping.c_str(),
':');
179 String value =
String(mapping, (ptr2-mapping.c_str())+1);
183 if (key ==
"LatestStoredRevision") {
185 if (value.empty() || *end != 0)
188 else if (key ==
"DiskUsage") {
189 h.
disk_usage = strtoull(value.c_str(), &end, 0);
190 if (value.empty() || *end != 0)
193 else if (key ==
"Files")
196 HT_WARNF(
"Unrecognized key (%s) in hints file %s",
197 key.c_str(), filename.c_str());
209 HT_ERRORF(
"Problem loading hints file %s - %s", filename.c_str(),
223 path.append(
"/hints");
230 const char *parse_key_value(
const char *base,
String &key,
231 const char **value,
size_t *value_len) {
234 if ((ptr = strchr(base,
':')) == 0)
237 key =
String((
const char *)base, ptr-base);
239 if (key.empty() || ptr[1] !=
' ')
243 while (*ptr && *ptr !=
'\n')
247 *value_len = ptr - *value;
254 const char *base = input;
259 base = parse_key_value(base, key, &value, &value_len);
262 if (key !=
"Version") {
267 int version = atoi(value);
270 "Unrecognized hints file version (%d)", version);
272 base = parse_key_value(base, key, &value, &value_len);
273 if (key !=
"Start Row")
275 "Unexpected key in hints file (%s)", key.c_str());
277 base = parse_key_value(base, key, &value, &value_len);
278 if (key !=
"End Row")
280 "Unexpected key in hints file (%s)", key.c_str());
283 base = parse_key_value(base, key, &value, &value_len);
284 if (key !=
"Location")
286 "Unexpected key in hints file (%s)", key.c_str());
289 base = parse_key_value(base, key, &value, &value_len);
290 if (key !=
"Access Groups")
292 "Unexpected key in hints file (%s)", key.c_str());
A memory buffer of static size.
void change_end_row(const String &end_row)
Changes the end row.
String m_start_row
Start row.
#define HT_WARNF(msg,...)
void parse_header(const char *input, const char **ag_base)
Parses header portion of hints file.
AccessGroupHintsFile(const String &table, const String &start_row, const String &end_row)
Constructor.
std::string String
A String is simply a typedef to std::string.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
long long unsigned int Llu
Shortcut for printf formats.
void change_start_row(const String &start_row)
Changes the start row.
bool escape(const char *in_buf, size_t in_len, const char **out_bufp, size_t *out_lenp)
A dynamic, resizable and reference counted memory buffer.
int64_t latest_stored_revision
void md5_trunc_modified_base64(const char *input, char output[17])
Get the modified base64 encoded string of the first 12 Bytes of the 16 Byte MD5 code of a null termin...
A dynamic, resizable memory buffer.
void read()
Reads hints file.
static std::string toplevel_dir
const char * get_text(int error)
Returns a descriptive error message.
void grow(size_t new_size, bool nocopy=false)
Grows the buffer and copies the data unless nocopy is true.
Logging routines and macros.
bool exists()
Checks if hints file exists.
Compatibility Macros for C/C++.
Declarations for AccessGroupHintsFile.
std::vector< AccessGroup::Hints > m_hints
Vector of access group hints.
static Hypertable::FilesystemPtr dfs
A memory buffer of static size.
long long int Lld
Shortcut for printf formats.
void write(String location)
Write hints file.
#define HT_INFOF(msg,...)
#define HT_THROWF(_code_, _fmt_,...)
uint8_t * base
Pointer to the allocated memory buffer.
This is a generic exception class for Hypertable.
A String class based on std::string.
#define HT_ERRORF(msg,...)
#define HINTS_FILE_VERSION
String m_table_id
Table ID string
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
String m_range_dir
Range subdirectory (md5 of end row)
int code() const
Returns the error code.