libfoedus-core
FOEDUS Core Library
hash_record_location.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  */
19 
21 #include "foedus/xct/xct.hpp"
22 
23 namespace foedus {
24 namespace storage {
25 namespace hash {
26 
28  xct::Xct* cur_xct,
29  HashDataPage* page,
30  DataPageSlotIndex index,
31  bool intended_for_write) {
32  page_ = page;
33  index_ = index;
34  readset_ = nullptr;
35 
36  HashDataPage::Slot* slot = page->get_slot_address(index);
37  record_ = page->record_from_offset(slot->offset_);
38  key_length_ = slot->key_length_; // key_length is immutable, so just read it.
39  physical_record_length_ = slot->physical_record_length_; // immutable, too.
40 
41  // cur_payload_length_ is mutable, so must be retrieved _as of_ the XID.
42  // we thus need a retry loop.
43  while (true) {
44  xct::XctId before = slot->tid_.xct_id_;
48 
49  // [Logical check]: Read XID in a finalized fashion. If we found it "moved",
50  // then we don't need to remember it as read-set.
52  intended_for_write,
53  &slot->tid_,
54  &observed_,
55  &readset_,
56  true, // no_readset_if_moved. see below
57  true)); // no_readset_if_next_layer. see below
58 
60  ASSERT_ND(!observed_.is_next_layer()); // we don't use this flag in hash. never occurs
62 
63  if (observed_ == before) {
64  // The consume fences make sure we are seeing in this order.
65  // 1. read "before"
66  // 2. read payload_length_
67  // 3. read observed_
68  // thus, observed==before guarantees that payload_length_ is *as of* observed_.
69  break;
70  }
71  }
72 
73  if (observed_.is_moved()) {
74  ASSERT_ND(readset_ == nullptr);
75  }
76  return kErrorCodeOk;
77 }
78 
80  page_ = page;
81  index_ = index;
82  readset_ = nullptr;
83 
84  HashDataPage::Slot* slot = page->get_slot_address(index);
85  cur_payload_length_ = slot->payload_length_; // no worry on physical-only read.
86  key_length_ = slot->key_length_;
88  record_ = page->record_from_offset(slot->offset_);
91  ASSERT_ND(!observed_.is_next_layer()); // we don't use this flag in hash. never occurs
93 }
94 
95 
96 } // namespace hash
97 } // namespace storage
98 } // namespace foedus
uint16_t physical_record_length_
Byte count the record of the slot occupies, which is immutable.
xct::RwLockableXctId tid_
TID of the record.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
uint16_t payload_length_
Byte length of the payload.
ErrorCode on_record_read(bool intended_for_write, RwLockableXctId *tid_address, XctId *observed_xid, ReadXctAccess **read_set_address, bool no_readset_if_moved=false, bool no_readset_if_next_layer=false)
The general logic invoked for every record read.
Definition: xct.cpp:258
Represents a user transaction.
Definition: xct.hpp:58
Persistent status part of Transaction ID.
Definition: xct_id.hpp:955
XctId xct_id_
the second 64bit: Persistent status part of TID.
Definition: xct_id.hpp:1137
ErrorCode populate_logical(xct::Xct *cur_xct, HashDataPage *page, DataPageSlotIndex index, bool intended_for_write)
Populates the result with XID and possibly readset.
bool is_valid() const __attribute__((always_inline))
Definition: xct_id.hpp:973
HashDataPage * page_
The data page (might not be bin-head) containing the record.
uint16_t key_length_
Byte length of key of the record.
const Slot * get_slot_address(DataPageSlotIndex record) const __attribute__((always_inline))
same as &get_slot(), but this is more explicit and easier to understand/maintain
char * record_
Address of the record.
0 means no-error.
Definition: error_code.hpp:87
uint16_t key_length_
Key length of the slot, which is immutable.
uint16_t cur_payload_length_
Logical payload length as-of the observed XID.
Fix-sized slot for each record, which is placed at the end of data region.
bool is_next_layer() const __attribute__((always_inline))
Definition: xct_id.hpp:1042
uint16_t DataPageSlotIndex
Definition: hash_id.hpp:196
uint16_t physical_record_length_
Byte count this record occupies.
void populate_physical(HashDataPage *page, DataPageSlotIndex index)
Populates fields other than readset_.
char * record_from_offset(uint16_t offset)
#define CHECK_ERROR_CODE(x)
This macro calls x and checks its returned error code.
Definition: error_code.hpp:155
Represents an individual data page in Hashtable Storage.
xct::XctId observed_
TID as of locate_record() identifying the record.
bool is_being_written() const __attribute__((always_inline))
Definition: xct_id.hpp:1038
XctId spin_while_being_written() const __attribute__((always_inline))
Returns a version of this Xid whose being_written flag is off.
Definition: xct_id.hpp:1190
void memory_fence_consume()
Equivalent to std::atomic_thread_fence(std::memory_order_consume).
xct::ReadXctAccess * readset_
If this method took a read-set on the returned record, points to the corresponding read-set...
bool is_moved() const __attribute__((always_inline))
Definition: xct_id.hpp:1041
#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
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
DataPageSlotIndex index_
Index of the record in the page.
uint16_t offset_
Byte offset in data_ where this record starts.