libfoedus-core
FOEDUS Core Library
foedus::storage::hash::ComposedBinsBuffer Struct Referencefinal

Abstracts how we batch-read several HashComposedBinsPage emit from individual composers. More...

Detailed Description

Abstracts how we batch-read several HashComposedBinsPage emit from individual composers.

This buffer is instantiated for each child of each HashRootInfoPage, which has several HashComposedBinsPage contiguously. We batch-read them to reduce I/O.

Definition at line 118 of file hash_composed_bins_impl.hpp.

#include <hash_composed_bins_impl.hpp>

Collaboration diagram for foedus::storage::hash::ComposedBinsBuffer:

Public Types

enum  Constants { kMinBufferSize = 1 << 6 }
 

Public Member Functions

void init (cache::SnapshotFileSet *fileset, SnapshotPagePointer head_page_id, uint32_t total_pages, uint32_t buffer_size, HashComposedBinsPage *buffer)
 
ErrorCode next_pages ()
 Read pages to buffer_. More...
 
ErrorCode next_bin () __attribute__((always_inline))
 Moves on to next bin. More...
 
const HashComposedBinsPageget_cur_page () const __attribute__((always_inline))
 
const ComposedBinget_cur_bin () const __attribute__((always_inline))
 
bool has_more () const
 

Static Public Member Functions

static void assure_read_buffer_size (memory::AlignedMemory *read_buffer, uint32_t inputs)
 If needed, expand the given read buffer to be used with the inputs. More...
 

Public Attributes

cache::SnapshotFileSetfileset_
 file handles More...
 
SnapshotPagePointer head_page_id_
 Page ID of the head of HashComposedBinsPage for this sub-tree. More...
 
uint32_t total_pages_
 Number of HashComposedBinsPage from head_page_id_ contiguously emit by a composer. More...
 
uint32_t buffer_size_
 How many pages buffer_ can hold. More...
 
uint32_t buffer_pos_
 index (0=head, total_pages_ - 1=tail, ) of the first page in the buffer_. More...
 
uint32_t buffer_count_
 number of pages so far read in the buffer_. More...
 
uint32_t cursor_buffer_
 Cursor position for page in the buffer. More...
 
uint16_t cursor_bin_
 Cursor position for bin in the current page. More...
 
uint16_t cursor_bin_count_
 Number of active bins in the current page. More...
 
HashComposedBinsPagebuffer_
 The buffer to read contiguous pages in one shot. More...
 

Member Enumeration Documentation

Member Function Documentation

void foedus::storage::hash::ComposedBinsBuffer::assure_read_buffer_size ( memory::AlignedMemory read_buffer,
uint32_t  inputs 
)
static

If needed, expand the given read buffer to be used with the inputs.

We split the one read buffer for inputs, so each input might not receive a large enough buffer to read HashComposedBinsPage.

Definition at line 74 of file hash_composed_bins_impl.cpp.

References ASSERT_ND, foedus::memory::AlignedMemory::assure_capacity(), foedus::memory::AlignedMemory::get_size(), kMinBufferSize, and foedus::storage::kPageSize.

Referenced by foedus::storage::hash::ComposedBinsMergedStream::init().

76  {
77  // split read_buffer_ to each input
78  read_buffer->assure_capacity(
79  kPageSize * kMinBufferSize * inputs,
80  2.0,
81  false);
82  uint32_t total_size = read_buffer->get_size() / kPageSize;
83  uint32_t buffer_size = total_size / inputs;
84  ASSERT_ND(buffer_size >= kMinBufferSize);
85 }
#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
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
Definition: storage_id.hpp:45

Here is the call graph for this function:

Here is the caller graph for this function:

const ComposedBin& foedus::storage::hash::ComposedBinsBuffer::get_cur_bin ( ) const
inline
Returns
the bin the cursor is currently on
Precondition
has_more()

Definition at line 190 of file hash_composed_bins_impl.hpp.

References ASSERT_ND, foedus::storage::hash::HashComposedBinsPage::bins_, cursor_bin_, get_cur_page(), and has_more().

Referenced by foedus::storage::hash::ComposedBinsMergedStream::init(), and foedus::storage::hash::ComposedBinsMergedStream::process_a_bin().

190  {
191  ASSERT_ND(has_more());
192  ASSERT_ND(cursor_bin_count_ == get_cur_page().bin_count_);
194  return get_cur_page().bins_[cursor_bin_];
195  }
uint16_t cursor_bin_count_
Number of active bins in the current page.
ComposedBin bins_[kHashComposedBinsPageMaxBins]
uint16_t cursor_bin_
Cursor position for bin in the current page.
const HashComposedBinsPage & get_cur_page() const __attribute__((always_inline))
#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

Here is the call graph for this function:

Here is the caller graph for this function:

const HashComposedBinsPage& foedus::storage::hash::ComposedBinsBuffer::get_cur_page ( ) const
inline
Returns
the page the cursor is currently on
Precondition
has_more()

