Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
file Class Referenceabstract

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

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.

the size of a request

Definition at line 60 of file file.hpp.

Member Enumeration Documentation

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 ( 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.

file ( const file )
delete

non-copyable: delete copy-constructor

file ( file &&  )
default

move-constructor: default

virtual ~file ( )
inlinevirtual

Definition at line 176 of file file.hpp.

References file::get_request_nref(), and LOG1.

Member Function Documentation

void add_request_ref ( )
inline

increment referenced requests

Definition at line 223 of file file.hpp.

References ReferenceCounter::inc_reference(), and file::request_ref_.

Referenced by request::request().

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 BlockPool::PinBlock(), BID< raw_size >::read(), BID< 0 >::read(), and typed_block< RawSize, Type, NRef, MetaInfoType >::read().

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 BID< raw_size >::write(), BID< 0 >::write(), and typed_block< RawSize, Type, NRef, MetaInfoType >::write().

virtual void close_remove ( )
inlinevirtual

close and remove file

Reimplemented in ufs_file_base.

Definition at line 174 of file file.hpp.

void delete_request_ref ( )
inline

decrement referenced requests

Definition at line 229 of file file.hpp.

References ReferenceCounter::dec_reference(), and file::request_ref_.

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

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().

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().

virtual int get_allocator_id ( ) const
pure virtual

Returns the file's parallel disk block allocator number.

Implemented in disk_queued_file.

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

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_.

file_stats* get_file_stats ( ) const
inline

Definition at line 212 of file file.hpp.

References file::file_stats_.

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(), and disk_queues::make_queue().

size_t get_request_nref ( )
inline

return number of referenced requests

Definition at line 235 of file file.hpp.

References ReferenceCounter::reference_count(), and file::request_ref_.

Referenced by file::~file().

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(), and request::io_type().

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.

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().

file& operator= ( const file )
delete

non-copyable: delete assignment operator

file& operator= ( file &&  )
default

move-assignment operator: default

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 serving_request::serve().

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 disk_block_allocator::grow_file(), and disk_block_allocator::~disk_block_allocator().

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.

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().

int unlink ( const char *  path)
static

unlink path from filesystem

Definition at line 18 of file file.cpp.

Member Data Documentation

const unsigned int DEFAULT_DEVICE_ID = std::numeric_limits<unsigned int>::max()
static
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().

const int DEFAULT_QUEUE = -1
static
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_
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(), and syscall_file::serve().

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().

const int NO_ALLOCATOR = -1
static

Definition at line 91 of file file.hpp.

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

tlx::reference_counter request_ref_
protected

count the number of requests referencing this file

Definition at line 219 of file file.hpp.

Referenced by file::add_request_ref(), file::delete_request_ref(), and file::get_request_nref().


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