Tkrzw
|
File implementation with positional access and locking for parallel operations. More...
#include <tkrzw_file_pos.h>
Public Member Functions | |
PositionalParallelFile () | |
Default constructor. More... | |
virtual | ~PositionalParallelFile () |
Destructor. More... | |
PositionalParallelFile (const PositionalParallelFile &rhs)=delete | |
Copy and assignment are disabled. More... | |
PositionalParallelFile & | operator= (const PositionalParallelFile &rhs)=delete |
Status | Open (const std::string &path, bool writable, int32_t options=OPEN_DEFAULT) override |
Opens a file. More... | |
Status | Close () override |
Closes the file. More... | |
Status | Read (int64_t off, void *buf, size_t size) override |
Reads data. More... | |
Status | Write (int64_t off, const void *buf, size_t size) override |
Writes data. More... | |
Status | Append (const void *buf, size_t size, int64_t *off=nullptr) override |
Appends data at the end of the file. More... | |
Status | Expand (size_t inc_size, int64_t *old_size=nullptr) override |
Expands the file size without writing data. More... | |
Status | Truncate (int64_t size) override |
Truncates the file. More... | |
Status | Synchronize (bool hard) override |
Synchronizes the content of the file to the file system. More... | |
Status | GetSize (int64_t *size) override |
Gets the size of the file. More... | |
Status | SetAllocationStrategy (int64_t init_size, double inc_factor) override |
Sets allocation strategy. More... | |
bool | IsMemoryMapping () const override |
Checks whether operations are done by memory mapping. More... | |
bool | IsAtomic () const override |
Checks whether updating operations are atomic and thread-safe. More... | |
std::unique_ptr< File > | MakeFile () const override |
Makes a new file object of the same concrete class. More... | |
![]() | |
virtual | ~File ()=default |
Destructor. More... | |
virtual std::string | ReadSimple (int64_t off, size_t size) |
Reads data, in a simple way. More... | |
virtual bool | WriteSimple (int64_t off, std::string_view data) |
Writes data, in a simple way. More... | |
virtual int64_t | AppendSimple (const std::string &data) |
Appends data at the end of the file, in a simple way. More... | |
virtual int64_t | ExpandSimple (size_t inc_size) |
Expands the file size without writing data, in a simple way. More... | |
virtual int64_t | GetSizeSimple () |
Gets the size of the file, in a simple way. More... | |
Additional Inherited Members | |
![]() | |
enum | OpenOption : int32_t { OPEN_DEFAULT = 0, OPEN_TRUNCATE = 1 << 0, OPEN_NO_CREATE = 1 << 1, OPEN_NO_WAIT = 1 << 2, OPEN_NO_LOCK = 1 << 3 } |
Enumeration of options for Open. More... | |
![]() | |
static constexpr int64_t | DEFAULT_ALLOC_INIT_SIZE = 1LL << 20 |
The default value of initial allocation size. More... | |
static constexpr double | DEFAULT_ALLOC_INC_FACTOR = 2.0 |
The default value of allocation increment factor. More... | |
File implementation with positional access and locking for parallel operations.
Reading and writing operations are thread-safe; Multiple threads can access the same file concurrently. Other operations including Open, Close, Truncate, and Synchronize are not thread-safe. Moreover, locking doesn't assure atomicity of reading and writing operations.
tkrzw::PositionalParallelFile::PositionalParallelFile | ( | ) |
Default constructor.
|
virtual |
Destructor.
|
explicitdelete |
Copy and assignment are disabled.
|
overridevirtual |
Opens a file.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
options | Bit-sum options. |
By default, exclusive locking against other processes is done for a writer and shared locking against other processes is done for a reader.
Implements tkrzw::File.
|
overridevirtual |
|
overridevirtual |
Reads data.
off | The offset of a source region. |
buf | The pointer to the destination buffer. |
size | The size of the data to be read. |
Implements tkrzw::File.
|
overridevirtual |
Writes data.
off | The offset of the destination region. |
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
Implements tkrzw::File.
|
overridevirtual |
Appends data at the end of the file.
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
off | The pointer to an integer object to contain the offset at which the data has been put. If it is nullptr, it is ignored. |
Implements tkrzw::File.
|
overridevirtual |
Expands the file size without writing data.
inc_size | The size to increment the file size by. |
old_size | The pointer to an integer object to contain the old size of the file. put. If it is nullptr, it is ignored. |
Implements tkrzw::File.
|
overridevirtual |
Truncates the file.
size | The new size of the file. |
Implements tkrzw::File.
|
overridevirtual |
Synchronizes the content of the file to the file system.
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
The pysical file size can be larger than the logical size in order to improve performance by reducing frequency of allocation. Thus, you should call this function before accessing the file with external tools.
Implements tkrzw::File.
|
overridevirtual |
Gets the size of the file.
size | The pointer to an integer object to contain the result size. |
Implements tkrzw::File.
|
overridevirtual |
Sets allocation strategy.
init_size | An initial size of allocation. |
inc_factor | A factor to increase the size of allocation. |
By default, the initial size is 1MB and the increasing factor is 2. This method must be called before the file is opened.
Implements tkrzw::File.
|
overridevirtual |
Checks whether operations are done by memory mapping.
Implements tkrzw::File.
|
overridevirtual |
Checks whether updating operations are atomic and thread-safe.
Implements tkrzw::File.
|
overridevirtual |
Makes a new file object of the same concrete class.
Implements tkrzw::File.