43 agdata(agdata_), rangedata(rangedata_) { }
48 struct StatsRecOrderingDescending {
49 bool operator()(
const StatsRec &x,
const StatsRec &y)
const {
50 if (x.agdata->mem_used == y.agdata->mem_used)
51 return x.agdata->mem_used > y.agdata->mem_used;
52 return x.agdata->mem_used > y.agdata->mem_used;
56 struct ShadowCacheSortOrdering {
68 struct CellStoreIndexSortOrdering {
74 if (y_mem == 0 || x_mem == 0)
82 return x_atime < y_atime;
90 std::vector<RangeData> &range_data, int32_t &priority) {
91 if (m_initialization_complete)
94 for (
size_t i=0; i<range_data.size(); i++) {
95 if (!range_data[i].data->initialized)
96 m_uninitialized_ranges_seen =
true;
97 if (range_data[i].data->busy || range_data[i].data->priority)
99 if (!range_data[i].data->initialized)
100 range_data[i].data->priority = priority++;
113 for (
size_t i=0; i<range_data.size(); i++) {
115 if (range_data[i].data->busy) {
117 *trace +=
format(
"%d busy %s\n", __LINE__,
118 range_data[i].range->get_name().c_str());
125 *trace +=
format(
"%d mid-relinquish %s (state=%d, priority=%d"
126 ", mem_needed=%lld)\n", __LINE__,
127 range_data[i].range->get_name().c_str(),
128 range_data[i].data->state, priority,
130 HT_INFOF(
"Adding maintenance for range %s because mid-relinquish(%d)",
131 range_data[i].range->get_name().c_str(), range_data[i].data->state);
138 *trace +=
format(
"%d mid-split %s (state=%d, priority=%d"
139 ", mem_needed=%lld)\n", __LINE__,
140 range_data[i].range->get_name().c_str(),
141 range_data[i].data->state, priority,
143 HT_INFOF(
"Adding maintenance for range %s because mid-split(%d)",
144 range_data[i].range->get_name().c_str(),
145 range_data[i].data->state);
151 range_data[i].data->priority = priority++;
154 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
156 for (cs_data=ag_data->
csdata; cs_data; cs_data=cs_data->
next)
172 int64_t disk_total, mem_total;
174 for (
size_t i=0; i<range_data.size(); i++) {
176 if (range_data[i].data->busy || range_data[i].data->priority) {
177 if (range_data[i].data->busy && trace)
178 *trace +=
format(
"%d busy %s\n", __LINE__,
179 range_data[i].range->get_name().c_str());
187 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
190 for (cs_data=ag_data->
csdata; cs_data; cs_data=cs_data->
next)
198 if (range_data[i].data->relinquish) {
200 *trace +=
format(
"%d relinquish %s (priority=%d, mem_needed=%lld)\n",
201 __LINE__, range_data[i].range->get_name().c_str(),
203 HT_INFOF(
"Adding maintenance for range %s because marked for relinquish(%d)",
204 range_data[i].range->get_name().c_str(), range_data[i].data->state);
206 range_data[i].data->priority = priority++;
209 else if (range_data[i].data->needs_split && !range_data[i].range->is_root()) {
211 *trace +=
format(
"%d disk_total %lld exceeds threshold %s "
212 " (priority=%d, mem_needed=%lld)\n",
213 __LINE__, (
Lld)disk_total,
214 range_data[i].range->get_name().c_str(),
216 HT_INFOF(
"Adding maintenance for range %s because disk_total %d exceeds split threshold",
217 range_data[i].range->get_name().c_str(), (int)disk_total);
219 range_data[i].data->priority = priority++;
230 int32_t &priority,
String *trace) {
232 CommitLog::CumulativeSizeMap::iterator iter;
237 log->load_cumulative_size_map(cumulative_size_map);
239 for (
size_t i=0; i<range_data.size(); i++) {
241 if (range_data[i].data->busy) {
243 *trace +=
format(
"%d busy %s\n", __LINE__,
244 range_data[i].range->get_name().c_str());
248 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
254 if (iter == cumulative_size_map.end()) {
256 for (iter = cumulative_size_map.begin(); iter != cumulative_size_map.end(); iter++) {
257 errstr +=
format(
"PERROR frag-%d\trevision\t%lld\n",
258 (
int)(*iter).second.fragno, (
Lld)(*iter).first);
259 errstr +=
format(
"PERROR frag-%d\tdistance\t%lld\n",
260 (*iter).second.fragno, (
Lld)(*iter).second.distance);
261 errstr +=
format(
"PERROR frag-%d\tsize\t%lld\n",
262 (*iter).second.fragno, (
Lld)(*iter).second.cumulative_size);
264 errstr +=
format(
"PERROR revision %lld not found in map\n",
266 cout << flush << errstr << flush;
268 *trace +=
format(
"%d THIS SHOULD NEVER HAPPEN, ecr=%lld\n",
273 if ((*iter).second.cumulative_size > prune_threshold) {
276 *trace+=
format(
"%d prune compact %s (cumulative_size=%lld, prune_"
277 "threshold=%lld, priority=%d, mem_needed=%lld)\n",
279 (
Lld)(*iter).second.cumulative_size,
280 (
Lld)prune_threshold,
281 range_data[i].data->priority ? range_data[i].data->priority : priority,
283 if (range_data[i].data->priority == 0)
284 range_data[i].data->priority = priority++;
302 for (
size_t i=0; i<range_data.size(); i++) {
304 if (range_data[i].data->busy)
307 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
314 if (range_data[i].data->compaction_type_needed) {
317 if (range_data[i].data->priority == 0)
318 range_data[i].data->priority = priority++;
326 if (range_data[i].data->priority == 0)
327 range_data[i].data->priority = priority++;
329 *trace +=
format(
"%d GC needed %s (priority=%d, mem_needed=%lld)\n",
331 range_data[i].data->priority,
347 if (range_data[i].data->priority == 0)
348 range_data[i].data->priority = priority++;
350 *trace +=
format(
"%d large CellCache %s (mem_used=%lld, "
351 "priority=%d, mem_needed=%lld)\n", __LINE__,
353 (
Lld)ag_data->
mem_used, range_data[i].data->priority,
358 if (range_data[i].data->priority == 0)
359 range_data[i].data->priority = priority++;
367 *trace +=
format(
"%d needs merging %s (priority=%d, "
368 "mem_needed=%lld)\n", __LINE__,
370 range_data[i].data->priority,
386 std::vector<AccessGroup::CellStoreMaintenanceData *> csmd;
389 for (
size_t i=0; i<range_data.size(); i++) {
390 if (range_data[i].data->busy || range_data[i].data->priority)
392 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
393 ag_data->
user_data = (
void *)range_data[i].data;
394 for (cs_data=ag_data->
csdata; cs_data; cs_data=cs_data->
next) {
397 csmd.push_back(cs_data);
404 struct ShadowCacheSortOrdering ordering;
405 sort(csmd.begin(), csmd.end(), ordering);
408 for (
size_t i=0; i<csmd.size(); i++) {
413 if (range_maintenance_data->
priority == 0)
414 range_maintenance_data->
priority = priority++;
416 *trace +=
format(
"%d shadow cache purge %s (priority=%d, "
417 "mem_needed=%lld)\n", __LINE__,
419 range_data[i].data->priority,
436 std::vector<AccessGroup::CellStoreMaintenanceData *> csmd;
438 for (
size_t i=0; i<range_data.size(); i++) {
439 if (range_data[i].data->busy ||
442 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
443 ag_data->
user_data = (
void *)range_data[i].data;
444 for (cs_data=ag_data->
csdata; cs_data; cs_data=cs_data->
next) {
448 csmd.push_back(cs_data);
455 CellStoreIndexSortOrdering ordering;
456 sort(csmd.begin(), csmd.end(), ordering);
459 int64_t memory_used = 0;
460 for (
size_t i=0; i<csmd.size(); i++) {
465 memory_used = csmd[i]->index_stats.block_index_memory + csmd[i]->index_stats.bloom_filter_memory;
466 if (range_maintenance_data->
priority == 0)
467 range_maintenance_data->
priority = priority++;
469 *trace +=
format(
"%d cellstore index purge %s (priority=%d, "
470 "mem_needed=%lld)\n", __LINE__,
472 range_data[i].data->priority,
485 struct CellCacheCompactionSortOrdering {
500 std::vector<AccessGroup::MaintenanceData *> md;
502 for (
size_t i=0; i<range_data.size(); i++) {
504 if (range_data[i].data->busy ||
508 for (ag_data = range_data[i].data->agdata; ag_data; ag_data = ag_data->
next) {
512 md.push_back(ag_data);
518 struct CellCacheCompactionSortOrdering ordering;
519 sort(md.begin(), md.end(), ordering);
522 for (
size_t i=0; i<md.size(); i++) {
526 *trace +=
format(
"%d minor compaction %s (priority=%d, "
527 "mem_needed=%lld)\n", __LINE__,
528 md[i]->ag->get_full_name(),
uint64_t bloom_filter_access_counter
int64_t earliest_cached_revision
bool compact_cellcaches(std::vector< RangeData > &range_data, MemoryState &memory_state, int32_t &priority, String *trace)
std::map< int64_t, CumulativeFragmentData > CumulativeSizeMap
Memory shadow cache purge mask.
std::string String
A String is simply a typedef to std::string.
bool purge_shadow_caches(std::vector< RangeData > &range_data, MemoryState &memory_state, int32_t &priority, String *trace)
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Memory cellstore index purge mask.
void decrement_needed(int64_t amount)
uint32_t shadow_cache_hits
CellStoreMaintenanceData * csdata
int16_t maintenance_flags
void schedule_initialization_operations(std::vector< RangeData > &range_data, int32_t &priority)
bool purge_cellstore_indexes(std::vector< RangeData > &range_data, MemoryState &memory_state, int32_t &priority, String *trace)
Relinquish - log installed.
bool schedule_inprogress_operations(std::vector< RangeData > &range_data, MemoryState &memory_state, int32_t &priority, String *trace)
CellStoreMaintenanceData * next
uint64_t block_index_access_counter
bool schedule_splits_and_relinquishes(std::vector< RangeData > &range_data, MemoryState &memory_state, int32_t &priority, String *trace)
Compatibility Macros for C/C++.
CellStore::IndexMemoryStats index_stats
int64_t block_index_memory
long long int Lld
Shortcut for printf formats.
static const int64_t TIMESTAMP_MAX
const char * get_full_name()
uint64_t shadow_cache_size
#define HT_INFOF(msg,...)
std::shared_ptr< CommitLog > CommitLogPtr
Smart pointer to CommitLog.
static int32_t access_group_max_mem
int16_t maintenance_flags
Declarations for MaintenanceFlag This file contains declarations that are part of the MaintenanceFlag...
bool major_compaction(int flags)
Tests the COMPACT_MAJOR bit of flags
int64_t bloom_filter_memory
bool schedule_necessary_compactions(std::vector< RangeData > &range_data, CommitLogPtr &log, int64_t prune_threshold, MemoryState &memory_state, int32_t &priority, String *trace)
String extensions and helpers: sets, maps, append operators etc.
Executes user-defined functions when leaving the current scope.