0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetaLog.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 
27 #include <Common/Compat.h>
28 
29 #include "MetaLog.h"
30 
31 #include <Common/Filesystem.h>
32 #include <Common/Serialization.h>
33 
34 #include <algorithm>
35 #include <cctype>
36 
37 using namespace Hypertable;
38 using namespace Hypertable::MetaLog;
39 
40 void Header::encode(uint8_t **bufp) const {
42  memcpy(*bufp, name, 14);
43  *bufp += 14;
44 }
45 
46 void Header::decode(const uint8_t **bufp, size_t *remainp) {
47  HT_ASSERT(*remainp >= LENGTH);
48  version = Serialization::decode_i16(bufp, remainp);
49  memcpy(name, *bufp, 14);
50  *bufp += 14;
51 }
52 
53 
54 void MetaLog::scan_log_directory(FilesystemPtr &fs, const string &path,
55  std::deque<int32_t> &file_ids) {
56  const char *ptr;
57  int32_t id;
58  std::vector<Filesystem::Dirent> listing;
59 
60  if (!fs->exists(path))
61  return;
62 
63  fs->readdir(path, listing);
64 
65  for (size_t i=0; i<listing.size(); i++) {
66 
67  for (ptr=listing[i].name.c_str(); ptr; ++ptr) {
68  if (!isdigit(*ptr))
69  break;
70  }
71 
72  if (*ptr == 0 || (ptr > listing[i].name.c_str() && !strcmp(ptr, ".bad")))
73  id = atoi(listing[i].name.c_str());
74 
75  if (*ptr != 0) {
76  HT_WARNF("Invalid META LOG file name encountered '%s', skipping...",
77  listing[i].name.c_str());
78  continue;
79  }
80 
81  file_ids.push_back(id);
82  }
83 
84  // reverse sort
85  sort(file_ids.begin(), file_ids.end(),
86  [](int32_t lhs, int32_t rhs) { return lhs > rhs; });
87 
88 }
#define HT_WARNF(msg,...)
Definition: Logger.h:290
char name[14]
MetaLog definition name (e.g. "mml" or "rsml")
Definition: MetaLog.h:88
void encode(uint8_t **bufp) const
Encodes MetaLog file header.
Definition: MetaLog.cc:40
Abstract base class for a filesystem.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
void decode(const uint8_t **bufp, size_t *remainp)
Decodes serialized header.
Definition: MetaLog.cc:46
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
Compatibility Macros for C/C++.
void encode_i16(uint8_t **bufp, uint16_t val)
Encode a 16-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
Static header length.
Definition: MetaLog.h:81
void scan_log_directory(FilesystemPtr &fs, const std::string &path, std::deque< int32_t > &file_ids)
Scans MetaLog directory for numeric file names.
Definition: MetaLog.cc:54
Hypertable definitions
uint16_t version
MetaLog definition version number
Definition: MetaLog.h:85
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
Definition: Filesystem.h:572
Declarations for MetaLog.
MetaLog framework.
Definition: MetaLog.h:44