Definition at line 183 of file hash_composed_bins_impl.hpp.

References cursor_buffer_.

Referenced by get_cur_bin().

183  {
184  return buffer_[cursor_buffer_];
185  }
HashComposedBinsPage * buffer_
The buffer to read contiguous pages in one shot.
uint32_t cursor_buffer_
Cursor position for page in the buffer.

Here is the caller graph for this function:

bool foedus::storage::hash::ComposedBinsBuffer::has_more ( ) const
inline

Definition at line 196 of file hash_composed_bins_impl.hpp.

References total_pages_.

Referenced by get_cur_bin(), foedus::storage::hash::ComposedBinsMergedStream::init(), and foedus::storage::hash::ComposedBinsMergedStream::process_a_bin().

196 { return buffer_pos_ < total_pages_; }
uint32_t total_pages_
Number of HashComposedBinsPage from head_page_id_ contiguously emit by a composer.
uint32_t buffer_pos_
index (0=head, total_pages_ - 1=tail, ) of the first page in the buffer_.

Here is the caller graph for this function:

void foedus::storage::hash::ComposedBinsBuffer::init ( cache::SnapshotFileSet fileset,
SnapshotPagePointer  head_page_id,
uint32_t  total_pages,
uint32_t  buffer_size,
HashComposedBinsPage buffer 
)

Definition at line 33 of file hash_composed_bins_impl.cpp.

References buffer_, buffer_count_, buffer_pos_, buffer_size_, cursor_bin_, cursor_bin_count_, cursor_buffer_, fileset_, head_page_id_, and total_pages_.

Referenced by foedus::storage::hash::ComposedBinsMergedStream::init().

38  {
39  fileset_ = fileset;
40  head_page_id_ = head_page_id;
41  total_pages_ = total_pages;
42  buffer_size_ = buffer_size;
43  buffer_pos_ = 0;
44  buffer_count_ = 0;
45  cursor_buffer_ = 0;
46  cursor_bin_ = 0;
48  buffer_ = buffer;
49 }
SnapshotPagePointer head_page_id_
Page ID of the head of HashComposedBinsPage for this sub-tree.
uint16_t cursor_bin_count_
Number of active bins in the current page.
uint32_t total_pages_
Number of HashComposedBinsPage from head_page_id_ contiguously emit by a composer.
uint32_t buffer_size_
How many pages buffer_ can hold.
uint32_t buffer_pos_
index (0=head, total_pages_ - 1=tail, ) of the first page in the buffer_.
uint32_t buffer_count_
number of pages so far read in the buffer_.
HashComposedBinsPage * buffer_
The buffer to read contiguous pages in one shot.
uint16_t cursor_bin_
Cursor position for bin in the current page.
cache::SnapshotFileSet * fileset_
file handles
uint32_t cursor_buffer_
Cursor position for page in the buffer.

Here is the caller graph for this function:

ErrorCode foedus::storage::hash::ComposedBinsBuffer::next_bin ( )
inline

Moves on to next bin.

Definition at line 268 of file hash_composed_bins_impl.hpp.

References foedus::storage::hash::HashComposedBinsPage::bin_count_, buffer_, buffer_count_, cursor_bin_, cursor_bin_count_, cursor_buffer_, foedus::kErrorCodeOk, LIKELY, and next_pages().

Referenced by foedus::storage::hash::ComposedBinsMergedStream::process_a_bin().

268  {
269  if (LIKELY(cursor_bin_ + 1U < cursor_bin_count_)) {
270  ++cursor_bin_;
271  return kErrorCodeOk;
272  } else if (LIKELY(cursor_buffer_ + 1U < buffer_count_)) {
273  ++cursor_buffer_;
274  cursor_bin_ = 0;
276  return kErrorCodeOk;
277  } else {
278  return next_pages();
279  }
280 }
uint16_t cursor_bin_count_
Number of active bins in the current page.
#define LIKELY(x)
Hints that x is highly likely true.
Definition: compiler.hpp:103
0 means no-error.
Definition: error_code.hpp:87
ErrorCode next_pages()
Read pages to buffer_.
uint32_t buffer_count_
number of pages so far read in the buffer_.
HashComposedBinsPage * buffer_
The buffer to read contiguous pages in one shot.
uint16_t cursor_bin_
Cursor position for bin in the current page.
uint32_t cursor_buffer_
Cursor position for page in the buffer.

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorCode foedus::storage::hash::ComposedBinsBuffer::next_pages ( )

Read pages to buffer_.

This doesn't return error even when buffer_pos_ + buffer_cursor_count_ ==total_pages_, in which case this method does nothing. Use has_more() to check for that.

Precondition
cursor_bin_ == cursor_bin_count_, otherwise you are skipping some bin
cursor_buffer_ == buffer_count_, otherwise you are skipping some page

Definition at line 51 of file hash_composed_bins_impl.cpp.

