|
casacore
|
#include <MultiFile.h>
Public Member Functions | |
| MultiFile (const String &name, ByteIO::OpenOption, Int blockSize=0, Bool useODirect=False, Bool useCRC=False) | |
| Open or create a MultiFile with the given name. | |
| MultiFile (const String &name, const std::shared_ptr< MultiFileBase > &parent, ByteIO::OpenOption, Int blockSize=0) | |
| Open or create a MultiFile with the given name which is nested in the given parent. | |
| ~MultiFile () override | |
| The destructor flushes and closes the file. | |
| MultiFile (const MultiFile &)=delete | |
| Copy constructor and assignment not possible. | |
| MultiFile & | operator= (const MultiFile &)=delete |
| std::shared_ptr< MultiFileBase > | makeNested (const std::shared_ptr< MultiFileBase > &parent, const String &name, ByteIO::OpenOption, Int blockSize) const override |
| Make a nested MultiFile. | |
| void | reopenRW () override |
| Reopen the underlying file for read/write access. | |
| void | fsync () override |
| Fsync the file (i.e., force the data to be physically written). | |
| void | show (std::ostream &) const |
| Show some info. | |
| Public Member Functions inherited from casacore::MultiFileBase | |
| MultiFileBase (const String &name, Int blockSize, Bool useODirect) | |
| Create a MultiFileBase object with the given name. | |
| virtual | ~MultiFileBase () |
| The destructor flushes dirty blocks and closes the container file. | |
| MultiFileBase (const MultiFileBase &)=delete | |
| Forbid copy constructor. | |
| MultiFileBase & | operator= (const MultiFileBase &)=delete |
| Forbid assignment. | |
| String | fileName () const |
| Get the file name of the MultiFileBase container file. | |
| Bool | isWritable () const |
| Is the container file writable? | |
| Int | openFile (const String &name) |
| Open the given logical file and return its file id. | |
| Int | createFile (const String &name, ByteIO::OpenOption=ByteIO::New) |
| Create a new logical file and return its file id. | |
| void | flushFile (Int fileId) |
| Flush the possible dirty buffer of the given logical file. | |
| void | closeFile (Int fileId) |
| Close a logical file. | |
| void | deleteFile (Int fileId) |
| Delete a logical file. | |
| Int64 | fileSize (Int fileId) const |
| Get the size of a logical file. | |
| Int64 | read (Int fileId, void *buffer, Int64 size, Int64 offset) |
| Read a block at the given offset in the logical file. | |
| Int64 | write (Int fileId, const void *buffer, Int64 size, Int64 offset) |
| Write a block at the given offset in the logical file. | |
| void | truncate (Int fileId, Int64 size) |
| Truncate the logical file to the given size. | |
| void | flush () |
| Flush the file by writing all dirty data and all header info. | |
| Int64 | blockSize () const |
| Get the block size used. | |
| uInt | nfile () const |
| Get the nr of logical files. | |
| Int64 | nblock () const |
| Get the total nr of data blocks used. | |
| const std::vector< MultiFileInfo > & | info () const |
| Get the info object (for test purposes mainly). | |
| const std::vector< Int64 > & | freeBlocks () const |
| Get the free blocks (for test purposes mainly). | |
| Int | fileId (const String &name, Bool throwExcp=True) const |
| Return the file id of a file in the MultiFileBase object. | |
| Bool | useODirect () const |
| Is O_DIRECT used? | |
Static Public Member Functions | |
| static std::vector< Int64 > | packIndex (const std::vector< Int64 > &blockNrs) |
| Compress a block index by looking for subsequent block numbers. | |
| static std::vector< Int64 > | unpackIndex (const std::vector< Int64 > &blockNrs) |
| Decompress a block index by inserting subsequent block numbers. | |
| Static Public Member Functions inherited from casacore::MultiFileBase | |
| static std::shared_ptr< MultiFileBase > | openMF (const String &fileName) |
| Open the correct MultiFileBase (as plain or HDF5). | |
Private Member Functions | |
| void | init (ByteIO::OpenOption option) |
| Initialize the MultiFile object. | |
| void | getInfoVersion2 (Int64 contBlockNr, CanonicalIO &aio) |
| Read the file info for the new version 2. | |
| void | writeVector (CanonicalIO &cio, const std::vector< Int64 > &index) |
| Write a vector of Int64. | |
| void | writeVector (CanonicalIO &cio, const std::vector< uInt > &index) |
| void | readVector (CanonicalIO &cio, std::vector< Int64 > &index) |
| Read a vector of Int64. | |
| void | readVector (CanonicalIO &cio, std::vector< uInt > &index) |
| void | writeRemainder (MemoryIO &mio, CanonicalIO &, MultiFileBuffer &mfbuf) |
| Write the remainder of the header (in case exceeding 1 block). | |
| void | readRemainder (Int64 headerSize, Int64 blockNr, std::vector< char > &buf) |
| Read the remainder of the header into the buffer. | |
| void | truncateIfNeeded () |
| Truncate the file if blocks are freed at the end. | |
| virtual void | writeHeaderShow (Int64 ncont, Int64 todo) const |
| Header writing hooks (meant for derived test classes). | |
| virtual void | writeHeaderTest () |
Additional Inherited Members | |
| Protected Member Functions inherited from casacore::MultiFileBase | |
| void | resync () |
| Resync with another process by clearing the buffers and rereading the header. | |
| void | setNewFile () |
| Set the flags and blockSize for a new MultiFile/HDF5. | |
| Protected Attributes inherited from casacore::MultiFileBase | |
| String | itsName |
| Int64 | itsBlockSize |
| Int64 | itsNrBlock |
| Int64 | itsHdrCounter |
| std::vector< MultiFileInfo > | itsInfo |
| std::shared_ptr< MultiFileBuffer > | itsBuffer |
| Bool | itsUseODirect |
| Bool | itsWritable |
| Bool | itsChanged |
| std::vector< Int64 > | itsFreeBlocks |
Class to combine multiple files in a single one.
Public interface
This class (derived from MultiFileBase) is a container file holding multiple virtual files in a regular file. It is primarily meant as a container file for the storage manager files of a table to reduce the number of files used (especially for Lustre) and to reduce the number of open files (especially when concatenating tables).
MultiFile has the following properties:
The SetupNewTable constructor has a StorageOption argument to define if a MultiFile has to be used and if so, the buffer size to use. It is also possible to specify that through aipsrc variables.
A virtual file is spread over multiple (fixed size) data blocks in the MultiFile. A data block is never shared by multiple files. For each virtual file MultiFile keeps a MultiFileInfo object telling the file size and the block numbers used for the file. When flushing the MultiFile, this meta info is written into the header block. If it does not fit in the header block, the rest is written in continuation blocks. On open and resync, it is read back. There are two sets of continuation blocks which are alternately used when the header is written. This is done to have a valid header in case of a crash in the middle of writing the header.
A virtual file is represented by an MFFileIO object, which is derived from ByteIO and as such part of the casacore IO framework. It makes it possible for applications to access a virtual file in the same way as a regular file.
It is possible to delete a virtual file. Its blocks will be added to the free block list (which is also stored in the meta info). The MultiFile is truncated when blocks are deleted at the end of the file.
In principle it is possible to use the MultiFile functions directly. However, in general it is much easier to use an MFFileIO object per virtual file as shown below.
Definition at line 146 of file MultiFile.h.
|
explicit |
Open or create a MultiFile with the given name.
Upon creation the block size can be given. If 0, it uses the block size of the file system the file is on.
If useODirect=True, the O_DIRECT flag is used (if supported). It tells the kernel to bypass its file cache to have more predictable I/O behaviour.
If useCRC=True, 32-bit CRC values are calculated and stored for each data block. Note that useCRC is only used for new files.
References casacore::MultiFileBase::blockSize(), casacore::False, casacore::name(), and casacore::MultiFileBase::useODirect().
Referenced by MultiFile(), and operator=().
|
explicit |
Open or create a MultiFile with the given name which is nested in the given parent.
Thus data are read/written in the parent file. Upon creation the block size can be given. If 0, it uses the block size of the parent.
References casacore::MultiFileBase::blockSize(), and casacore::name().
|
override |
The destructor flushes and closes the file.
|
delete |
Copy constructor and assignment not possible.
References MultiFile().
|
overridevirtual |
Fsync the file (i.e., force the data to be physically written).
Implements casacore::MultiFileBase.
|
private |
Read the file info for the new version 2.
|
private |
Initialize the MultiFile object.
|
overridevirtual |
Make a nested MultiFile.
Implements casacore::MultiFileBase.
References casacore::MultiFileBase::blockSize(), and casacore::name().
References MultiFile().
Compress a block index by looking for subsequent block numbers.
|
private |
Read the remainder of the header into the buffer.
|
private |
Read a vector of Int64.
|
private |
|
overridevirtual |
Reopen the underlying file for read/write access.
Nothing will be done if the file is writable already. Otherwise it will be reopened and an exception will be thrown if it is not possible to reopen it for read/write access.
Implements casacore::MultiFileBase.
| void casacore::MultiFile::show | ( | std::ostream & | ) | const |
Show some info.
|
private |
Truncate the file if blocks are freed at the end.
|
static |
Decompress a block index by inserting subsequent block numbers.
Header writing hooks (meant for derived test classes).
|
privatevirtual |
|
private |
Write the remainder of the header (in case exceeding 1 block).
iobuf should be large enough
|
private |
Write a vector of Int64.
|
private |