libfoedus-core
FOEDUS Core Library
|
Represents an I/O stream on one file without filesystem caching. More...
Represents an I/O stream on one file without filesystem caching.
This class bypasses filesystem caching for disk I/O for three purposes.
This class is used for two kinds of files.
Definition at line 48 of file direct_io_file.hpp.
#include <direct_io_file.hpp>
Public Types | |
enum | Constants { kInvalidDescriptor = -1 } |
Constant values. More... | |
enum | SeekType { kDirectIoSeekSet = 0, kDirectIoSeekCur, kDirectIoSeekEnd } |
Analogue of SEEK_SET/SEEK_CUR/SEEK_END in POSIX. More... | |
typedef int | file_descriptor |
Represents low-level file descriptor. More... | |
Public Member Functions | |
DirectIoFile (const Path &path, const DeviceEmulationOptions &emulation=DeviceEmulationOptions()) | |
Constructs this object without opening it yet. More... | |
~DirectIoFile () | |
Automatically closes the file if it is opened. More... | |
DirectIoFile ()=delete | |
DirectIoFile (const DirectIoFile &)=delete | |
DirectIoFile & | operator= (const DirectIoFile &)=delete |
ErrorCode | open (bool read, bool write, bool append, bool create) |
Tries to open the file for the specified volume. More... | |
bool | is_opened () const |
Whether the file is already and successfully opened. More... | |
bool | close () |
Close the file if not yet closed. More... | |
ErrorCode | read (uint64_t desired_bytes, foedus::memory::AlignedMemory *buffer) |
Sequentially read the given amount of contents from the current position. More... | |
ErrorCode | read (uint64_t desired_bytes, const foedus::memory::AlignedMemorySlice &slice) |
Memory slice version. More... | |
ErrorCode | read_raw (uint64_t desired_bytes, void *buffer) |
A version that receives a raw pointer that has to be aligned (be careful to use this ver). More... | |
ErrorCode | write (uint64_t desired_bytes, const foedus::memory::AlignedMemory &buffer) |
Sequentially write the given amount of contents from the current position. More... | |
ErrorCode | write (uint64_t desired_bytes, const foedus::memory::AlignedMemorySlice &slice) |
Memory slice version. More... | |
ErrorCode | write_raw (uint64_t desired_bytes, const void *buffer) |
A version that receives a raw pointer that has to be aligned (be careful to use this ver). More... | |
ErrorCode | truncate (uint64_t new_length, bool sync=false) |
Discard the content of the file after the given offset. More... | |
ErrorCode | seek (uint64_t offset, SeekType seek_type) |
Sets the position of the next byte to be written/extracted from/to the stream. More... | |
ErrorCode | sync () |
Analogues of POSIX fsync(). More... | |
Path | get_path () const |
DeviceEmulationOptions | get_emulation () const |
file_descriptor | get_descriptor () const |
uint64_t | get_current_offset () const |
bool | is_read () const |
bool | is_write () const |
std::string | to_string () const |
Friends | |
std::ostream & | operator<< (std::ostream &o, const DirectIoFile &v) |
typedef int foedus::fs::DirectIoFile::file_descriptor |
Represents low-level file descriptor.
Definition at line 51 of file direct_io_file.hpp.
Constant values.
Enumerator | |
---|---|
kInvalidDescriptor |
POSIX open() semantics says -1 is invalid or not-yet-opened. |
Definition at line 53 of file direct_io_file.hpp.
Analogue of SEEK_SET/SEEK_CUR/SEEK_END in POSIX.
Definition at line 59 of file direct_io_file.hpp.
foedus::fs::DirectIoFile::DirectIoFile | ( | const Path & | path, |
const DeviceEmulationOptions & | emulation = DeviceEmulationOptions() |
||
) |
Constructs this object without opening it yet.
[in] | path | Path of the file to manipulate |
[in] | emulation | Optional argument to emulate slower devices. |
Definition at line 44 of file direct_io_file.cpp.
foedus::fs::DirectIoFile::~DirectIoFile | ( | ) |
Automatically closes the file if it is opened.
Definition at line 51 of file direct_io_file.cpp.
References close().
|
delete |
|
delete |
bool foedus::fs::DirectIoFile::close | ( | ) |
Close the file if not yet closed.
Definition at line 129 of file direct_io_file.cpp.
References ASSERT_ND, kInvalidDescriptor, and foedus::assorted::os_error().
Referenced by foedus::snapshot::SnapshotWriter::close(), foedus::externalize::Externalizable::save_to_file(), foedus::log::MetaLogger::uninitialize_once(), foedus::log::Logger::uninitialize_once(), and ~DirectIoFile().
|
inline |
Definition at line 173 of file direct_io_file.hpp.
Referenced by foedus::log::MetaLogger::initialize_once(), foedus::log::Logger::initialize_once(), foedus::snapshot::SnapshotWriter::open(), foedus::fs::operator<<(), foedus::log::operator<<(), and foedus::snapshot::DumpFileSortedBuffer::wind().
|
inline |
Definition at line 172 of file direct_io_file.hpp.
Referenced by foedus::fs::operator<<().
|
inline |
Definition at line 171 of file direct_io_file.hpp.
|
inline |
Definition at line 170 of file direct_io_file.hpp.
Referenced by foedus::snapshot::SnapshotWriter::close(), foedus::fs::operator<<(), and foedus::snapshot::DumpFileSortedBuffer::to_string().
|
inline |
Whether the file is already and successfully opened.
Definition at line 95 of file direct_io_file.hpp.
References kInvalidDescriptor.
Referenced by read_raw(), sync(), truncate(), and write_raw().
|
inline |
Definition at line 174 of file direct_io_file.hpp.
Referenced by foedus::fs::operator<<().
|
inline |
Definition at line 175 of file direct_io_file.hpp.
Referenced by foedus::fs::operator<<(), and sync().
ErrorCode foedus::fs::DirectIoFile::open | ( | bool | read, |
bool | write, | ||
bool | append, | ||
bool | create | ||
) |
Tries to open the file for the specified volume.
[in] | read | whether to allow read accesses on the opened file |
[in] | write | whether to allow write accesses on the opened file |
[in] | append | whether to set initial offset at the end of the file |
[in] | create | whether to create the file. if already exists, does nothing. |
Definition at line 55 of file direct_io_file.cpp.
References foedus::fs::Path::c_str(), foedus::fs::create_directories(), foedus::fs::DeviceEmulationOptions::disable_direct_io_, foedus::fs::exists(), foedus::fs::file_size(), foedus::kErrorCodeFsAlreadyOpened, foedus::kErrorCodeFsFailedToOpen, foedus::kErrorCodeFsMkdirFailed, foedus::kErrorCodeOk, kInvalidDescriptor, foedus::assorted::os_error(), foedus::fs::Path::parent_path(), read(), and write().
Referenced by foedus::log::MetaLogger::initialize_once(), foedus::log::Logger::initialize_once(), foedus::snapshot::SnapshotWriter::open(), and foedus::externalize::Externalizable::save_to_file().
|
delete |
ErrorCode foedus::fs::DirectIoFile::read | ( | uint64_t | desired_bytes, |
foedus::memory::AlignedMemory * | buffer | ||
) |
Sequentially read the given amount of contents from the current position.
[in] | desired_bytes | Number of bytes to read. If we can't read this many bytes, we return errors. |
[out] | buffer | Memory to copy into. As this is Direct-IO, it must be aligned. |
Definition at line 144 of file direct_io_file.cpp.
Referenced by open(), read_raw(), and foedus::snapshot::DumpFileSortedBuffer::wind().
ErrorCode foedus::fs::DirectIoFile::read | ( | uint64_t | desired_bytes, |
const foedus::memory::AlignedMemorySlice & | slice | ||
) |
Memory slice version.
Definition at line 147 of file direct_io_file.cpp.
References ASSERT_ND, foedus::memory::AlignedMemorySlice::count_, foedus::memory::AlignedMemory::get_alignment(), foedus::memory::AlignedMemorySlice::get_block(), foedus::fs::is_odirect_aligned(), foedus::kErrorCodeFsBufferNotAligned, foedus::kErrorCodeFsBufferTooSmall, foedus::memory::AlignedMemorySlice::memory_, foedus::fs::DeviceEmulationOptions::null_device_, and read_raw().
ErrorCode foedus::fs::DirectIoFile::read_raw | ( | uint64_t | desired_bytes, |
void * | buffer | ||
) |
A version that receives a raw pointer that has to be aligned (be careful to use this ver).
Definition at line 162 of file direct_io_file.cpp.
References ASSERT_ND, foedus::fs::DeviceEmulationOptions::disable_direct_io_, foedus::fs::DeviceEmulationOptions::emulated_read_kb_cycles_, foedus::fs::is_odirect_aligned(), is_opened(), foedus::kErrorCodeFsExcessRead, foedus::kErrorCodeFsNotOpened, foedus::kErrorCodeFsResultNotAligned, foedus::kErrorCodeFsTooShortRead, foedus::kErrorCodeOk, foedus::fs::DeviceEmulationOptions::null_device_, foedus::assorted::os_error(), read(), and foedus::debugging::wait_rdtsc_cycles().
Referenced by read(), foedus::cache::SnapshotFileSet::read_page(), and foedus::cache::SnapshotFileSet::read_pages().
Sets the position of the next byte to be written/extracted from/to the stream.
Definition at line 326 of file direct_io_file.cpp.
References foedus::fs::DeviceEmulationOptions::emulated_seek_latency_cycles_, foedus::fs::is_odirect_aligned(), kDirectIoSeekCur, kDirectIoSeekEnd, kDirectIoSeekSet, foedus::kErrorCodeFsBadSeekInput, foedus::kErrorCodeFsBufferNotAligned, foedus::kErrorCodeFsSeekFailed, foedus::kErrorCodeOk, foedus::fs::DeviceEmulationOptions::null_device_, foedus::assorted::os_error(), and foedus::debugging::wait_rdtsc_cycles().
Referenced by foedus::cache::SnapshotFileSet::read_page(), and foedus::cache::SnapshotFileSet::read_pages().
ErrorCode foedus::fs::DirectIoFile::sync | ( | ) |
Analogues of POSIX fsync().
Definition at line 360 of file direct_io_file.cpp.
References foedus::fs::fsync(), is_opened(), is_write(), foedus::kErrorCodeFsNotOpened, foedus::kErrorCodeFsSyncFailed, foedus::kErrorCodeInvalidParameter, foedus::kErrorCodeOk, foedus::fs::DeviceEmulationOptions::null_device_, and foedus::assorted::os_error().
std::string foedus::fs::DirectIoFile::to_string | ( | ) | const |
Definition at line 383 of file direct_io_file.cpp.
ErrorCode foedus::fs::DirectIoFile::truncate | ( | uint64_t | new_length, |
bool | sync = false |
||
) |
Discard the content of the file after the given offset.
[in] | new_length | The size of this file would become this value. |
[in] | sync | Whether to call fsync on the file and its parent folder after the truncation. |
After a successful call of this method, the cursor would be at new_length, too. This method is used only when we restart the engine in order to discard non-durable parts of log files (regions after durable watermark).
Definition at line 296 of file direct_io_file.cpp.
References foedus::fs::fsync(), foedus::fs::is_odirect_aligned(), is_opened(), foedus::kErrorCodeFsBufferNotAligned, foedus::kErrorCodeFsNotOpened, foedus::kErrorCodeFsTruncateFailed, foedus::kErrorCodeOk, foedus::fs::DeviceEmulationOptions::null_device_, and foedus::assorted::os_error().
Referenced by foedus::log::Logger::initialize_once().
ErrorCode foedus::fs::DirectIoFile::write | ( | uint64_t | desired_bytes, |
const foedus::memory::AlignedMemory & | buffer | ||
) |
Sequentially write the given amount of contents from the current position.
[in] | desired_bytes | Number of bytes to write. If we can't write this many bytes, we return errors. |
[in] | buffer | Memory to read from. As this is Direct-IO, it must be aligned. |
Definition at line 216 of file direct_io_file.cpp.
Referenced by foedus::snapshot::SnapshotWriter::open(), open(), foedus::externalize::Externalizable::save_to_file(), and write_raw().
ErrorCode foedus::fs::DirectIoFile::write | ( | uint64_t | desired_bytes, |
const foedus::memory::AlignedMemorySlice & | slice | ||
) |
Memory slice version.
Definition at line 221 of file direct_io_file.cpp.
References ASSERT_ND, foedus::memory::AlignedMemorySlice::count_, foedus::memory::AlignedMemory::get_alignment(), foedus::memory::AlignedMemorySlice::get_block(), foedus::fs::is_odirect_aligned(), foedus::memory::AlignedMemorySlice::is_valid(), foedus::kErrorCodeFsBufferNotAligned, foedus::kErrorCodeFsBufferTooSmall, foedus::memory::AlignedMemorySlice::memory_, and write_raw().
ErrorCode foedus::fs::DirectIoFile::write_raw | ( | uint64_t | desired_bytes, |
const void * | buffer | ||
) |
A version that receives a raw pointer that has to be aligned (be careful to use this ver).
Definition at line 236 of file direct_io_file.cpp.
References ASSERT_ND, foedus::fs::DeviceEmulationOptions::disable_direct_io_, foedus::fs::DeviceEmulationOptions::emulated_write_kb_cycles_, foedus::fs::is_odirect_aligned(), is_opened(), foedus::kErrorCodeFsExcessWrite, foedus::kErrorCodeFsNotOpened, foedus::kErrorCodeFsResultNotAligned, foedus::kErrorCodeFsWriteFail, foedus::kErrorCodeOk, foedus::fs::DeviceEmulationOptions::null_device_, foedus::assorted::os_error(), foedus::debugging::wait_rdtsc_cycles(), and write().
Referenced by write().
|
friend |
Definition at line 388 of file direct_io_file.cpp.