18 #ifndef FOEDUS_STORAGE_MASSTREE_MASSTREE_CURSOR_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_CURSOR_HPP_
151 return order_[index];
196 bool forward_cursor =
true,
197 bool for_writes =
false,
198 bool begin_inclusive =
true,
199 bool end_inclusive =
false);
204 bool forward_cursor =
true,
205 bool for_writes =
false,
206 bool begin_inclusive =
true,
207 bool end_inclusive =
false) {
208 ASSERT_ND((forward_cursor && end_key >= begin_key) ||
209 (!forward_cursor && end_key <= begin_key));
210 KeySlice begin_key_be = assorted::htobe<KeySlice>(begin_key);
211 KeySlice end_key_be = assorted::htobe<KeySlice>(end_key);
213 reinterpret_cast<const char*>(&begin_key_be),
215 reinterpret_cast<const char*>(&end_key_be),
224 return route_count_ > 0 && !reached_end_ && cur_route()->
is_valid_record();
229 return cur_key_length_;
236 return cur_route_prefix_slices_;
240 return cur_route_prefix_be_;
245 return cur_key_in_layer_slice_;
250 return cur_key_suffix_;
256 return cur_key_in_layer_slice_;
283 return std::string(buf, cur_key_length_);
292 return cur_payload_length_;
314 template <
typename PAYLOAD>
319 template <
typename PAYLOAD>
329 bool forward_cursor_;
341 bool search_key_in_layer_extremum_;
344 uint16_t route_count_;
358 bool should_skip_cur_route_;
360 bool cur_key_next_layer_;
383 char* cur_route_prefix_be_;
389 const char* cur_key_suffix_;
392 const char* cur_payload_;
415 void check_end_key();
422 const char* full_key,
431 return cur_route()->
page_;
436 return routes_ + route_count_ - 1;
440 return routes_ + route_count_ - 1;
443 template <
typename T>
444 ErrorCode allocate_if_not_exist(T** pointer);
499 void proceed_route_intermediate_rebase_separator();
501 void set_should_skip_cur_route();
503 MasstreePage* resolve_volatile(VolatilePagePointer ptr)
const;
505 void assert_modify() const ALWAYS_INLINE {
511 ASSERT_ND(reinterpret_cast<Page*>(get_cur_page())->get_header().get_page_type()
515 void assert_route() const ALWAYS_INLINE {
520 void assert_route_impl()
const;
526 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_CURSOR_HPP_
const char * get_payload() const __attribute__((always_inline))
MovedPageSearchStatus moved_page_search_status_
only when stable_ indicates that this page is a moved page
This means either was_stably_moved() is false or it's intermediate page, in which case we don't neeed...
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definitions of IDs in this package and a few related constant values.
ErrorCode overwrite_record_primitive(PAYLOAD payload, PayloadLength payload_offset)
uint16_t SlotIndex
Index of a record in a (border) page.
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
KeySlice get_normalized_key() const __attribute__((always_inline))
This method assumes the key length is at most 8 bytes.
const KeyLength kMaxKeyLength
Max length of a key.
std::string get_combined_key() const __attribute__((always_inline))
For even handier use, it returns std::string.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
SlotIndex index_
index in ordered keys.
Represents one thread running on one NUMA core.
bool is_moved() const __attribute__((always_inline))
ErrorCode next()
Moves the cursor to next record.
Represents a user transaction.
ErrorCode open(const char *begin_key=nullptr, KeyLength begin_key_length=kKeyLengthExtremum, const char *end_key=nullptr, KeyLength end_key_length=kKeyLengthExtremum, bool forward_cursor=true, bool for_writes=false, bool begin_inclusive=true, bool end_inclusive=false)
Represents one border page in Masstree Storage.
void copy_combined_key(char *buffer) const
Copies the entire big-endian key of the current record to the given buffer.
uint64_t KeySlice
Each key slice is an 8-byte integer.
Definitions of IDs in this package and a few related constant values.
uint16_t KeyLength
Represents a byte-length of a key in this package.
A few macros and helper methods related to byte endian-ness.
Common base of MasstreeIntermediatePage and MasstreeBorderPage.
const char * get_cur_route_prefix_be() const __attribute__((always_inline))
Big-endian version.
KeySlice latest_separator_
Upto which separator we are done.
Represents one page in the current search path from layer0-root.
void copy_combined_key_part(KeyLength offset, KeyLength len, char *buffer) const
Another version to get a part of the key, from the offset for len bytes.
The MCS reader-writer lock variant of LockableXctId.
SlotIndex get_cur_original_index() const __attribute__((always_inline))
uint8_t Layer
Represents the depth of a B-trie layer.
bool is_valid_record() const __attribute__((always_inline))
SlotIndex index_mini_
only for interior.
Forward declarations of classes in storage package.
Definitions of IDs in this package and a few related constant values.
PayloadLength get_payload_length() const __attribute__((always_inline))
SlotIndex get_original_index(SlotIndex index) const __attribute__((always_inline))
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
bool is_forward_cursor() const
MasstreeStorage & get_storage()
Database engine object that holds all resources and provides APIs.
const SlotIndex kBorderPageMaxSlots
Maximum number of slots in one MasstreeBorderPage.
bool is_next_layer() const __attribute__((always_inline))
Represents a Masstree storage.
SlotIndex key_count_mini_
only for interior.
ErrorCode open_normalized(KeySlice begin_key, KeySlice end_key, bool forward_cursor=true, bool for_writes=false, bool begin_inclusive=true, bool end_inclusive=false)
MasstreeCursor(MasstreeStorage storage, thread::Thread *context)
bool is_for_writes() const
PageVersionStatus stable_
version as of calculating order_.
KeySlice get_key_in_layer_slice() const __attribute__((always_inline))
Returns only the slice of the key in the layer of the current page.
KeyLength get_key_length() const __attribute__((always_inline))
Returns the length of the whole key we are currently pointing to.
SlotIndex key_count_
same as stable_.get_key_count()
Layer layer_
Shorthand for page_->get_layer()
SlotIndex order_[kBorderPageMaxSlots]
only for border.
const KeySlice * get_cur_route_prefix_slices() const __attribute__((always_inline))
Returns the prefix slices upto the current page.
Represents a cursor object for Masstree storage.
Forward declarations of classes in masstree storage package.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
ErrorCode overwrite_record(const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
ErrorCode delete_record()
Forward declarations of classes in thread package.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
thread::Thread * get_context()
xct::XctId observed_
TID as of locate_record() identifying the record.
return value of MasstreeStoragePimpl::locate_record()/reserve_record().
bool snapshot_
whether page_ is a snapshot page
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
ErrorCode
Enum of error codes defined in error_code.xmacro.
ErrorCode increment_record(PAYLOAD *value, PayloadLength payload_offset)
bool was_stably_moved() const
In almost all places of the cursor code, we check is_moved() only on the stable version so that the c...
bool is_valid_record() const __attribute__((always_inline))
const char * get_key_suffix() const __attribute__((always_inline))
Returns the suffix part of the key in the page.