0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LiveFileTracker.h
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 
22 #ifndef Hypertable_RangeServer_LifeFileTracker_h
23 #define Hypertable_RangeServer_LifeFileTracker_h
24 
26 #include <Hypertable/Lib/Schema.h>
28 
29 #include <Common/String.h>
30 
31 #include <mutex>
32 #include <unordered_map>
33 
34 namespace Hypertable {
35 
36  typedef std::unordered_map<String, uint32_t> FileRefCountMap;
37 
43  public:
44 
45  LiveFileTracker(const TableIdentifier *identifier, SchemaPtr &schema_ptr,
46  const RangeSpec *range, const String &ag_name);
47 
51  void change_range(const String &start_row, const String &end_row) {
52  std::lock_guard<std::mutex> lock(m_mutex);
53  m_start_row = start_row;
54  m_end_row = end_row;
55  }
56 
65  void update_live(const String &add, std::vector<String> &deletes, uint32_t nextcsid, int64_t total_blocks);
66 
73  void add_live_noupdate(const String &fname, int64_t total_blocks) {
74  std::lock_guard<std::mutex> lock(m_mutex);
75  m_live.insert(strip_basename(fname));
76  m_total_blocks = total_blocks;
77  }
78 
86  void add_references(const std::vector<String> &filev);
87 
95  void remove_references(const std::vector<String> &filev);
96 
97 
101  void update_files_column();
102 
113  void get_file_data(String &file_list, int64_t *block_countp, bool include_blocked);
114 
118  void get_file_list(String &file_list);
119 
120  void set_next_csid(uint32_t nid) {
122  }
123 
124  private:
125 
126  String strip_basename(const String &fname);
127 
136  FileRefCountMap m_referenced;
137  std::set<String> m_live;
138  std::set<String> m_blocked;
140  bool m_is_root;
141  uint32_t m_last_nextcsid;
142  uint32_t m_cur_nextcsid;
143  int64_t m_total_blocks;
144  };
145 
146 }
147 
148 #endif // Hypertable_RangeServer_LifeFileTracker_h
static std::mutex mutex
Definition: Logger.cc:43
void add_references(const std::vector< String > &filev)
Adds a set of files to the referenced file set.
std::unordered_map< String, uint32_t > FileRefCountMap
Range specification.
Definition: RangeSpec.h:40
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
TableIdentifierManaged m_identifier
void update_live(const String &add, std::vector< String > &deletes, uint32_t nextcsid, int64_t total_blocks)
Updates the live file set.
Declarations for TableIdentifier and TableIdentifierManaged.
LiveFileTracker(const TableIdentifier *identifier, SchemaPtr &schema_ptr, const RangeSpec *range, const String &ag_name)
void add(const Key &key, uint8_t flag, const void *value, uint32_t value_len, TableMutatorAsync *value_index_mutator, TableMutatorAsync *qualifier_index_mutator)
Definition: IndexTables.cc:34
Declarations for Schema.
std::set< String > m_blocked
Wrapper for TableIdentifier providing member storage.
Tracks files that are live or referenced for purposes of maintaining the 'Files' METADATA column...
void get_file_data(String &file_list, int64_t *block_countp, bool include_blocked)
Returns ' ' separated list of files, suitable for writing into the 'Files' column of METADATA...
void set_next_csid(uint32_t nid)
void remove_references(const std::vector< String > &filev)
Decrements the reference count of each file in the given vector.
Declarations for RangeSpec and RangeSpecManaged.
Hypertable definitions
void update_files_column()
Updates the 'Files' METADATA column if it needs updating.
void get_file_list(String &file_list)
Populates string with live files separated by ';'.
String strip_basename(const String &fname)
A String class based on std::string.
void change_range(const String &start_row, const String &end_row)
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
Definition: Schema.h:465
void add_live_noupdate(const String &fname, int64_t total_blocks)
Adds a file to the live file set without seting the 'need_update' bit.