27 #include <foxxll/config.hpp> 40 template <
class base_file_type>
46 unsigned int device_id)
49 filename_prefix_(filename_prefix),
54 template <
class base_file_type>
61 template <
class base_file_type>
64 std::ostringstream name;
66 name <<
filename_prefix_ <<
"_fpb_" << std::setw(20) << std::setfill(
'0') << offset;
70 template <
class base_file_type>
77 base_file.set_size(bytes);
78 base_file.serve(buffer, 0, bytes, op);
81 template <
class base_file_type>
86 lock_file_ = tlx::make_counting<base_file_type>(
92 void* one_page = aligned_alloc<BlockAlignment>(page_size);
93 #if FOXXLL_WITH_VALGRIND 94 memset(one_page, 0, page_size);
99 aligned_dealloc<BlockAlignment>(one_page);
104 template <
class base_file_type>
108 #ifdef FOXXLL_FILEPERBLOCK_NO_DELETE 111 <<
" error=" << strerror(errno);
115 <<
" error=" << strerror(errno);
118 TLX_LOG <<
"discard " << offset <<
" + " << length;
121 template <
class base_file_type>
125 filename.insert(0, original.substr(0, original.find_last_of(
"/") + 1));
126 if (::
remove(filename.c_str()) != 0)
127 TLX_LOG1 <<
"remove() error on path=" << filename
128 <<
" error=" << strerror(errno);
130 if (::rename(original.c_str(), filename.c_str()) != 0)
131 TLX_LOG1 <<
"rename() error on path=" << filename
132 <<
" to=" << original <<
" error=" << strerror(errno);
144 template <
class base_file_type>
147 return "fileperblock";
154 #if FOXXLL_HAVE_MMAP_FILE 158 #if FOXXLL_HAVE_WINCALL_FILE
static const unsigned int DEFAULT_DEVICE_ID
request::offset_type offset_type
the offset of a request, also the size of the file
Implementation of some file methods based on serving_request.
virtual ~fileperblock_file()
const char * io_type() const final
std::string filename_prefix_
constexpr size_t BlockAlignment
request::size_type size_type
the size of a request
virtual void discard(offset_type offset, offset_type length)
#define FOXXLL_THROW_ERRNO(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [errno message]".
tlx::counting_ptr< base_file_type > lock_file_
fileperblock_file(const std::string &filename_prefix, int mode, int queue_id=DEFAULT_QUEUE, int allocator_id=NO_ALLOCATOR, unsigned int device_id=DEFAULT_DEVICE_ID)
static int truncate(const char *path, external_size_type length)
std::string filename_for_block(offset_type offset)
Constructs a file name for a given block.
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
virtual void lock()
Locks file for reading and writing (acquires a lock in the file system).
High-performance smart pointer used as a wrapping reference counting pointer.
static const size_t bytes
number of bytes in uint_pair
std::make_signed< Integral >::type as_signed(Integral value)
Return the given value casted to the corresponding signed type.
static const int NO_ALLOCATOR
void serve(void *buffer, offset_type offset, size_type bytes, request::read_or_write op) final
virtual void export_files(offset_type offset, offset_type length, std::string filename)
Rename the file corresponding to the offset such that it is out of reach for deleting.
#define TLX_LOG
Default logging method: output if the local debug variable is true.
int get_queue_id() const override