FileStore

The default storage mechanism of the MVStore. This implementation persists data to a file. The file store is responsible to persist data and for free space management.

Methods
long allocate(int length)
Allocate a number of blocks and mark them as used.
long allocate(int length)
Allocate a number of blocks and mark them as used.
Parameters:
length - the number of bytes to allocate
Returns:
the start position in bytes
void clear()
Mark the file as empty.
void clear()
Mark the file as empty.
void close()
Close this store.
void close()
Close this store.
void free(long pos, int length)
Mark the space as free.
void free(long pos, int length)
Mark the space as free.
Parameters:
pos - the position in bytes
length - the number of bytes
int getDefaultRetentionTime()
Get the default retention time for this store in milliseconds.
int getDefaultRetentionTime()
Get the default retention time for this store in milliseconds.
Returns:
the retention time
FileChannel getEncryptedFile()
Get the encrypted file instance, if encryption is used.
FileChannel getEncryptedFile()
Get the encrypted file instance, if encryption is used.

The application may read from the file (for example for online backup), but not write to it or truncate it.

Returns:
the encrypted file, or null if encryption is not used
FileChannel getFile()
Get the file instance in use.
FileChannel getFile()
Get the file instance in use.

The application may read from the file (for example for online backup), but not write to it or truncate it.

Returns:
the file
long getFileLengthInUse()
long getFileLengthInUse()
String getFileName()
Get the file name.
String getFileName()
Get the file name.
Returns:
the file name
int getFillRate()
int getFillRate()
long getFirstFree()
long getFirstFree()
long getReadBytes()
Get the number of read bytes since this store was opened.
long getReadBytes()
Get the number of read bytes since this store was opened.
Returns:
the number of write operations
long getReadCount()
Get the number of read operations since this store was opened.
long getReadCount()
Get the number of read operations since this store was opened. For file based stores, this is the number of file read operations.
Returns:
the number of read operations
long getWriteBytes()
Get the number of written bytes since this store was opened.
long getWriteBytes()
Get the number of written bytes since this store was opened.
Returns:
the number of write operations
long getWriteCount()
Get the number of write operations since this store was opened.
long getWriteCount()
Get the number of write operations since this store was opened. For file based stores, this is the number of file write operations.
Returns:
the number of write operations
boolean isReadOnly()
boolean isReadOnly()
void markUsed(long pos, int length)
Mark the space as in use.
void markUsed(long pos, int length)
Mark the space as in use.
Parameters:
pos - the position in bytes
length - the number of bytes
void open(String fileName, boolean readOnly, char[] encryptionKey)
Try to open the file.
void open(String fileName, boolean readOnly, char[] encryptionKey)
Try to open the file.
Parameters:
fileName - the file name
readOnly - whether the file should only be opened in read-only mode, even if the file is writable
encryptionKey - the encryption key, or null if encryption is not used
ByteBuffer readFully(long pos, int len)
Read from the file.
ByteBuffer readFully(long pos, int len)
Read from the file.
Parameters:
pos - the write position
len - the number of bytes to read
Returns:
the byte buffer
long size()
Get the file size.
long size()
Get the file size.
Returns:
the file size
void sync()
Flush all changes.
void sync()
Flush all changes.
String toString()
String toString()
void truncate(long size)
Truncate the file.
void truncate(long size)
Truncate the file.
Parameters:
size - the new file size
void writeFully(long pos, ByteBuffer src)
Write to the file.
void writeFully(long pos, ByteBuffer src)
Write to the file.
Parameters:
pos - the write position
src - the source buffer

Fields
static FileChannel encryptedFile
static FileChannel file
static FileLock fileLock
static String fileName
static long fileSize
static FreeSpaceBitSet freeSpace
static AtomicLong readBytes
static AtomicLong readCount
static boolean readOnly
static AtomicLong writeBytes
static AtomicLong writeCount

encryptedFile

The encrypted file (if encryption is used).

file

The file.

fileLock

The file lock.

fileName

The file name.

fileSize

The file size (cached).

freeSpace

The free spaces between the chunks. The first block to use is block 2 (the first two blocks are the store header).

readBytes

The number of read bytes.

readCount

The number of read operations.

readOnly

Whether this store is read-only.

writeBytes

The number of written bytes.

writeCount

The number of write operations.