21 #include <glog/logging.h>
44 numa_node_(numa_node),
46 snapshot_id_(snapshot_id),
47 pool_memory_(pool_memory),
48 intermediate_memory_(intermediate_memory),
49 snapshot_file_(nullptr),
57 bool closed = snapshot_file_->
close();
59 LOG(ERROR) <<
"Failed to close a snapshot file: " << *
this;
64 LOG(ERROR) <<
"Failed to fsync a snapshot file: " << *
this;
68 delete snapshot_file_;
69 snapshot_file_ =
nullptr;
76 fs::Path SnapshotWriter::get_snapshot_file_path()
const {
84 fs::Path path(get_snapshot_file_path());
86 bool create_new_file = append_ ?
false :
true;
90 char* first_page =
reinterpret_cast<char*
>(pool_memory_->
get_block());
95 first_page_header->
checksum_ = 0x1BF0ED05;
100 std::string duh(
"This is the first 4kb page of a snapshot file in libfoedus."
101 " The first page is never used as data. It just has the common page header"
102 " and these useless sentences. Maybe we put our complaints on our cafeteria here.");
110 LOG(INFO) <<
to_string() <<
" Appending to " << file_size <<
"th bytes";
135 ASSERT_ND(local_page_id == correct_local_page_id);
146 next_page_id_ += count;
175 o <<
"<SnapshotWriter>"
176 <<
"<numa_node_>" << v.numa_node_ <<
"</numa_node_>"
177 <<
"<append_>" << v.append_ <<
"</append_>"
178 <<
"<snapshot_id_>" << v.snapshot_id_ <<
"</snapshot_id_>"
179 <<
"<pool_memory_>" << *v.pool_memory_ <<
"</pool_memory_>"
180 <<
"<intermediate_memory_>" << *v.intermediate_memory_ <<
"</intermediate_memory_>"
181 <<
"<next_page_id_>" << v.next_page_id_ <<
"</next_page_id_>"
182 <<
"</SnapshotWriter>";
uint64_t SnapshotLocalPageId
Represents a local page ID in each one snapshot file in some NUMA node.
bool close()
Close the file and makes sure all writes become durable (including the directory entry).
SnapshotLocalPageId extract_local_page_id_from_snapshot_pointer(SnapshotPagePointer pointer)
ErrorCode expand_intermediate_memory(uint32_t required_pages, bool retain_content)
Expands intermediate_memory_ in case it is too small.
ErrorCode write(uint64_t desired_bytes, const foedus::memory::AlignedMemory &buffer)
Sequentially write the given amount of contents from the current position.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
foedus::fs::DeviceEmulationOptions emulation_
Settings to emulate slower data device.
SnapshotPagePointer to_snapshot_page_pointer(uint16_t snapshot_id, uint8_t node, SnapshotLocalPageId local_page_id)
bool close()
Close the file if not yet closed.
memory::PagePoolOffset get_page_size() const __attribute__((always_inline))
Brings error stacktrace information as return value of functions.
ErrorCode assure_capacity(uint64_t required_size, double expand_margin=2.0, bool retain_content=false) noexcept
If the current size is smaller than the given size, automatically expands.
ErrorCode open(bool read, bool write, bool append, bool create)
Tries to open the file for the specified volume.
uint64_t get_current_offset() const
const EngineOptions & get_options() const
ErrorStack open()
Open the file so that the writer can start writing.
Analogue of boost::filesystem::path.
snapshot::SnapshotOptions snapshot_
Database engine object that holds all resources and provides APIs.
memory::PagePoolOffset get_intermediate_size() const __attribute__((always_inline))
Just a marker to denote that the memory region represents a data page.
uint16_t extract_snapshot_id_from_snapshot_pointer(SnapshotPagePointer pointer)
A slice of foedus::memory::AlignedMemory.
void * get_block() const
Returns the memory block.
uint8_t extract_numa_node_from_snapshot_pointer(SnapshotPagePointer pointer)
uint64_t file_size(const Path &p)
Returns size of the file.
uint16_t SnapshotId
Unique ID of Snapshot.
std::string construct_snapshot_file_path(int snapshot_id, int node) const
'folder_path'/snapshot_'snapshot-id'node'node-id'.data.
uint64_t get_size() const
Returns the byte size of the memory block.
#define CHECK_ERROR_CODE(x)
This macro calls x and checks its returned error code.
Represents an I/O stream on one file without filesystem caching.
Represents one memory block aligned to actual OS/hardware pages.
const ErrorStack kRetOk
Normal return value for no-error case.
ErrorCode expand_pool_memory(uint32_t required_pages, bool retain_content)
Expands pool_memory_ in case it is too small.
PageHeader & get_header()
At least the basic header exists in all pages.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
#define WRAP_ERROR_CODE(x)
Same as CHECK_ERROR(x) except it receives only an error code, thus more efficient.
bool fsync(const Path &path, bool sync_parent_directory=false)
Makes the content and metadata of the file durable all the way up to devices.
ErrorCode
Enum of error codes defined in error_code.xmacro.
std::ostream & operator<<(std::ostream &o, const SortedBuffer &v)
Writes out one snapshot file for all data pages in one reducer.
std::string to_string() const