0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStore.h
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 
27 
28 #ifndef Hypertable_RangeServer_CellStore_h
29 #define Hypertable_RangeServer_CellStore_h
30 
36 
39 
40 #include <Common/String.h>
41 #include <Common/ByteString.h>
42 #include <Common/Filesystem.h>
43 
44 #include <memory>
45 #include <mutex>
46 #include <vector>
47 
48 namespace Hypertable {
49 
52 
57  class CellStore : public CellList, public std::enable_shared_from_this<CellStore> {
58  public:
59 
61  public:
69  };
70 
72 
73  virtual ~CellStore() { return; }
74 
75  virtual void add(const Key &key, const ByteString value) = 0;
76 
83  virtual void split_row_estimate_data(SplitRowDataMapT &split_row_data) {
84  HT_FATAL("Not implemented!");
85  }
86 
93 
96  virtual int64_t get_total_entries() = 0;
97 
98  virtual CellListScannerPtr
100 
110  virtual void create(const char *fname, size_t max_entries,
111  PropertiesPtr &props, const TableIdentifier *table_id=0) = 0;
112 
119  virtual void finalize(TableIdentifier *table_identifier) = 0;
120 
136  virtual void open(const String &fname, const String &start_row,
137  const String &end_row, int32_t fd, int64_t file_length,
138  CellStoreTrailer *trailer) = 0;
139 
140  virtual void rescope(const String &start_row, const String &end_row) {
141  HT_FATAL("Not implemented!");
142  }
143 
151  virtual int64_t get_blocksize() = 0;
152 
159  virtual bool may_contain(ScanContext *scan_ctx) = 0;
160 
168  virtual uint64_t disk_usage() = 0;
169 
174  virtual size_t block_count() {
175  std::lock_guard<std::mutex> lock(m_mutex);
176  return m_block_count;
177  }
178 
184  virtual float compression_ratio() = 0;
185 
191  virtual std::string &get_filename() = 0;
192 
199  virtual int get_file_id() = 0;
200 
206  virtual CellStoreTrailer *get_trailer() = 0;
207 
215 
223 
227  virtual void set_replaced_files(const std::vector<String> &old_files);
228 
234  virtual const std::vector<String> &get_replaced_files();
235 
239  virtual void display_block_info() = 0;
240 
246  virtual size_t bloom_filter_size() = 0;
247 
253  virtual int32_t get_fd() = 0;
254 
260  virtual int32_t reopen_fd() = 0;
261 
267  virtual int64_t bloom_filter_memory_used() = 0;
268 
274  virtual int64_t block_index_memory_used() = 0;
275 
281  virtual int64_t end_of_last_block() = 0;
282 
288  virtual uint64_t purge_indexes() = 0;
289 
293  virtual void get_index_memory_stats(IndexMemoryStats *statsp) {
294  std::lock_guard<std::mutex> lock(m_mutex);
295  memcpy(statsp, &m_index_stats, sizeof(IndexMemoryStats));
296  }
297 
303  virtual bool restricted_range() = 0;
304 
311  uint64_t bytes_read() {
312  std::lock_guard<std::mutex> lock(m_mutex);
313  return m_bytes_read;
314  }
315 
319  std::lock_guard<std::mutex> lock(m_mutex);
321  }
322 
323  virtual uint16_t block_header_format() = 0;
324 
325  static const char DATA_BLOCK_MAGIC[10];
326  static const char INDEX_FIXED_BLOCK_MAGIC[10];
327  static const char INDEX_VARIABLE_BLOCK_MAGIC[10];
328 
329  protected:
330 
333  std::vector <String> m_replaced_files;
334  uint64_t m_bytes_read;
337  };
338 
340  typedef std::shared_ptr<CellStore> CellStorePtr;
341 
343 
344 } // namespace Hypertable
345 
346 #endif // Hypertable_RangeServer_CellStore_h
static const char INDEX_FIXED_BLOCK_MAGIC[10]
Definition: CellStore.h:326
virtual CellListScannerPtr create_scanner(ScanContext *scan_ctx)
Creates a scanner on this cell list.
Definition: CellStore.h:99
static std::mutex mutex
Definition: Logger.cc:43
Abstract base class for cell store trailer.
Cell list scanner over a buffer of cells.
Abstract base class for persistent cell lists (ones that are stored on disk).
Definition: CellStore.h:57
static const char INDEX_VARIABLE_BLOCK_MAGIC[10]
Definition: CellStore.h:327
virtual bool may_contain(ScanContext *scan_ctx)=0
Bloom filter lookup.
Abstract base class for a filesystem.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Declarations for TableIdentifier and TableIdentifierManaged.
virtual void display_block_info()=0
Displays block information to stdout.
virtual int64_t get_total_entries()=0
Returns the number of key/value pairs in the cell store.
#define HT_FATAL(msg)
Definition: Logger.h:339
virtual int64_t get_blocksize()=0
Returns the block size used for this cell store.
virtual void finalize(TableIdentifier *table_identifier)=0
Finalizes the creation of a cell store, by writing block index and metadata trailer.
Scan context information.
Definition: ScanContext.h:52
uint32_t m_index_refcount
Definition: CellStore.h:336
Declarations for CellListScannerBuffer.
Declarations for BlockCompressionCodec.
virtual void rescope(const String &start_row, const String &end_row)
Definition: CellStore.h:140
virtual int32_t reopen_fd()=0
Closes and reopens the underlying CellStore file.
virtual int64_t block_index_memory_used()=0
Returns the amount of memory consumed by the block index.
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
IndexMemoryStats m_index_stats
Definition: CellStore.h:332
std::map< const char *, int64_t, LtCstr, SplitRowDataAlloc > SplitRowDataMapT
Definition: CellList.h:66
virtual int get_file_id()=0
Returns a unique identifier which identifies the underlying file for caching purposes.
virtual void add(const Key &key, const ByteString value)=0
Inserts a key/value pair into the cell list.
virtual int64_t end_of_last_block()=0
Returns the offset of the end of the last block in the cell store.
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
virtual size_t bloom_filter_size()=0
Return Bloom filter size.
void decrement_index_refcount()
Decrement index reference count.
Definition: CellStore.h:318
virtual int64_t bloom_filter_memory_used()=0
Returns the amount of memory consumed by the bloom filter.
std::mutex m_mutex
Definition: CellStore.h:331
virtual KeyDecompressor * create_key_decompressor()
Creates a key decompressor suitable for decompressing the keys stored in this cell store...
Definition: CellStore.cc:42
virtual CellStoreTrailer * get_trailer()=0
Return a pointer to the trailer object for this cell store.
virtual int32_t get_fd()=0
Returns the open file descriptor for the CellStore file.
uint64_t bytes_read()
Returns the number of "uncompressed" bytes read from the underlying filesystem.
Definition: CellStore.h:311
virtual size_t block_count()
Returns the number of CellStore blocks covered by this object.
Definition: CellStore.h:174
virtual std::string & get_filename()=0
Pathname of cell store file.
virtual uint64_t purge_indexes()=0
Purges bloom filter and block indexes.
std::shared_ptr< CellStore > CellStorePtr
Smart pointer to CellStore.
Definition: CellStore.h:340
virtual uint16_t block_header_format()=0
Hypertable definitions
virtual float compression_ratio()=0
Returns block compression ratio of this cell store.
virtual void set_replaced_files(const std::vector< String > &old_files)
Sets the cell store files replaced by this CellStore.
Definition: CellStore.cc:46
std::vector< String > m_replaced_files
Definition: CellStore.h:333
virtual void get_index_memory_stats(IndexMemoryStats *statsp)
Returns amount of purgeable index memory available.
Definition: CellStore.h:293
virtual uint64_t disk_usage()=0
Returns the disk used by this cell store.
virtual ~CellStore()
Definition: CellStore.h:73
virtual void populate_index_pseudo_table_scanner(CellListScannerBuffer *scanner)
Populates scanner with key/value pairs generated from CellStore index.
Definition: CellStore.h:92
Provides access to internal components of opaque key.
Definition: Key.h:40
static const char DATA_BLOCK_MAGIC[10]
Definition: CellStore.h:325
virtual BlockCompressionCodec * create_block_compression_codec()=0
Creates a block compression codec suitable for decompressing the cell store's blocks.
A String class based on std::string.
A serializable ByteString.
virtual void open(const String &fname, const String &start_row, const String &end_row, int32_t fd, int64_t file_length, CellStoreTrailer *trailer)=0
Opens a cell store with possibly a restricted view.
std::shared_ptr< CellListScanner > CellListScannerPtr
Definition: CellList.h:35
virtual void split_row_estimate_data(SplitRowDataMapT &split_row_data)
Populates split_row_data with unique row and count estimates from block index.
Definition: CellStore.h:83
virtual bool restricted_range()=0
Returns true if the cellstore was opened with a restricted range.
virtual void create(const char *fname, size_t max_entries, PropertiesPtr &props, const TableIdentifier *table_id=0)=0
Creates a new cell store.
Abstract base class for block compression codecs.
Declarations for CellStoreBlockIndexArray.
virtual const std::vector< String > & get_replaced_files()
Returns all the cell store files replaced by this CellStore.
Definition: CellStore.cc:50
Abstract base class for cell lists (sorted lists of key/value pairs).
Definition: CellList.h:42