0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellCacheManager.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 
26 
27 #include <Common/Compat.h>
28 #include "CellCacheManager.h"
29 
31 
32 #include <Hypertable/Lib/Key.h>
33 
34 #include <Common/ByteString.h>
35 
36 using namespace Hypertable;
37 using namespace std;
38 
40 
41  if (!m_immutable_cache)
42  return;
43 
44  if (m_immutable_cache->size() == 0) {
45  m_immutable_cache = 0;
46  return;
47  }
48 
49  if (m_active_cache->size() == 0) {
50  install_new_active_cache(m_immutable_cache);
51  m_immutable_cache = 0;
52  return;
53  }
54 
55  Key key;
56  ByteString value;
57  CellCachePtr merged_cache = make_shared<CellCache>();
58  ScanContextPtr scan_ctx = make_shared<ScanContext>(schema);
59  CellListScannerPtr scanner = m_immutable_cache->create_scanner(scan_ctx.get());
60  while (scanner->get(key, value)) {
61  merged_cache->add(key, value);
62  scanner->forward();
63  }
64 
65  // Add cell cache
66  scanner = m_active_cache->create_scanner(scan_ctx.get());
67  while (scanner->get(key, value)) {
68  merged_cache->add(key, value);
69  scanner->forward();
70  }
71  install_new_active_cache(merged_cache);
72  m_immutable_cache = 0;
73 }
74 
76  ByteString value;
77  Key key;
78  while (scanner->get(key, value)) {
79  m_active_cache->add(key, value);
80  scanner->forward();
81  }
82 }
83 
85  ScanContext *scan_ctx) {
86  if (m_immutable_cache)
87  mscanner->add_scanner(m_immutable_cache->create_scanner(scan_ctx));
88 }
89 
91  ScanContext *scan_ctx) {
92  if (!m_active_cache->empty())
93  scanner->add_scanner(m_active_cache->create_scanner(scan_ctx));
94  add_immutable_scanner(scanner, scan_ctx);
95 }
96 
97 
98 void
100  if (m_immutable_cache)
101  m_immutable_cache->split_row_estimate_data(split_row_data);
102  m_active_cache->split_row_estimate_data(split_row_data);
103 }
104 
105 
107  return m_active_cache->memory_used() +
108  (m_immutable_cache ? m_immutable_cache->memory_used() : 0);
109 }
110 
112  return m_active_cache->logical_size() +
113  (m_immutable_cache ? m_immutable_cache->logical_size() : 0);
114 }
115 
117  m_active_cache->add_statistics(stats);
118  if (m_immutable_cache)
119  m_immutable_cache->add_statistics(stats);
120 }
121 
123  return m_active_cache->delete_count() +
124  (m_immutable_cache ? m_immutable_cache->delete_count() : 0);
125 }
126 
128  m_immutable_cache = m_active_cache;
129  m_active_cache = make_shared<CellCache>();
130 }
131 
133  if (m_immutable_cache)
134  m_immutable_cache->populate_key_set(keys);
135  m_active_cache->populate_key_set(keys);
136 }
Holds cache statistics.
Definition: CellCache.h:57
int64_t logical_size()
Returns the logical amount of memory used by the active and immutable caches.
void populate_key_set(KeySet &keys)
Populates a set with all keys in the cell caches.
void add_immutable_scanner(MergeScannerAccessGroup *mscanner, ScanContext *scan_ctx)
Creates a scanner on the immutable cache and adds it to a merge scanner.
int64_t memory_used()
Returns the amount of memory used by the active and immutable caches.
STL namespace.
int32_t delete_count()
Returns the number of deletes present in the caches.
Scan context information.
Definition: ScanContext.h:52
void split_row_estimate_data(CellList::SplitRowDataMapT &split_row_data)
Populates map of split row data.
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
std::set< Key, key_revision_lt > KeySet
Definition: CellCache.h:44
void add_scanners(MergeScannerAccessGroup *scanner, ScanContext *scan_ctx)
Creates scanners on the active and immutable caches and adds them to a merge scanner.
std::map< const char *, int64_t, LtCstr, SplitRowDataAlloc > SplitRowDataMapT
Definition: CellList.h:66
Declarations for ScanContext.
Compatibility Macros for C/C++.
void add_scanner(CellListScannerPtr scanner)
Hypertable definitions
Provides access to internal components of opaque key.
Definition: Key.h:40
void get_cache_statistics(CellCache::Statistics &stats)
Gets cache statistics.
A serializable ByteString.
Declarations for CellCacheManager.
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
Definition: Schema.h:465
std::shared_ptr< CellListScanner > CellListScannerPtr
Definition: CellList.h:35
void freeze()
Freezes the active cache.
void merge_caches(SchemaPtr &schema)
Merges immutable cache into active cache.
std::shared_ptr< CellCache > CellCachePtr
Shared smart pointer to CellCache.
Definition: CellCache.h:163
std::shared_ptr< ScanContext > ScanContextPtr
Definition: ScanContext.h:169
void add(const Key &key, const ByteString value)
Inserts a key/value pair to the active cache.
Merge scanner for access groups.