libfoedus-core
FOEDUS Core Library
page.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #include "foedus/storage/page.hpp"
19 
20 #include <glog/logging.h>
21 
22 #include <ostream>
23 
24 #include "foedus/engine.hpp"
27 #include "foedus/thread/thread.hpp"
28 #include "foedus/xct/xct.hpp"
29 
30 namespace foedus {
31 namespace storage {
32 
33 std::ostream& operator<<(std::ostream& o, const PageVersionStatus& v) {
34  o << "<PageVersionStatus><flags>"
35  << (v.is_moved() ? "M" : " ")
36  << (v.is_retired() ? "R" : " ")
37  << "</flags><ver>" << v.get_version_counter() << "</ver>"
38  << "</PageVersionStatus>";
39  return o;
40 }
41 
42 std::ostream& operator<<(std::ostream& o, const PageVersion& v) {
43  o << "<PageVersion><locked>"
44  << (v.is_locked() ? "L" : " ")
45  << (v.is_moved() ? "M" : " ")
46  << (v.is_retired() ? "R" : " ")
47  << "</locked>" << v.status_
48  << "</PageVersion>";
49  return o;
50 }
51 
52 std::ostream& operator<<(std::ostream& o, const PageHeader& v) {
53  o << "<PageHeader>";
54  o << std::endl << "<page_id>"
55  << "<raw>" << assorted::Hex(v.page_id_, 16) << "</raw>";
56  // Also write out interpreted version
57  if (v.snapshot_) {
59  } else {
60  VolatilePagePointer pointer;
61  pointer.word = v.page_id_;
62  describe_volatile_pointer(&o, pointer);
63  }
64  o << "</page_id>";
65  o << std::endl << "<storage_id_>" << v.storage_id_ << "</storage_id_>";
66  o << "<checksum_>" << v.checksum_ << "</checksum_>";
67  o << "<page_type_>" << static_cast<int>(v.page_type_) << "</page_type_>";
68  o << std::endl << "<snapshot_>" << v.snapshot_ << "</snapshot_>";
69  o << "<key_count_>" << v.key_count_ << "</key_count_>";
70  o << "<masstree_layer_>" << static_cast<int>(v.masstree_layer_) << "</masstree_layer_>";
71  o << "<masstree_in_layer_level_>" << static_cast<int>(v.masstree_in_layer_level_)
72  << "</masstree_in_layer_level_>";
73  o << "<hotness_>" << static_cast<int>(v.hotness_.value_) << "</hotness_>";
74  o << std::endl << "<stat_last_updater_node_>" << static_cast<int>(v.stat_last_updater_node_)
75  << "</stat_last_updater_node_>";
76  o << v.page_version_;
77  o << "</PageHeader>";
78  return o;
79 }
80 
83 }
84 
86  const memory::GlobalVolatilePageResolver& resolver,
87  const void* address) {
88  const Page* page = to_page(reinterpret_cast<const void*>(address));
89  ASSERT_ND(!page->get_header().snapshot_);
90 
92  ASSERT_ND(vpp.get_numa_node() < resolver.numa_node_count_);
93  ASSERT_ND(vpp.get_offset() >= resolver.begin_);
94  ASSERT_ND(vpp.get_offset() < resolver.end_);
95 
96  const Page* same_page = resolver.resolve_offset(vpp);
97  ASSERT_ND(same_page->get_header().page_id_ == page->get_header().page_id_);
98  ASSERT_ND(!same_page->get_header().snapshot_);
103  // const uintptr_t int_address = reinterpret_cast<uintptr_t>(address);
104  // ASSERT_ND(int_address >= base + vpp.components.offset * kPageSize);
105  // ASSERT_ND(int_address < base + (vpp.components.offset + 1U) * kPageSize);
106 }
107 
108 } // namespace storage
109 } // namespace foedus
xct::Xct & get_current_xct()
Returns the transaction that is currently running on this thread.
Definition: thread.cpp:75
storage::Page * resolve_offset(uint8_t numa_node, PagePoolOffset offset) const __attribute__((always_inline))
Resolves offset plus NUMA node ID to storage::Page*.
void describe_volatile_pointer(std::ostream *o, VolatilePagePointer pointer)
Definition: storage_id.cpp:44
Page * to_page(const void *address)
super-dirty way to obtain Page the address belongs to.
Definition: page.hpp:395
uint8_t page_type_
Actually of PageType.
Definition: page.hpp:205
bool is_retired() const __attribute__((always_inline))
Definition: page.hpp:140
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
uint8_t masstree_layer_
used only in masstree.
Definition: page.hpp:226
uint16_t numa_node_count_
number of NUMA nodes in this engine.
StorageId storage_id_
ID of the storage this page belongs to.
Definition: page.hpp:196
bool is_moved() const __attribute__((always_inline))
Definition: page.hpp:71
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
uint8_t value_
Log arithmic counter of aborts.
Just a synonym of XctId to be used as a page lock mechanism.
Definition: page.hpp:129
PagePoolOffset begin_
where a valid page entry starts.
PagePoolOffset end_
where a valid page entry ends.
bool contains_hot_records(thread::Thread *context)
Definition: page.cpp:81
bool is_moved() const __attribute__((always_inline))
Definition: page.hpp:139
uint8_t masstree_in_layer_level_
used only in masstree.
Definition: page.hpp:243
uint16_t key_count_
physical key count (those keys might be deleted) in this page.
Definition: page.hpp:219
uint16_t get_hot_threshold_for_this_xct() const
Definition: xct.hpp:128
void assert_within_valid_volatile_page_impl(const memory::GlobalVolatilePageResolver &resolver, const void *address)
Definition: page.cpp:85
Just a marker to denote that a memory region represents a data page.
Definition: page.hpp:184
Just a marker to denote that the memory region represents a data page.
Definition: page.hpp:334
PageVersion page_version_
Used in several storage types as concurrency control mechanism for the page.
Definition: page.hpp:272
uint32_t get_version_counter() const __attribute__((always_inline))
Definition: page.hpp:99
void describe_snapshot_pointer(std::ostream *o, SnapshotPagePointer pointer)
Definition: storage_id.cpp:27
Checksum checksum_
Checksum of the content of this page to detect corrupted pages.
Definition: page.hpp:202
PageVersionStatus status_
Definition: page.hpp:172
VolatilePagePointer construct_volatile_page_pointer(uint64_t word)
Definition: storage_id.hpp:230
Convenient way of writing hex integers to stream.
uint8_t stat_last_updater_node_
A loosely maintained statistics for volatile pages.
Definition: page.hpp:251
Resolves an offset in a volatile page pool to an actual pointer and vice versa.
PageHeader & get_header()
At least the basic header exists in all pages.
Definition: page.hpp:336
std::ostream & operator<<(std::ostream &o, const Composer &v)
Definition: composer.cpp:39
bool is_retired() const __attribute__((always_inline))
Definition: page.hpp:72
assorted::ProbCounter hotness_
Loosely maintained statistics on data temperature.
Definition: page.hpp:268
bool snapshot_
Whether this page image is of a snapshot page.
Definition: page.hpp:211
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
bool is_locked() const __attribute__((always_inline))
Definition: page.hpp:138
uint64_t page_id_
Page ID of this page.
Definition: page.hpp:191