0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
HyperspaceTableCache.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 
28 #include "Common/Compat.h"
29 
30 #include "Global.h"
31 #include "HyperspaceTableCache.h"
32 
33 #include <vector>
34 
35 using namespace Hypertable;
36 
38  const String &toplevel_dir) {
39 
40  try {
41  std::vector<Hyperspace::DirEntryAttr> listing;
42  hyperspace->readdir_attr(toplevel_dir + "/tables", "schema", true, listing);
43  map_table_schemas("", listing);
44  listing.clear();
45  hyperspace->readdir_attr(toplevel_dir + "/tables", "maintenance_disabled", true, listing);
46  map_maintenance_disabled("", listing);
47  }
48  catch (Exception &e) {
49  HT_FATAL_OUT << "Problem loading table schemas " << e << HT_END;
50  }
51 }
52 
53 bool HyperspaceTableCache::get(const String &table_id, Entry &entry) {
54  auto iter = m_map.find(table_id);
55  if (iter == m_map.end())
56  return false;
57  entry = iter->second;
58  return true;
59 }
60 
61 
63  const std::vector<Hyperspace::DirEntryAttr> &listing) {
64  String prefix = !parent.empty() ? parent + "/" : ""; // avoid leading slash
65  for (auto &e : listing) {
66  String name = prefix + e.name;
67  if (e.has_attr) {
68  Entry entry;
69  entry.schema.reset( Schema::new_instance((const char *)e.attr.base) );
70  m_map.insert(TableEntryMap::value_type(name, entry));
71  }
72  map_table_schemas(name, e.sub_entries);
73  }
74 }
75 
76 void
78  const std::vector<Hyperspace::DirEntryAttr> &listing) {
79  String prefix = !parent.empty() ? parent + "/" : ""; // avoid leading slash
80  for (auto &e : listing) {
81  String name = prefix + e.name;
82  auto iter = m_map.find(name);
83  if (e.has_attr && iter != m_map.end())
84  iter->second.maintenance_disabled = true;
85  map_maintenance_disabled(name, e.sub_entries);
86  }
87 }
88 
bool get(const String &table_id, Entry &entry)
Returns Hyperspace cache entry for a table.
Cache entry for Hyperspace table data.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
HyperspaceTableCache(Hyperspace::SessionPtr &hyperspace, const String &toplevel_dir)
Constructor.
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
Compatibility Macros for C/C++.
Declarations for HyperspaceTableCache.
#define HT_END
Definition: Logger.h:220
Hypertable definitions
static Schema * new_instance(const std::string &buf)
Creates schema object from XML schema string.
Definition: Schema.cc:202
void map_maintenance_disabled(const String &parent, const std::vector< Hyperspace::DirEntryAttr > &listing)
Recursively updates maintenance_disabled field in map entries.
void map_table_schemas(const String &parent, const std::vector< Hyperspace::DirEntryAttr > &listing)
Recursively populates map with table schemas.
SchemaPtr schema
Smart pointer to Schema object.
This is a generic exception class for Hypertable.
Definition: Error.h:314
TableEntryMap m_map
Table ID to Entry map
#define HT_FATAL_OUT
Definition: Logger.h:347