References ASSERT_ND, foedus::storage::hash::HashComposedBinsPage::bin_count_, buffer_, buffer_count_, buffer_pos_, buffer_size_, CHECK_ERROR_CODE, cursor_bin_, cursor_bin_count_, cursor_buffer_, fileset_, head_page_id_, foedus::kErrorCodeOk, foedus::cache::SnapshotFileSet::read_pages(), and total_pages_.

Referenced by next_bin().

51  {
54  uint32_t previous_end = buffer_pos_ + buffer_count_;
55  uint32_t pages_to_read = std::min<uint32_t>(buffer_size_, total_pages_ - previous_end);
56  SnapshotPagePointer read_from = head_page_id_ + previous_end;
57  CHECK_ERROR_CODE(fileset_->read_pages(read_from, pages_to_read, buffer_));
58  buffer_pos_ = previous_end;
59  buffer_count_ = pages_to_read;
60  cursor_buffer_ = 0;
61  cursor_bin_ = 0;
64  } else {
66  buffer_count_ = 0;
67  cursor_buffer_ = 0;
68  cursor_bin_ = 0;
70  }
71  return kErrorCodeOk;
72 }
SnapshotPagePointer head_page_id_
Page ID of the head of HashComposedBinsPage for this sub-tree.
uint16_t cursor_bin_count_
Number of active bins in the current page.
uint32_t total_pages_
Number of HashComposedBinsPage from head_page_id_ contiguously emit by a composer.
uint32_t buffer_size_
How many pages buffer_ can hold.
0 means no-error.
Definition: error_code.hpp:87
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Definition: storage_id.hpp:79
uint32_t buffer_pos_
index (0=head, total_pages_ - 1=tail, ) of the first page in the buffer_.
ErrorCode read_pages(storage::SnapshotPagePointer page_id_begin, uint32_t page_count, void *out)
Read contiguous pages in one shot.
uint32_t buffer_count_
number of pages so far read in the buffer_.
HashComposedBinsPage * buffer_
The buffer to read contiguous pages in one shot.
#define CHECK_ERROR_CODE(x)
This macro calls x and checks its returned error code.
Definition: error_code.hpp:155
uint16_t cursor_bin_
Cursor position for bin in the current page.
cache::SnapshotFileSet * fileset_
file handles
#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
uint32_t cursor_buffer_
Cursor position for page in the buffer.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

HashComposedBinsPage* foedus::storage::hash::ComposedBinsBuffer::buffer_

The buffer to read contiguous pages in one shot.

Definition at line 153 of file hash_composed_bins_impl.hpp.

Referenced by init(), next_bin(), and next_pages().

uint32_t foedus::storage::hash::ComposedBinsBuffer::buffer_count_

number of pages so far read in the buffer_.

upto total_pages_.

Definition at line 136 of file hash_composed_bins_impl.hpp.

Referenced by init(), next_bin(), and next_pages().

uint32_t foedus::storage::hash::ComposedBinsBuffer::buffer_pos_

index (0=head, total_pages_ - 1=tail, ) of the first page in the buffer_.

When there is no more page to read, total_pages_.

Definition at line 134 of file hash_composed_bins_impl.hpp.

Referenced by init(), and next_pages().

uint32_t foedus::storage::hash::ComposedBinsBuffer::buffer_size_

How many pages buffer_ can hold.

Definition at line 129 of file hash_composed_bins_impl.hpp.

Referenced by init(), and next_pages().

uint16_t foedus::storage::hash::ComposedBinsBuffer::cursor_bin_

Cursor position for bin in the current page.

Invariant
cursor_bin_ <= cursor_bin_count_

Definition at line 148 of file hash_composed_bins_impl.hpp.

Referenced by get_cur_bin(), init(), next_bin(), and next_pages().

uint16_t foedus::storage::hash::ComposedBinsBuffer::cursor_bin_count_

Number of active bins in the current page.

Definition at line 150 of file hash_composed_bins_impl.hpp.

Referenced by init(), next_bin(), and next_pages().

uint32_t foedus::storage::hash::ComposedBinsBuffer::cursor_buffer_

Cursor position for page in the buffer.

Invariant
cursor_buffer_ <= buffer_count_

Definition at line 142 of file hash_composed_bins_impl.hpp.

Referenced by get_cur_page(), init(), next_bin(), and next_pages().

cache::SnapshotFileSet* foedus::storage::hash::ComposedBinsBuffer::fileset_

file handles

Definition at line 123 of file hash_composed_bins_impl.hpp.

Referenced by init(), and next_pages().

SnapshotPagePointer foedus::storage::hash::ComposedBinsBuffer::head_page_id_

Page ID of the head of HashComposedBinsPage for this sub-tree.

Definition at line 125 of file hash_composed_bins_impl.hpp.

Referenced by init(), and next_pages().

uint32_t foedus::storage::hash::ComposedBinsBuffer::total_pages_

Number of HashComposedBinsPage from head_page_id_ contiguously emit by a composer.

Definition at line 127 of file hash_composed_bins_impl.hpp.

Referenced by has_more(), init(), and next_pages().


The documentation for this struct was generated from the following files: