Zero  0.1.0
buffer_pool.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2011-2014, Hewlett-Packard Development Company, LP
3  */
4 
5 #ifndef __SM_BUFFER_POOL_HPP
6 #define __SM_BUFFER_POOL_HPP
7 
8 #include "w_defines.h"
9 #include "bf_tree_cb.h"
10 #include "latch.h"
11 #include "vol.h"
12 #include "generic_page.h"
13 #include <iosfwd>
15 #include "page_cleaner.h"
16 #include "page_evictioner.hpp"
17 #include "restart.h"
18 #include "restore.h"
19 
20 #include <array>
24 
25 #include "boost/align/aligned_allocator.hpp"
26 
27 class sm_options;
28 class lsn_t;
29 class test_bf_tree;
30 class bf_tree_cleaner;
31 class btree_page_h;
33 
34 namespace zero::buffer_pool {
35 
40  class BufferPool {
41  friend class ::test_bf_tree; // for testcases
42  friend class ::bf_tree_cleaner; // for page cleaning
43  friend class page_cleaner_decoupled; // for log-based "decoubled" page cleaning
44  friend class ::GenericPageIterator;
45  friend class FreeListLowContention;
46  friend class FreeListHighContention;
47  friend class PageEvictioner;
48 
49  template<class selector_class, class filter_class, bool filter_early> friend class PageEvictionerSelectAndFilter;
50 
51  public:
61  BufferPool();
62 
71  void postInitialize();
72 
80  void shutdown();
81 
89  ~BufferPool();
90 
96  inline bf_idx getBlockCount() const noexcept {
97  return _blockCount;
98  };
99 
105  inline bool isNoDBMode() const noexcept {
106  return _noDBMode;
107  }
108 
114  inline bool usesWriteElision() const noexcept {
115  return _useWriteElision;
116  }
117 
125  inline bool isWarmupDone() const noexcept {
126  return _warmupDone;
127  }
128 
135  inline const std::shared_ptr<zero::buffer_pool::Hashtable> getHashtable() const noexcept {
136  return _hashtable;
137  };
138 
144  inline const std::shared_ptr<zero::buffer_pool::FreeListLowContention> getFreeList() const noexcept {
145  return _freeList;
146  };
147 
153  inline const std::shared_ptr<page_cleaner_base> getPageCleaner() const noexcept {
154  return _cleaner;
155  };
156 
160  inline void wakeupPageCleaner() const {
161  if (_cleaner) {
162  _cleaner->wakeup(true, 1);
163  }
164  };
165 
171  const std::shared_ptr<PAGE_EVICTIONER> getPageEvictioner() const noexcept;
172 
180  bool hasDirtyFrames();
181 
197  void fixRoot(generic_page*& targetPage, StoreID store, latch_mode_t latchMode, bool conditional, bool virgin);
198 
199  w_rc_t fixRootOldStyleExceptions(generic_page*& targetPage, StoreID store, latch_mode_t latchMode,
200  bool conditional, bool virgin);
201 
232  bool fixNonRoot(generic_page*& targetPage, generic_page* parentPage, PageID pid, latch_mode_t latchMode,
233  bool conditional = false, bool virgin = false, bool onlyIfHit = false, bool doRecovery = true,
234  lsn_t emlsn = lsn_t::null);
235 
236  w_rc_t fixNonRootOldStyleExceptions(generic_page*& targetPage, generic_page* parentPage, PageID pid,
237  latch_mode_t latchMode, bool conditional = false, bool virgin = false,
238  bool onlyIfHit = false, bool doRecovery = true, lsn_t emlsn = lsn_t::null);
239 
257  bf_idx pinForRefix(const generic_page* pinPage);
258 
271  void refixDirect(generic_page*& targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional);
272 
273  w_rc_t refixDirectOldSytleExceptions(generic_page*& targetPage, bf_idx refixIndex, latch_mode_t latchMode,
274  bool conditional);
275 
286  void unpinForRefix(bf_idx unpinIndex);
287 
296  void unfix(const generic_page* unfixPage, bool evict = false);
297 
308  return _controlBlocks[index];
309  };
310 
312  const bf_tree_cb_t& getControlBlock(bf_idx index) const noexcept {
313  return _controlBlocks[index];
314  };
315 
327  bf_tree_cb_t& getControlBlock(const generic_page* page) noexcept {
328  return getControlBlock(getIndex(page));
329  };
330 
338  bf_idx getIndex(const bf_tree_cb_t& controlBlock) const noexcept {
339  return std::distance(_controlBlocks.data(), &controlBlock);
340  };
341 
349  bf_idx getIndex(const generic_page* page) const noexcept {
350  return static_cast<bf_idx>(page - _buffer);
351  };
352 
361  bf_idx getRootIndex(StoreID store) const noexcept {
362  bf_idx rootIndex = _rootPages[store];
363  if (!isValidIndex(rootIndex)) {
364  return 0;
365  } else {
366  return rootIndex;
367  }
368  };
369 
379  generic_page* getPage(const bf_idx& index) noexcept {
380  w_assert1(isValidIndex(index));
381  return &_buffer[index];
382  };
383 
385  const generic_page* getPage(const bf_idx& index) const noexcept {
386  w_assert1(isValidIndex(index));
387  return &_buffer[index];
388  };
389 
398  bool isValidIndex(bf_idx index) const noexcept {
399  return index > 0 && index < _blockCount;
400  };
401 
414  bool isActiveIndex(bf_idx index) const noexcept {
415  return isValidIndex(index) && getControlBlock(index)._used;
416  };
417 
427  bool upgradeLatchConditional(const generic_page* page) noexcept;
428 
436  void downgradeLatch(const generic_page* page) noexcept;
437 
455  bool unswizzlePagePointer(generic_page* parentPage, general_recordid_t childSlotInParentPage,
456  PageID* childPageID = nullptr);
457 
470  PageID normalizePID(const PageID pid) const noexcept {
471  if constexpr (POINTER_SWIZZLER::usesPointerSwizzling) {
472  if (POINTER_SWIZZLER::isSwizzledPointer(pid)) {
473  bf_idx index = POINTER_SWIZZLER::makeBufferIndex(pid);
474  w_assert1(isValidIndex(index));
475  const bf_tree_cb_t& controlBlock = getControlBlock(index);
476  w_assert1(!POINTER_SWIZZLER::isSwizzledPointer(controlBlock._pid));
477  return controlBlock._pid;
478  } else {
479  return pid;
480  }
481  } else {
482  return pid;
483  }
484  };
485 
524  bool isEvictable(const bf_idx indexToCheck, const bool doFlushIfDirty) noexcept;
525 
538  void batchPrefetch(PageID startPID, bf_idx numberOfPages) noexcept;
539 
555  void recoverIfNeeded(bf_tree_cb_t& controlBlock, generic_page* page, bool onlyIfDirty = true) noexcept;
556 
567  void fuzzyCheckpoint(chkpt_t& checkpoint) const noexcept;
568 
582  void sxUpdateChildEMLSN(btree_page_h& parentPage, general_recordid_t childSlotID, lsn_t childEMLSN) const;
583 
596  void switchParent(PageID childPID, generic_page* newParentPage) noexcept;
597 
605  void setMediaFailure() noexcept;
606 
614  void unsetMediaFailure() noexcept;
615 
622  PageID getMediaFailurePID() const noexcept {
623  return _mediaFailurePID;
624  };
625 
632  bool isMediaFailure() const noexcept {
633  return _mediaFailurePID > 0;
634  };
635 
643  bool isMediaFailure(PageID pid) const noexcept {
644  return _mediaFailurePID > 0 && pid < _mediaFailurePID;
645  };
646 
657  void debugDump(std::ostream& o) const;
658 
670  void debugDumpPagePointers(std::ostream& o, generic_page* page) const;
671 
672  private:
678 
679  // CS TODO: concurrency???
685  std::array<bf_idx, stnode_page::max> _rootPages;
686 
692  std::vector<bf_tree_cb_t, boost::alignment::aligned_allocator<bf_tree_cb_t, sizeof(bf_tree_cb_t)>>
694 
701 
708  std::shared_ptr<Hashtable> _hashtable;
709 
717  std::shared_ptr<FreeListLowContention> _freeList;
718 
723  std::shared_ptr<page_cleaner_base> _cleaner;
724 
731 
738  std::shared_ptr<PAGE_EVICTIONER> _evictioner;
739 
752 
758 
765  static thread_local SprIterator _localSprIter;
766 
768 
773  std::shared_ptr<RestoreCoord> _restoreCoordinator;
774 
776 
781  std::shared_ptr<BgRestorer> _backgroundRestorer;
782 
790 
795  std::atomic<PageID> _mediaFailurePID;
796 
802 
807  bool _noDBMode;
808 
815 
821 
827 
833 
839 
844  unsigned _warmupMinFixes;
845 
850  static thread_local unsigned _fixCount;
851 
856  static thread_local unsigned _hitCount;
857 
888  bool _fix(generic_page* parentPage, generic_page*& targetPage, PageID pid, latch_mode_t latchMode,
889  bool conditional, bool virgin, bool onlyIfHit = false, bool doRecovery = true,
890  lsn_t emlsn = lsn_t::null);
891 
902  void _convertToDiskPage(generic_page* page) const noexcept;
903 
915  void _readPage(PageID pid, generic_page* targetPage, bool fromBackup = false);
916 
927  void _deletePage(bf_idx index) noexcept;
928 
935  void _checkWarmupDone() noexcept;
936 
940  void _setWarmupDone() noexcept;
941  };
942 
943  class BufferPoolException : public std::exception {
944  public:
945  const char* what() const noexcept override {
946  return "Some error happened in this buffer pool!";
947  };
948  };
949 
951  public:
952  BufferPoolSizeException(const bf_idx& blockCount) :
953  _blockCount(blockCount) {};
954 
955  const char* what() const noexcept override {
956  int whatStringLength = snprintf(nullptr, 0,
957  "The set buffer pool size of %zdMB causes an error in this buffer pool!",
958  (_blockCount * sizeof(generic_page) + 33) / 1024 / 1024);
959  char* whatSentence = new char[whatStringLength + 1];
960  snprintf(whatSentence, whatStringLength,
961  "The set buffer pool size of %zdMB causes an error in this buffer pool!",
962  (_blockCount * sizeof(generic_page) + 33) / 1024 / 1024);
963  return whatSentence;
964  };
965 
966  protected:
968  };
969 
971  public:
972  BufferPoolTooSmallException(const bf_idx& blockCount, const bf_idx& minimumBlockCount) :
973  BufferPoolSizeException(blockCount),
974  _minimumBlockCount(minimumBlockCount) {};
975 
976  const char* what() const noexcept override {
977  int whatStringLength = snprintf(nullptr, 0,
978  "The set buffer pool size of %zdMB is too small! At least %zdMB are required.",
979  (_blockCount * sizeof(generic_page) + 33) / 1024 / 1024,
980  (_minimumBlockCount * sizeof(generic_page) + 33) / 1024 / 1024);
981  char* whatSentence = new char[whatStringLength + 1];
982  snprintf(whatSentence, whatStringLength,
983  "The set buffer pool size of %zdMB is too small! At least %zdMB are required.",
984  (_blockCount * sizeof(generic_page) + 33) / 1024 / 1024,
985  (_minimumBlockCount * sizeof(generic_page) + 33) / 1024 / 1024);
986  return whatSentence;
987  };
988 
989  protected:
991  };
992 
994  public:
995  BufferPoolTooLargeException(const bf_idx& blockCount) :
996  BufferPoolSizeException(blockCount) {};
997 
998  const char* what() const noexcept override {
999  int whatStringLength = snprintf(nullptr, 0,
1000  "The set buffer pool size of %zdMB cannot be allocated!",
1001  (_blockCount * sizeof(generic_page) + 33) / 1024 / 1024);
1002  char* whatSentence = new char[whatStringLength + 1];
1003  snprintf(whatSentence, whatStringLength,
1004  "The set buffer pool size of %zdMB cannot be allocated!",
1005  (_blockCount * sizeof(generic_page) + 33) / 1024 / 1024);
1006  return whatSentence;
1007  };
1008  };
1009 
1011  public:
1012  BufferPoolOldStyleException(const w_rc_t& oldStyleException) :
1013  _oldStyleException(oldStyleException) {};
1014 
1015  const char* what() const noexcept override {
1016  if (_oldStyleException.err_num() == w_error_ok) {
1017  return "No error";
1018  } else {
1019  char* whatStringFirstLine;
1020  int whatStringFirstLineLength;
1021  if (_oldStyleException.get_custom_message() != nullptr) {
1022  whatStringFirstLineLength = snprintf(nullptr, 0, "%s(%d):%s:%s",
1023  w_error_name(_oldStyleException.err_num()),
1024  _oldStyleException.err_num(),
1025  _oldStyleException.get_message(),
1026  _oldStyleException.get_custom_message());
1027  whatStringFirstLine = new char[whatStringFirstLineLength + 1];
1028  snprintf(whatStringFirstLine, whatStringFirstLineLength, "%s(%d):%s:%s",
1029  w_error_name(_oldStyleException.err_num()),
1030  _oldStyleException.err_num(),
1031  _oldStyleException.get_message(),
1032  _oldStyleException.get_custom_message());
1033  } else {
1034  whatStringFirstLineLength = snprintf(nullptr, 0, "%s(%d):%s:%s",
1035  w_error_name(_oldStyleException.err_num()),
1036  _oldStyleException.err_num(),
1037  _oldStyleException.get_message(),
1038  _oldStyleException.get_custom_message());
1039  whatStringFirstLine = new char[whatStringFirstLineLength + 1];
1040  snprintf(whatStringFirstLine, whatStringFirstLineLength, "%s(%d):%s",
1041  w_error_name(_oldStyleException.err_num()),
1042  _oldStyleException.err_num(),
1043  _oldStyleException.get_message());
1044  }
1045 
1046  char** whatStringStack = new char* [_oldStyleException.get_stack_depth()];
1047  int* whatStringStackLength = new int[_oldStyleException.get_stack_depth()];
1048  int whatStringStackTotalLength = 0;
1049  for (int stackIndex = 0; stackIndex < _oldStyleException.get_stack_depth(); stackIndex++) {
1050  whatStringStackLength[stackIndex] = snprintf(nullptr, 0, " %s:%d",
1051  _oldStyleException.get_filename(stackIndex),
1052  _oldStyleException.get_linenum(stackIndex));
1053  whatStringStack[stackIndex] = new char[whatStringStackLength[stackIndex] + 1];
1054  snprintf(whatStringStack[stackIndex], whatStringStackLength[stackIndex], " %s:%d",
1055  _oldStyleException.get_filename(stackIndex),
1056  _oldStyleException.get_linenum(stackIndex));
1057  whatStringStackTotalLength += whatStringStackLength[stackIndex];
1058  }
1059 
1060  char* whatStringLastLine;
1061  int whatStringLastLineLength = 0;
1062  if (_oldStyleException.get_stack_depth() >= MAX_RCT_STACK_DEPTH) {
1063  whatStringLastLine = " .. and more. Increase MAX_RCT_STACK_DEPTH to see full stacktraces";
1064  whatStringLastLineLength = strlen(whatStringLastLine);
1065  }
1066 
1067  char* whatString = new char[whatStringFirstLineLength + 1
1068  + whatStringStackTotalLength + _oldStyleException.get_stack_depth() - 1
1069  + whatStringLastLineLength + (whatStringLastLineLength ? 1 : 0)
1070  + 1];
1071  strcpy(whatString, whatStringFirstLine);
1072  for (int stackLine = 0; stackLine < sizeof(whatStringStack) / sizeof(whatStringStack[0]); stackLine++) {
1073  strcat(whatString, "\n");
1074  strcat(whatString, whatStringStack[stackLine]);
1075  }
1076  if (whatStringLastLineLength > 0) {
1077  strcat(whatString, "\n");
1078  strcat(whatString, whatStringLastLine);
1079  }
1080 
1081  return whatString;
1082  }
1083  }
1084 
1085  const w_rc_t& getOldStyleException() const noexcept {
1086  return _oldStyleException;
1087  };
1088 
1089  protected:
1091  };
1092 } // zero::buffer_pool
1093 
1101 public:
1103  _idx(0) {};
1104 
1106  _idx(idx) {};
1107 
1109  steal_ownership(h);
1110  };
1111 
1113  if (_idx != 0) {
1114  release();
1115  }
1116  };
1117 
1119  steal_ownership(h);
1120  return *this;
1121  };
1122 
1124  if (_idx != 0) {
1125  release();
1126  }
1127  _idx = h._idx;
1128  h._idx = 0;
1129  };
1130 
1131  void set(bf_idx idx) {
1132  if (_idx != 0) {
1133  release();
1134  }
1135  _idx = idx;
1136  };
1137 
1138  void release();
1139 
1141 };
1142 
1144 public:
1147  _first(0),
1148  _count(0),
1149  _virgin(false),
1150  _current(nullptr),
1151  _current_pid(0),
1152  _fix_depth(0) {};
1153 
1155  GenericPageIterator(PageID first, PageID count, bool virgin) :
1156  _first(first),
1157  _count(count),
1158  _virgin(virgin),
1159  _current(nullptr),
1160  _fix_depth(0) {
1161  if (count > 0) {
1162  _current_pid = _first - 1;
1163  operator++();
1164  }
1165  };
1166 
1168  _first(other._first),
1169  _count(other._count),
1170  _virgin(other._virgin),
1171  _current(nullptr),
1172  _fix_depth(0) {
1173  if (_count > 0) {
1174  _current_pid = _first - 1;
1175  operator++();
1176  }
1177  };
1178 
1180  unfix_current();
1181  w_assert1(_fix_depth == 0);
1182  };
1183 
1185  if (!_current || _current_pid >= end_pid()) {
1186  return nullptr;
1187  }
1188  return _current;
1189  };
1190 
1191  /*
1192  * WARNING: this operator may skip a PID (e.g., jump from 42 to 44) if
1193  * fix_current() returns false! I couldn't find a quick, elegant way to
1194  * work around this problem yet.
1195  */
1197  unfix_current();
1198 
1199  bool success = false;
1200  while (!success) {
1201  _current_pid++;
1202  if (_current_pid >= end_pid()) {
1203  return *this;
1204  }
1205  success = fix_current();
1206  }
1207 
1208  return *this;
1209  };
1210 
1212  std::swap(*this, other);
1213  return *this;
1214  };
1215 
1217  std::swap(a._first, b._first);
1218  std::swap(a._count, b._count);
1219  std::swap(a._virgin, b._virgin);
1220  std::swap(a._current, b._current);
1221  std::swap(a._current_pid, b._current_pid);
1222  std::swap(a._fix_depth, b._fix_depth);
1223  };
1224 
1226  if (!_current && !other._current) {
1227  return true;
1228  }
1229  return other._current_pid == _current_pid && _current && other._current;
1230  };
1231 
1233  return !(*this == other);
1234  };
1235 
1236  PageID begin_pid() const {
1237  return _first;
1238  };
1239 
1240  PageID end_pid() const {
1241  return _first + _count;
1242  };
1243 
1245 
1246 private:
1248 
1250 
1251  bool _virgin;
1252 
1254 
1256 
1257  bool fix_current() {
1258  w_assert1(_fix_depth == 0);
1259  constexpr bool conditional = true;
1260  constexpr bool do_recovery = false;
1261  constexpr bool only_if_hit = false;
1262  try {
1263  smlevel_0::bf->_fix(nullptr, _current, _current_pid, LATCH_EX, conditional, _virgin, only_if_hit,
1264  do_recovery);
1265  } catch (const zero::buffer_pool::BufferPoolOldStyleException& exception) {
1266  /*
1267  * The latch is already held, either by this thread (in SH mode, which
1268  * results in stINUSE to avoid deadlock) or by another thread. In that
1269  * case, we assume that if the frame is latched, the thread that holds
1270  * that latch already made sure that the page is consistent, and thus
1271  * log replay is not required.
1272  */
1273  if (exception.getOldStyleException().err_num() == stINUSE
1274  || exception.getOldStyleException().err_num() == stTIMEOUT) {
1275  ERROUT(<< "failed to fix "
1276  << _current_pid);
1277  _current = nullptr;
1278  return false;
1279  }
1280  W_COERCE(exception.getOldStyleException());
1281  }
1282 
1283  _fix_depth++;
1284 
1285  return true;
1286  };
1287 
1288  void unfix_current() {
1289  if (_current) {
1290  w_assert1(_fix_depth == 1);
1291  bf_tree_cb_t& currentControlBlock = smlevel_0::bf->getControlBlock(_current);
1292  currentControlBlock.unpin_for_restore();
1293  currentControlBlock.set_check_recovery(true);
1294  smlevel_0::bf->unfix(_current);
1295  _current = nullptr;
1296  _fix_depth--;
1297  }
1298  };
1299 };
1300 
1301 #endif // __SM_BUFFER_POOL_HPP
PageID _count
Definition: buffer_pool.hpp:1249
Definition: buffer_pool_free_list.hpp:58
const generic_page * getPage(const bf_idx &index) const noexcept
A buffered page at a buffer pool index. noexcept
Definition: buffer_pool.hpp:385
void sxUpdateChildEMLSN(btree_page_h &parentPage, general_recordid_t childSlotID, lsn_t childEMLSN) const
Update the EMLSN of a B-Tree child inside its parent page.
Definition: buffer_pool.cpp:580
PageID _pid
Definition: bf_tree_cb.h:108
GenericPageIterator & operator++()
Definition: buffer_pool.hpp:1196
Definition: latch.h:82
const std::shared_ptr< page_cleaner_base > getPageCleaner() const noexcept
Returns the page cleaner of this buffer pool.
Definition: buffer_pool.hpp:153
w_error_codes err_num() const
Definition: w_rc.h:510
const std::shared_ptr< zero::buffer_pool::Hashtable > getHashtable() const noexcept
Returns the hashtable of this buffer pool.
Definition: buffer_pool.hpp:135
generic_page * getPage(const bf_idx &index) noexcept
A buffered page at a buffer pool index.
Definition: buffer_pool.hpp:379
GenericPageIterator()
This essentially yields an "end" iterator.
Definition: buffer_pool.hpp:1146
void wakeupPageCleaner() const
Definition: buffer_pool.hpp:160
size_t _batchSegmentSize
MG TODO.
Definition: buffer_pool.hpp:820
bf_idx _minimumBlockCount
Definition: buffer_pool.hpp:987
void _readPage(PageID pid, generic_page *targetPage, bool fromBackup=false)
Reads a page from database or backup.
Definition: buffer_pool.cpp:1153
bool isValidIndex(bf_idx index) const noexcept
Checks the validity of a buffer pool index in this buffer pool.
Definition: buffer_pool.hpp:398
Definition: buffer_pool.hpp:970
void _convertToDiskPage(generic_page *page) const noexcept
Converts an image of a page with swizzled pointers to one without.
Definition: buffer_pool.cpp:1131
~BufferPool()
Default destructor for a buffer pool.
Definition: buffer_pool.cpp:129
static thread_local SprIterator _localSprIter
Single-page-recovery iterator used for instant restart redo.
Definition: buffer_pool.hpp:765
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
Definition: buffer_pool.hpp:943
w_rc_t _oldStyleException
Definition: buffer_pool.hpp:1087
Control block in the new buffer pool class.
Definition: bf_tree_cb.h:53
void unsetMediaFailure() noexcept
MG TODO.
Definition: buffer_pool.cpp:669
void fixRoot(generic_page *&targetPage, StoreID store, latch_mode_t latchMode, bool conditional, bool virgin)
Fixes a root B-Tree page in this buffer pool.
Definition: buffer_pool.cpp:153
bf_idx pinForRefix(const generic_page *pinPage)
Pin a page for a cheaper re-fix.
Definition: buffer_pool.cpp:230
bf_idx getIndex(const bf_tree_cb_t &controlBlock) const noexcept
The buffer pool index of a control block.
Definition: buffer_pool.hpp:338
pin_for_refix_holder()
Definition: buffer_pool.hpp:1102
bool _cleanerDecoupled
Use log-based "decoupled" cleaner.
Definition: buffer_pool.hpp:730
int16_t general_recordid_t
An integer to point to any record in B-tree pages.
Definition: basics.h:71
Definition: buffer_pool.hpp:34
Definition: restore.h:312
const char * what() const noexcept override
Definition: buffer_pool.hpp:976
BufferPool()
Default constructor for a buffer pool.
Definition: buffer_pool.cpp:50
std::atomic< bool > _used
true if this block is actually used
Definition: bf_tree_cb.h:142
Page handle for B-Tree data page.
Definition: btree_page_h.h:185
static thread_local unsigned _fixCount
MG TODO.
Definition: buffer_pool.hpp:850
void _deletePage(bf_idx index) noexcept
Deletes a page from this buffer pool.
Definition: buffer_pool.cpp:1172
std::shared_ptr< BgRestorer > _backgroundRestorer
MG TODO.
Definition: buffer_pool.hpp:781
void batchPrefetch(PageID startPID, bf_idx numberOfPages) noexcept
Prefetches a batch of pages into this buffer pool.
Definition: buffer_pool.cpp:462
bool fixNonRoot(generic_page *&targetPage, generic_page *parentPage, PageID pid, latch_mode_t latchMode, bool conditional=false, bool virgin=false, bool onlyIfHit=false, bool doRecovery=true, lsn_t emlsn=lsn_t::null)
Fixes a non-root B-Tree page in this buffer pool.
Definition: buffer_pool.cpp:209
STL namespace.
uint32_t StoreID
Definition: basics.h:47
bool _useWriteElision
Use write elision.
Definition: buffer_pool.hpp:789
void steal_ownership(pin_for_refix_holder &h)
Definition: buffer_pool.hpp:1123
void unfix_current()
Definition: buffer_pool.hpp:1288
A generic page view: any Zero page can be viewed as being of this type but it only exposes fields sha...
Definition: generic_page.h:121
Definition: chkpt.h:156
BufferPoolOldStyleException(const w_rc_t &oldStyleException)
Definition: buffer_pool.hpp:1012
GenericPageIterator(const GenericPageIterator &other)
Definition: buffer_pool.hpp:1167
std::shared_ptr< PAGE_EVICTIONER > _evictioner
Evicts pages.
Definition: buffer_pool.hpp:738
bool isActiveIndex(bf_idx index) const noexcept
Checks whether a buffer pool frame is used in this buffer pool.
Definition: buffer_pool.hpp:414
Definition: buffer_pool.hpp:1010
Coordinator that synchronizes multi-threaded decentralized restore.
Definition: restore.h:117
const std::shared_ptr< zero::buffer_pool::FreeListLowContention > getFreeList() const noexcept
Returns the free list of this buffer pool.
Definition: buffer_pool.hpp:144
Start-up parameters for the storage engine. See OPTIONS.
Definition: sm_options.h:24
void _checkWarmupDone() noexcept
Decides if this buffer pool is "warmed up".
Definition: buffer_pool.cpp:1188
bool isEvictable(const bf_idx indexToCheck, const bool doFlushIfDirty) noexcept
Check if a page can be evicted.
Definition: buffer_pool.cpp:411
bf_idx _idx
Definition: buffer_pool.hpp:1140
bf_idx getBlockCount() const noexcept
Number of buffer frames of this buffer pool.
Definition: buffer_pool.hpp:96
static const lsn_t null
Definition: lsn.h:371
PageID getMediaFailurePID() const noexcept
MG TODO.
Definition: buffer_pool.hpp:622
uint32_t bf_idx
Definition: basics.h:56
GenericPageIterator(PageID first, PageID count, bool virgin)
This essentially yields a "begin" iterator.
Definition: buffer_pool.hpp:1155
std::shared_ptr< Hashtable > _hashtable
Allows to locate pages by PageID.
Definition: buffer_pool.hpp:708
int _fix_depth
Definition: buffer_pool.hpp:1255
bool _maintainEMLSN
Maintain EMLSN of B-Tree pages.
Definition: buffer_pool.hpp:757
void setMediaFailure() noexcept
MG TODO.
Definition: buffer_pool.cpp:633
const w_rc_t & getOldStyleException() const noexcept
Definition: buffer_pool.hpp:1085
std::vector< bf_tree_cb_t, boost::alignment::aligned_allocator< bf_tree_cb_t, sizeof(bf_tree_cb_t)> > _controlBlocks
Array of control blocks.
Definition: buffer_pool.hpp:693
std::shared_ptr< page_cleaner_base > _cleaner
Cleans dirty pages.
Definition: buffer_pool.hpp:723
w_rc_t refixDirectOldSytleExceptions(generic_page *&targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional)
Definition: buffer_pool.cpp:274
Definition: w_error.h:45
bool _warmupDone
MG TODO.
Definition: buffer_pool.hpp:832
const char * what() const noexcept override
Definition: buffer_pool.hpp:1015
Page evictioner for the buffer pool.
Definition: page_evictioner.hpp:24
bool fix_current()
Definition: buffer_pool.hpp:1257
double _warmupHitRatio
Hit rate of a "warm" buffer pool.
Definition: buffer_pool.hpp:838
std::atomic< PageID > _mediaFailurePID
MG TODO.
Definition: buffer_pool.hpp:795
unsigned _warmupMinFixes
Minimum number of fixes of a "warm" buffer pool.
Definition: buffer_pool.hpp:844
uint32_t PageID
Definition: basics.h:45
void recoverIfNeeded(bf_tree_cb_t &controlBlock, generic_page *page, bool onlyIfDirty=true) noexcept
Recover buffered page if needed.
Definition: buffer_pool.cpp:524
Definition: bf_tree_cleaner.h:55
Log Sequence Number. See Log Sequence Numbers (LSN).
Definition: lsn.h:243
PageID begin_pid() const
Definition: buffer_pool.hpp:1236
pin_for_refix_holder & operator=(pin_for_refix_holder &h)
Definition: buffer_pool.hpp:1118
bool _logFetches
Log page fetches.
Definition: buffer_pool.hpp:814
void set_check_recovery(bool chk)
Definition: bf_tree_cb.h:269
BufferPoolTooLargeException(const bf_idx &blockCount)
Definition: buffer_pool.hpp:995
PageID _first
Definition: buffer_pool.hpp:1247
#define ERROUT(a)
Definition: w_debug.h:175
w_rc_t fixNonRootOldStyleExceptions(generic_page *&targetPage, generic_page *parentPage, PageID pid, latch_mode_t latchMode, bool conditional=false, bool virgin=false, bool onlyIfHit=false, bool doRecovery=true, lsn_t emlsn=lsn_t::null)
Definition: buffer_pool.cpp:215
void downgradeLatch(const generic_page *page) noexcept
Downgrade the latch of a page.
Definition: buffer_pool.cpp:354
const char * what() const noexcept override
Definition: buffer_pool.hpp:955
pin_for_refix_holder(bf_idx idx)
Definition: buffer_pool.hpp:1105
Return code for most functions and methods.
Definition: w_rc.h:87
void unpin_for_restore()
Definition: bf_tree_cb.h:133
bool hasDirtyFrames()
Whether this buffer pool has dirty buffer frames.
Definition: buffer_pool.cpp:133
generic_page * _current
Definition: buffer_pool.hpp:1253
void shutdown()
Shuts down this buffer pool.
Definition: buffer_pool.cpp:114
bf_tree_cb_t & getControlBlock(bf_idx index) noexcept
Returns the control block corresponding to a buffer pool index.
Definition: buffer_pool.hpp:307
bf_idx getRootIndex(StoreID store) const noexcept
The buffer pool index of a buffered B-Tree root page.
Definition: buffer_pool.hpp:361
bf_tree_cb_t & getControlBlock(const generic_page *page) noexcept
Returns the control block corresponding to a buffered page.
Definition: buffer_pool.hpp:327
friend void swap(GenericPageIterator &a, GenericPageIterator &b)
Definition: buffer_pool.hpp:1216
A buffer manager that exploits the tree structure of indexes.
Definition: buffer_pool.hpp:40
Definition: buffer_pool.hpp:950
Definition: restart.h:136
bool _asyncEviction
Use a dedicated thread for eviction.
Definition: buffer_pool.hpp:751
bool upgradeLatchConditional(const generic_page *page) noexcept
Upgrade the latch of a page.
Definition: buffer_pool.cpp:335
bool _fix(generic_page *parentPage, generic_page *&targetPage, PageID pid, latch_mode_t latchMode, bool conditional, bool virgin, bool onlyIfHit=false, bool doRecovery=true, lsn_t emlsn=lsn_t::null)
Fixes a page in this buffer pool.
Definition: buffer_pool.cpp:798
void unpinForRefix(bf_idx unpinIndex)
Unpin a page for re-fix.
Definition: buffer_pool.cpp:284
#define W_COERCE(x)
Call a function or method x, fail catastrophically if error is returned.
Definition: w_rc.h:349
void _setWarmupDone() noexcept
Sets this buffer pool to "warmed up".
Definition: buffer_pool.cpp:1198
pin_for_refix_holder(pin_for_refix_holder &h)
Definition: buffer_pool.hpp:1108
BufferPoolTooSmallException(const bf_idx &blockCount, const bf_idx &minimumBlockCount)
Definition: buffer_pool.hpp:972
bool isMediaFailure() const noexcept
Definition: buffer_pool.hpp:632
PageID end_pid() const
Definition: buffer_pool.hpp:1240
Select-and-Filter page evictioner for the buffer pool
Definition: page_evictioner_select_and_filter.hpp:53
std::shared_ptr< FreeListLowContention > _freeList
List of unused buffer frames.
Definition: buffer_pool.hpp:717
const bf_tree_cb_t & getControlBlock(bf_idx index) const noexcept
Returns the control block corresponding to a buffer pool index. noexcept
Definition: buffer_pool.hpp:312
bool isWarmupDone() const noexcept
Return whether this buffer pool is already "warmed up".
Definition: buffer_pool.hpp:125
void debugDumpPagePointers(std::ostream &o, generic_page *page) const
Dumps the pointers stored inside a page to an output stream.
Definition: buffer_pool.cpp:762
void fuzzyCheckpoint(chkpt_t &checkpoint) const noexcept
Creates a fuzzy checkpoint for this buffer pool.
Definition: buffer_pool.cpp:555
bf_idx getIndex(const generic_page *page) const noexcept
The buffer pool index of a buffered page.
Definition: buffer_pool.hpp:349
Definition: page_cleaner_decoupled.h:12
const std::shared_ptr< PAGE_EVICTIONER > getPageEvictioner() const noexcept
Returns the page evictioner of this buffer pool.
Definition: buffer_pool.cpp:331
std::shared_ptr< RestoreCoord > _restoreCoordinator
MG TODO.
Definition: buffer_pool.hpp:773
generic_page * operator*()
Definition: buffer_pool.hpp:1184
bool isMediaFailure(PageID pid) const noexcept
MG TODO.
Definition: buffer_pool.hpp:643
BufferPoolSizeException(const bf_idx &blockCount)
Definition: buffer_pool.hpp:952
Definition: buffer_pool.hpp:993
~GenericPageIterator()
Definition: buffer_pool.hpp:1179
void debugDump(std::ostream &o) const
Dumps some meta data of this buffer pool to an output stream.
Definition: buffer_pool.cpp:680
bool _instantRestore
Use instant restore.
Definition: buffer_pool.hpp:801
w_rc_t fixRootOldStyleExceptions(generic_page *&targetPage, StoreID store, latch_mode_t latchMode, bool conditional, bool virgin)
Definition: buffer_pool.cpp:199
PageID normalizePID(const PageID pid) const noexcept
Normalize a page ID.
Definition: buffer_pool.hpp:470
bool usesWriteElision() const noexcept
Whether this buffer pool uses write elision.
Definition: buffer_pool.hpp:114
latch_mode_t
Definition: latch.h:79
bool unswizzlePagePointer(generic_page *parentPage, general_recordid_t childSlotInParentPage, PageID *childPageID=nullptr)
Unswizzle a page pointer in a page&#39;s parent page.
Definition: buffer_pool.cpp:363
generic_page * _buffer
Array of buffered pages.
Definition: buffer_pool.hpp:700
Definition: buffer_pool.hpp:1100
bool operator==(GenericPageIterator &other)
Definition: buffer_pool.hpp:1225
void postInitialize()
Completes the initialization of this buffer pool.
Definition: buffer_pool.cpp:95
bool isNoDBMode() const noexcept
Whether this buffer pool is in NoDB mode.
Definition: buffer_pool.hpp:105
std::array< bf_idx, stnode_page::max > _rootPages
Buffer indexes of root pages.
Definition: buffer_pool.hpp:685
GenericPageIterator & operator=(GenericPageIterator other)
Definition: buffer_pool.hpp:1211
void refixDirect(generic_page *&targetPage, bf_idx refixIndex, latch_mode_t latchMode, bool conditional)
Re-fix a pinned page.
Definition: buffer_pool.cpp:247
bool _virgin
Definition: buffer_pool.hpp:1251
bool _noDBMode
Use NoDB.
Definition: buffer_pool.hpp:807
~pin_for_refix_holder()
Definition: buffer_pool.hpp:1112
static thread_local unsigned _hitCount
MG TODO.
Definition: buffer_pool.hpp:856
const char * what() const noexcept override
Definition: buffer_pool.hpp:998
void unfix(const generic_page *unfixPage, bool evict=false)
Unfixes a page in this buffer pool.
Definition: buffer_pool.cpp:303
bool operator!=(GenericPageIterator &other)
Definition: buffer_pool.hpp:1232
bf_idx _blockCount
Definition: buffer_pool.hpp:964
PageID _current_pid
Definition: buffer_pool.hpp:1242
bool _batchWarmup
MG TODO.
Definition: buffer_pool.hpp:826
Definition: buffer_pool.hpp:1143
const char * what() const noexcept override
Definition: buffer_pool.hpp:945
const uint16_t MAX_RCT_STACK_DEPTH
Constant to define maximum stack trace depth for w_rc_t.
Definition: w_rc.h:62
void switchParent(PageID childPID, generic_page *newParentPage) noexcept
Switch the parent page of a buffered B-Tree page in this buffer pool.
Definition: buffer_pool.cpp:598
Definition: buffer_pool_free_list.hpp:44
bf_idx _blockCount
Maximum number of pages in this buffer pool.
Definition: buffer_pool.hpp:677