CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FileBackedBuffer Class Reference

#include <file_backed_buffer.h>

Inheritance diagram for FileBackedBuffer:
Collaboration diagram for FileBackedBuffer:

Public Member Functions

 ~FileBackedBuffer ()
 
void Append (const void *source, uint64_t len)
 
void Commit ()
 
int64_t Data (void **ptr, int64_t len, uint64_t pos)
 
int64_t Read (void *ptr, int64_t len)
 
int64_t ReadP (void *ptr, int64_t len, uint64_t pos)
 
void Rewind ()
 
uint64_t GetSize () const
 

Static Public Member Functions

static FileBackedBufferCreate (uint64_t in_memory_threshold, const std::string &tmp_dir="/tmp/")
 

Private Types

enum  { kWriteState = 0, kReadState }
 
enum  { kMemoryMode = 0, kFileMode }
 

Private Member Functions

 FRIEND_TEST (T_FileBackedBuffer, SimpleWriteAndRead)
 
 FRIEND_TEST (T_FileBackedBuffer, EmptyBuffer)
 
 FRIEND_TEST (T_FileBackedBuffer, EmptyWrite)
 
 FRIEND_TEST (T_FileBackedBuffer, StraightToFile)
 
 FRIEND_TEST (T_FileBackedBuffer, OnlyInMemory)
 
 FileBackedBuffer (uint64_t in_memory_threshold, const std::string &tmp_dir)
 
void SaveToFile ()
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Private Attributes

const uint64_t in_memory_threshold_
 
const std::string tmp_dir_
 
enum FileBackedBuffer:: { ... }  state_
 
enum FileBackedBuffer:: { ... }  mode_
 
uint64_t size_
 
unsigned char * buf_
 
uint64_t pos_
 
FILE * fp_
 
std::string file_path_
 
MemoryMappedFilemmapped_
 

Detailed Description

This file is part of the CernVM File System. FileBackedBuffer is a class for smart data writing and reading. It represents a buffer that is in a first step filled with data and, once all data has been written, it can be read back out.

It works in 2 modes: memory mode and file mode. It first starts working in memory mode, but as soon as the buffer size reaches a configurable threshold, it writes all data into a temporary file, freeing up the occupied memory. From that point, all further data are written directly into the file.

Reading is done straight from memory or using mmap, depending on the current mode of operation.

Method call timeline:

  1. Create
  2. Append
  3. Commit
  4. Data/Read/ReadP, Rewind

Definition at line 37 of file file_backed_buffer.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
kWriteState 
kReadState 

Definition at line 65 of file file_backed_buffer.h.

anonymous enum
private
Enumerator
kMemoryMode 
kFileMode 

Definition at line 70 of file file_backed_buffer.h.

Constructor & Destructor Documentation

FileBackedBuffer::~FileBackedBuffer ( )

Definition at line 37 of file file_backed_buffer.cc.

Here is the call graph for this function:

FileBackedBuffer::FileBackedBuffer ( uint64_t  in_memory_threshold,
const std::string &  tmp_dir 
)
private

Definition at line 22 of file file_backed_buffer.cc.

Referenced by Create().

Here is the caller graph for this function:

Member Function Documentation

void FileBackedBuffer::Append ( const void *  source,
uint64_t  len 
)

Definition at line 57 of file file_backed_buffer.cc.

Referenced by upload::S3Uploader::DoUpload().

Here is the call graph for this function:

Here is the caller graph for this function:

void FileBackedBuffer::Commit ( )

Definition at line 98 of file file_backed_buffer.cc.

Referenced by upload::S3Uploader::DoUpload().

Here is the call graph for this function:

Here is the caller graph for this function:

FileBackedBuffer * FileBackedBuffer::Create ( uint64_t  in_memory_threshold,
const std::string &  tmp_dir = "/tmp/" 
)
static

This file is part of the CernVM File System.

Definition at line 16 of file file_backed_buffer.cc.

Referenced by upload::S3Uploader::CreateJobInfo(), upload::S3Uploader::DoUpload(), and upload::S3StreamHandle::S3StreamHandle().

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t FileBackedBuffer::Data ( void **  ptr,
int64_t  len,
uint64_t  pos 
)

Definition at line 121 of file file_backed_buffer.cc.

Referenced by ReadP().

Here is the call graph for this function:

Here is the caller graph for this function:

FileBackedBuffer::FRIEND_TEST ( T_FileBackedBuffer  ,
SimpleWriteAndRead   
)
private
FileBackedBuffer::FRIEND_TEST ( T_FileBackedBuffer  ,
EmptyBuffer   
)
private
FileBackedBuffer::FRIEND_TEST ( T_FileBackedBuffer  ,
EmptyWrite   
)
private
FileBackedBuffer::FRIEND_TEST ( T_FileBackedBuffer  ,
StraightToFile   
)
private
FileBackedBuffer::FRIEND_TEST ( T_FileBackedBuffer  ,
OnlyInMemory   
)
private
uint64_t FileBackedBuffer::GetSize ( ) const

Definition at line 154 of file file_backed_buffer.cc.

int64_t FileBackedBuffer::Read ( void *  ptr,
int64_t  len 
)

Definition at line 136 of file file_backed_buffer.cc.

Here is the call graph for this function:

int64_t FileBackedBuffer::ReadP ( void *  ptr,
int64_t  len,
uint64_t  pos 
)

Definition at line 142 of file file_backed_buffer.cc.

Referenced by Read().

Here is the call graph for this function:

Here is the caller graph for this function:

void FileBackedBuffer::Rewind ( )

Definition at line 149 of file file_backed_buffer.cc.

Here is the call graph for this function:

void FileBackedBuffer::SaveToFile ( )
private

Definition at line 161 of file file_backed_buffer.cc.

Referenced by Append().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

unsigned char* FileBackedBuffer::buf_
private

Definition at line 77 of file file_backed_buffer.h.

Referenced by Append(), Commit(), Data(), SaveToFile(), and ~FileBackedBuffer().

std::string FileBackedBuffer::file_path_
private

Definition at line 83 of file file_backed_buffer.h.

Referenced by Append(), Commit(), SaveToFile(), and ~FileBackedBuffer().

FILE* FileBackedBuffer::fp_
private

Definition at line 81 of file file_backed_buffer.h.

Referenced by Append(), Commit(), SaveToFile(), and ~FileBackedBuffer().

const uint64_t FileBackedBuffer::in_memory_threshold_
private

Definition at line 62 of file file_backed_buffer.h.

Referenced by Append().

MemoryMappedFile* FileBackedBuffer::mmapped_
private

Definition at line 85 of file file_backed_buffer.h.

Referenced by Commit(), Data(), and ~FileBackedBuffer().

enum { ... } FileBackedBuffer::mode_
uint64_t FileBackedBuffer::pos_
private

Definition at line 79 of file file_backed_buffer.h.

Referenced by Append(), Commit(), GetSize(), Read(), Rewind(), and SaveToFile().

uint64_t FileBackedBuffer::size_
private

Definition at line 75 of file file_backed_buffer.h.

Referenced by Append(), Commit(), Data(), GetSize(), and SaveToFile().

enum { ... } FileBackedBuffer::state_
const std::string FileBackedBuffer::tmp_dir_
private

Definition at line 63 of file file_backed_buffer.h.

Referenced by SaveToFile().


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