Thrill  0.1

Detailed Description

Defines interface of file.

It is a base class for different implementations that might base on various file systems or even remote storage interfaces

Definition at line 54 of file file.hpp.

+ Inheritance diagram for file:
+ Collaboration diagram for file:

#include <file.hpp>

Public Types

using offset_type = request::offset_type
 the offset of a request, also the size of the file More...
 
enum  open_mode {
  RDONLY = 1, WRONLY = 2, RDWR = 4, CREAT = 8,
  DIRECT = 16, TRUNC = 32, SYNC = 64, NO_LOCK = 128,
  REQUIRE_DIRECT = 256
}
 
using size_type = request::size_type
 the size of a request More...
 

Public Member Functions

 file (unsigned int device_id=DEFAULT_DEVICE_ID, file_stats *file_stats=nullptr)
 Construct a new file, usually called by a subclass. More...
 
 file (const file &)=delete
 non-copyable: delete copy-constructor More...
 
 file (file &&)=default
 move-constructor: default More...
 
virtual ~file ()
 
void add_request_ref ()
 increment referenced requests More...
 
virtual request_ptr aread (void *buffer, offset_type pos, size_type bytes, const completion_handler &on_complete=completion_handler())=0
 
virtual request_ptr awrite (void *buffer, offset_type pos, size_type bytes, const completion_handler &on_complete=completion_handler())=0
 
virtual void close_remove ()
 close and remove file More...
 
void delete_request_ref ()
 decrement referenced requests More...
 
virtual void discard (offset_type offset, offset_type size)
 
virtual void export_files (offset_type offset, offset_type length, std::string prefix)
 
virtual int get_allocator_id () const =0
 Returns the file's parallel disk block allocator number. More...
 
unsigned int get_device_id () const
 Returns the file's physical device id. More...
 
file_statsget_file_stats () const
 
virtual int get_queue_id () const =0
 
size_t get_request_nref ()
 return number of referenced requests More...
 
virtual const char * io_type () const =0
 
virtual void lock ()=0
 Locks file for reading and writing (acquires a lock in the file system). More...
 
bool need_alignment () const
 Returns need_alignment_. More...
 
fileoperator= (const file &)=delete
 non-copyable: delete assignment operator More...
 
fileoperator= (file &&)=default
 move-assignment operator: default More...
 
virtual void serve (void *buffer, offset_type offset, size_type bytes, request::read_or_write op)=0
 
virtual void set_size (offset_type newsize)=0
 
virtual offset_type size ()=0
 
- Public Member Functions inherited from ReferenceCounter
 ReferenceCounter () noexcept
 new objects have zero reference count More...
 
 ReferenceCounter (const ReferenceCounter &) noexcept
 coping still creates a new object with zero reference count More...
 
 ~ReferenceCounter ()
 
