Zero  0.1.0
logrec_support.h
Go to the documentation of this file.
1 #ifndef __LOGREC_SUPPORT_H
2 #define __LOGREC_SUPPORT_H
3 
4 #include "lock.h"
5 #include "btree_page.h"
6 #include "alloc_page.h"
7 #include "stnode_page.h"
8 
18 template<class PagePtr>
21 
22  size_t ending_bytes;
23 
24  char data[logrec_t::max_data_sz - 2 * sizeof(size_t)];
25 
26  int size() {
27  return 2 * sizeof(size_t) + beginning_bytes + ending_bytes;
28  }
29 
30  page_img_format_t(const PagePtr p) {
31  /*
32  * The mid-section of a btree page is usually not used, since head
33  * entries are stored on the beginning of the page and variable-sized
34  * "bodies" (i.e., key-value data) at the end of the page. This method
35  * returns a pointer to the beginning of the unused part and its length.
36  * The loc record then just contains the parts before and after the
37  * unused section. For pages other than btree ones, the unused part
38  * is either at the beginning or at the end of the page, and it must
39  * be set to zero when replaying the log record.
40  */
41 
42  size_t unused_length;
43  char* unused;
44  switch (p->tag()) {
45  case t_alloc_p: {
46  auto page = reinterpret_cast<alloc_page*>(p->get_generic_page());
47  unused = page->unused_part(unused_length);
48  break;
49  }
50  case t_stnode_p: {
51  auto page = reinterpret_cast<stnode_page*>(p->get_generic_page());
52  unused = page->unused_part(unused_length);
53  break;
54  }
55  case t_btree_p: {
56  auto page = reinterpret_cast<btree_page*>(p->get_generic_page());
57  unused = page->unused_part(unused_length);
58  break;
59  }
60  default:
61  W_FATAL(eNOTIMPLEMENTED);
62  }
63 
64  const char* pp_bin = (const char*)p->get_generic_page();
65  beginning_bytes = unused - pp_bin;
66  ending_bytes = sizeof(generic_page) - (beginning_bytes + unused_length);
67 
68  ::memcpy(data, pp_bin, beginning_bytes);
69  ::memcpy(data + beginning_bytes, unused + unused_length, ending_bytes);
70  // w_assert1(beginning_bytes >= btree_page::hdr_sz);
71  w_assert1(beginning_bytes + ending_bytes <= sizeof(generic_page));
72  }
73 
74  void apply(PagePtr page) {
75  // w_assert1(beginning_bytes >= btree_page::hdr_sz);
76  w_assert1(beginning_bytes + ending_bytes <= sizeof(generic_page));
77  char* pp_bin = (char*)page->get_generic_page();
78  ::memcpy(pp_bin, data, beginning_bytes);
79  ::memcpy(pp_bin + sizeof(generic_page) - ending_bytes,
80  data + beginning_bytes, ending_bytes);
81  }
82 };
83 
84 #endif // __LOGREC_SUPPORT_H
#define w_assert1(x)
Level 1 should not add significant extra time.
Definition: w_base.h:198
size_t ending_bytes
Definition: logrec_support.h:22
page_img_format_t(const PagePtr p)
Definition: logrec_support.h:30
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
int size()
Definition: logrec_support.h:26
char * unused_part(size_t &length)
Definition: alloc_page.h:87
char * unused_part(size_t &length)
Definition: btree_page.cpp:477
Definition: logrec_support.h:19
size_t beginning_bytes
Definition: logrec_support.h:20
free-page allocation page
Definition: generic_page.h:88
Definition: logrec.h:259
btree page
Definition: generic_page.h:90
Free-page allocation/deallocation page.
Definition: alloc_page.h:28
char * unused_part(size_t &length)
Definition: stnode_page.h:100
char data[logrec_t::max_data_sz - 2 *sizeof(size_t)]
Definition: logrec_support.h:24
Store-node page that contains one stnode_t for each (possibly deleted or uncreated) store belonging t...
Definition: stnode_page.h:59
store node page
Definition: generic_page.h:89
void apply(PagePtr page)
Definition: logrec_support.h:74
B-tree page.
Definition: btree_page.h:518
#define W_FATAL(e)
Croak with the error code e.
Definition: w_rc.h:378