26 #include <boost/algorithm/string.hpp>
36 m_tables_dir = context->props->get_str(
"Hypertable.Directory");
49 HT_ERRORF(
"Error: caught exception while gc'ing: %s", e.what());
58 scan_spec.
columns.push_back(
"Files");
67 int64_t last_time = 0;
68 bool found_valid_files =
true;
70 HT_DEBUG(
"MasterGc: scanning metadata...");
72 while (scanner->next(cell)) {
73 if (strcmp(
"Files", cell.column_family)) {
74 HT_ERRORF(
"Unexpected column family '%s', while scanning METADATA",
78 if (last_row != cell.row_key) {
80 if (!found_valid_files)
83 last_row = cell.row_key;
84 last_cq = cell.column_qualifier;
85 last_time = cell.timestamp;
86 found_valid_files = *cell.value !=
'!';
88 if (found_valid_files)
89 insert_files(files_map, (
char *)cell.value, cell.value_len, 1);
91 else if (last_cq != cell.column_qualifier) {
93 last_cq = cell.column_qualifier;
94 last_time = cell.timestamp;
95 bool is_valid_files = (cell.value_len == 0) || (*cell.value !=
'!');
96 found_valid_files |= is_valid_files;
99 insert_files(files_map, (
char *)cell.value, cell.value_len, 1);
103 if (cell.timestamp > last_time) {
104 HT_ERROR(
"Unexpected timestamp order while scanning METADATA");
107 if (cell.value_len == 0 || *cell.value !=
'!') {
108 insert_files(files_map, (
char *)cell.value, cell.value_len);
114 if (!found_valid_files)
126 key.
row = row.c_str();
130 HT_DEBUGF(
"MasterGc: Deleting row %s", (
char *)key.
row);
132 mutator->set_delete(key);
142 mutator->set_delete(key);
147 const char *p = buf, *pn = p, *endp = p + len - 1;
150 while (p < endp && (*p !=
';' || p[1] !=
'\n'))
156 string name(pn, p - pn);
170 (*ret.first).second += c;
179 size_t nf = 0, nf_done = 0, nd = 0, nd_done = 0;
181 for (
const auto &v : files_map) {
183 HT_INFOF(
"MasterGc: removing file %s", v.first);
195 HT_DEBUGF(
"MasterGc: removed %lu/%lu files; %lu/%lu directories",
196 (
Lu)nf_done, (
Lu)nf, (
Lu)nd_done, (
Lu)nd);
void delete_cell(const Cell &cell, TableMutatorPtr &mutator)
#define HT_WARNF(msg,...)
static const uint32_t FLAG_DELETE_ROW
std::string String
A String is simply a typedef to std::string.
std::pair< iterator, bool > InsRet
A hash map for storing and lookup char * strings efficiently.
const char * column_qualifier
static const uint32_t FLAG_DELETE_CELL
GcWorker(ContextPtr &context)
std::shared_ptr< TableScanner > TableScannerPtr
Smart pointer to TableScanner.
void reap(CountMap &files_map)
Currently only stale cs files and range directories are reaped Table directories probably should be o...
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Scan predicate and control specification.
std::shared_ptr< TableMutator > TableMutatorPtr
Smart pointer to TableMutator.
Compatibility Macros for C/C++.
InsRet insert(const char *key, const DataT &data)
Inserts a new string/data pair in the map.
#define HT_DEBUGF(msg,...)
const char * column_family
#define HT_INFOF(msg,...)
void scan_metadata(CountMap &files_map)
This is a generic exception class for Hypertable.
long unsigned int Lu
Shortcut for printf formats.
#define HT_ERRORF(msg,...)
void delete_row(const std::string &row, TableMutatorPtr &mutator)
Encapsulates decomposed key and value.
void insert_files(CountMap &map, const char *buf, size_t len, int c=0)
void insert_file(CountMap &map, const char *fname, int c)