bool dec_reference () const noexcept
 Call whenever resetting (i.e. More...
 
void inc_reference () const noexcept
 Call whenever setting a pointer to the object. More...
 
ReferenceCounteroperator= (const ReferenceCounter &) noexcept
 assignment operator, leaves pointers unchanged More...
 
size_t reference_count () const noexcept
 Return the number of references to this object (for debugging) More...
 
bool unique () const noexcept
 Test if the ReferenceCounter is referenced by only one CountingPtr. More...
 

Static Public Member Functions

Static Functions for Platform Abstraction
static int unlink (const char *path)
 unlink path from filesystem More...
 
static int truncate (const char *path, external_size_type length)
 

Static Public Attributes

static const unsigned int DEFAULT_DEVICE_ID = std::numeric_limits<unsigned int>::max()
 
static const int DEFAULT_LINUXAIO_QUEUE = -2
 
static const int DEFAULT_QUEUE = -1
 
static const int NO_ALLOCATOR = -1
 

Protected Attributes

unsigned int device_id_
 
file_statsfile_stats_
 
bool need_alignment_ = false
 Flag whether read/write operations REQUIRE alignment. More...
 
tlx::reference_counter request_ref_
 count the number of requests referencing this file More...
 

Member Typedef Documentation

◆ offset_type

using offset_type = request::offset_type

the offset of a request, also the size of the file

Definition at line 58 of file file.hpp.

◆ size_type

the size of a request

Definition at line 60 of file file.hpp.

Member Enumeration Documentation

◆ open_mode

enum open_mode

Definition of acceptable file open modes. Various open modes in a file system must be converted to this set of acceptable modes

Enumerator
RDONLY 

only reading of the file is allowed

WRONLY 

only writing of the file is allowed

RDWR 

read and write of the file are allowed

CREAT 

in case file does not exist no error occurs and file is newly created

DIRECT 

I/Os proceed bypassing file system buffers, i.e. unbuffered I/O. Tries to open with appropriate flags, if fails print warning and open normally.

TRUNC 

once file is opened its length becomes zero

SYNC 

open the file with O_SYNC | O_DSYNC | O_RSYNC flags set

NO_LOCK 

do not acquire an exclusive lock by default

REQUIRE_DIRECT 

implies DIRECT, fail if opening with DIRECT flag does not work.

Definition at line 64 of file file.hpp.

Constructor & Destructor Documentation

◆ file() [1/3]

file ( unsigned int  device_id = DEFAULT_DEVICE_ID,
file_stats file_stats = nullptr 
)
inlineexplicit

Construct a new file, usually called by a subclass.

Definition at line 95 of file file.hpp.

References file::aread(), file::awrite(), bytes, file::get_allocator_id(), file::get_queue_id(), file::lock(), file::operator=(), file::serve(), file::set_size(), and file::size().

◆ file() [2/3]

file ( const file )
delete

non-copyable: delete copy-constructor

◆ file() [3/3]

file ( file &&  )
default

move-constructor: default

◆ ~file()

virtual ~file ( )
inlinevirtual

Definition at line 176 of file file.hpp.

References file::get_request_nref(), file::io_type(), and TLX_LOG1.

Member Function Documentation

◆ add_request_ref()

void add_request_ref ( )
inline

increment referenced requests

Definition at line 223 of file file.hpp.

References ReferenceCounter::inc_reference().

Referenced by request::request().

◆ aread()

virtual request_ptr aread ( void *  buffer,
offset_type  pos,
size_type  bytes,
const completion_handler on_complete = completion_handler() 
)
pure virtual

Schedules an asynchronous read request to the file.

Parameters
bufferpointer to memory buffer to read into
posfile position to start read from
bytesnumber of bytes to transfer
on_completeI/O completion handler
Returns
request_ptr request object, which can be used to track the status of the operation

Implemented in disk_queued_file.

Referenced by file::file(), BlockPool::PinBlock(), BID< raw_size >::read(), BID< 0 >::read(), and typed_block< RawSize, Type, NRef, MetaInfoType >::read().

◆ awrite()

virtual request_ptr awrite ( void *  buffer,
offset_type  pos,
size_type  bytes,
const completion_handler on_complete = completion_handler() 
)
pure virtual

Schedules an asynchronous write request to the file.

Parameters
bufferpointer to memory buffer to write from
posstarting file position to write
bytesnumber of bytes to transfer
on_completeI/O completion handler
Returns
request_ptr request object, which can be used to track the status of the operation

Implemented in disk_queued_file.

Referenced by BlockPool::EvictBlockLRU(), file::file(), BID< raw_size >::write(), BID< 0 >::write(), and typed_block< RawSize, Type, NRef, MetaInfoType >::write().

◆ close_remove()

virtual void close_remove ( )
inlinevirtual

close and remove file

Reimplemented in ufs_file_base.

Definition at line 174 of file file.hpp.

◆ delete_request_ref()

void delete_request_ref ( )
inline

decrement referenced requests

Definition at line 229 of file file.hpp.

References ReferenceCounter::dec_reference().

Referenced by request_with_state::cancel(), and request::release_file_reference().

◆ discard()

virtual void discard ( offset_type  offset,
offset_type  size 
)
inlinevirtual

Discard a region of the file (mark it unused). Some specialized file types may need to know freed regions

Reimplemented in memory_file.

Definition at line 159 of file file.hpp.

References tlx::unused().

◆ export_files()

virtual void export_files ( offset_type  offset,
offset_type  length,
std::string  prefix 
)
inlinevirtual

Definition at line 165 of file file.hpp.

References tlx::unused().

◆ get_allocator_id()

virtual int get_allocator_id ( ) const
pure virtual

Returns the file's parallel disk block allocator number.

Implemented in disk_queued_file.

Referenced by file::file(), BID< raw_size >::is_managed(), BID< 0 >::is_managed(), and serving_request::serve().

◆ get_device_id()

unsigned int get_device_id ( ) const
inline

Returns the file's physical device id.

Definition at line 207 of file file.hpp.

References file::device_id_.

◆ get_file_stats()

file_stats* get_file_stats ( ) const
inline

Definition at line 212 of file file.hpp.

References file::file_stats_.

◆ get_queue_id()

virtual int get_queue_id ( ) const
pure virtual

Returns the identifier of the file's queue number.

Remarks
Files allocated on the same physical device usually share the same queue, unless there is a common queue (e.g. with linuxaio).

Implemented in disk_queued_file.

Referenced by request_with_state::cancel(), file::file(), and disk_queues::make_queue().

◆ get_request_nref()

size_t get_request_nref ( )
inline

return number of referenced requests

Definition at line 235 of file file.hpp.

References ReferenceCounter::reference_count(), file::truncate(), and file::unlink().

Referenced by file::~file().

◆ io_type()

virtual const char* io_type ( ) const
pure virtual

Identifies the type of I/O implementation.

Returns
pointer to null terminated string of characters, containing the name of I/O implementation

Implemented in fileperblock_file< base_file_type >, memory_file, syscall_file, and ufs_file_base.

Referenced by request::check_nref_failed(), serving_request::io_type(), request::io_type(), and file::~file().

◆ lock()

virtual void lock ( )
pure virtual

Locks file for reading and writing (acquires a lock in the file system).

Implemented in fileperblock_file< base_file_type >, memory_file, and ufs_file_base.

Referenced by file::file().

◆ need_alignment()

bool need_alignment ( ) const
inline

Returns need_alignment_.

Definition at line 204 of file file.hpp.

References file::need_alignment_.

Referenced by serving_request::serving_request().

◆ operator=() [1/2]

file& operator= ( const file )
delete

non-copyable: delete assignment operator

Referenced by file::file().

◆ operator=() [2/2]

file& operator= ( file &&  )
default

move-assignment operator: default

◆ serve()

virtual void serve ( void *  buffer,
offset_type  offset,
size_type  bytes,
request::read_or_write  op 
)
pure virtual

Implemented in syscall_file, and memory_file.

Referenced by file::file(), and serving_request::serve().

◆ set_size()

virtual void set_size ( offset_type  newsize)
pure virtual

Changes the size of the file.

Parameters
newsizenew file size

Implemented in memory_file, and ufs_file_base.

Referenced by file::file(), disk_block_allocator::grow_file(), and disk_block_allocator::~disk_block_allocator().

◆ size()

virtual offset_type size ( )
pure virtual

Returns size of the file.

Returns
file size in bytes

Implemented in fileperblock_file< base_file_type >, memory_file, and ufs_file_base.

Referenced by file::file().

◆ truncate()

static int truncate ( const char *  path,
external_size_type  length 
)
static

truncate a path to given length. Use this only if you dont have a fileio-specific object, which provides truncate().

Referenced by fileperblock_file< base_file_type >::discard(), fileperblock_file< base_file_type >::export_files(), and file::get_request_nref().

◆ unlink()

int unlink ( const char *  path)
static

unlink path from filesystem

Definition at line 18 of file file.cpp.

Referenced by file::get_request_nref().

Member Data Documentation

◆ DEFAULT_DEVICE_ID

const unsigned int DEFAULT_DEVICE_ID = std::numeric_limits<unsigned int>::max()
static

◆ DEFAULT_LINUXAIO_QUEUE

const int DEFAULT_LINUXAIO_QUEUE = -2
static

Definition at line 90 of file file.hpp.

Referenced by foxxll::create_file(), and disk_config::fileio_string().

◆ DEFAULT_QUEUE

const int DEFAULT_QUEUE = -1
static

◆ device_id_

unsigned int device_id_
protected

The file's physical device id (e.g. used for prefetching sequence calculation)

Definition at line 196 of file file.hpp.

Referenced by file::get_device_id().

◆ file_stats_

file_stats* file_stats_
protected

pointer to file's stats inside of iostats. Because the stats can live longer than the file, the iostats keeps ownership.

Definition at line 200 of file file.hpp.

Referenced by file::get_file_stats(), memory_file::serve(), syscall_file::serve(), and fileperblock_file< base_file_type >::serve().

◆ need_alignment_

bool need_alignment_ = false
protected

Flag whether read/write operations REQUIRE alignment.

Definition at line 192 of file file.hpp.

Referenced by file::need_alignment(), and ufs_file_base::ufs_file_base().

◆ NO_ALLOCATOR

const int NO_ALLOCATOR = -1
static

◆ request_ref_

tlx::reference_counter request_ref_
protected

count the number of requests referencing this file

Definition at line 219 of file file.hpp.


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