Class FileStore
- java.lang.Object
-
- org.dizitart.no2.mvstore.compat.v1.mvstore.FileStore
-
public class FileStore extends Object
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.
-
-
Constructor Summary
Constructors Constructor Description FileStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Mark the file as empty.void
close()
Close this store.void
free(long pos, int length)
Mark the space as free.int
getDefaultRetentionTime()
Get the default retention time for this store in milliseconds.FileChannel
getEncryptedFile()
Get the encrypted file instance, if encryption is used.FileChannel
getFile()
Get the file instance in use.String
getFileName()
Get the file name.int
getFillRate()
int
getProjectedFillRate(int vacatedBlocks)
Calculates a prospective fill rate, which store would have after rewrite of sparsely populated chunk(s) and evacuation of still live data into a new chunk.long
getReadBytes()
Get the number of read bytes since this store was opened.long
getReadCount()
Get the number of read operations since this store was opened.long
getWriteBytes()
Get the number of written bytes since this store was opened.long
getWriteCount()
Get the number of write operations since this store was opened.boolean
isReadOnly()
void
markUsed(long pos, int length)
Mark the space as in use.void
open(String fileName, boolean readOnly, char[] encryptionKey)
Try to open the file.ByteBuffer
readFully(long pos, int len)
Read from the file.long
size()
Get the file size.void
sync()
Flush all changes.String
toString()
void
truncate(long size)
Truncate the file.void
writeFully(long pos, ByteBuffer src)
Write to the file.
-
-
-
Method Detail
-
readFully
public ByteBuffer readFully(long pos, int len)
Read from the file.- Parameters:
pos
- the write positionlen
- the number of bytes to read- Returns:
- the byte buffer
-
writeFully
public void writeFully(long pos, ByteBuffer src)
Write to the file.- Parameters:
pos
- the write positionsrc
- the source buffer
-
open
public void open(String fileName, boolean readOnly, char[] encryptionKey)
Try to open the file.- Parameters:
fileName
- the file namereadOnly
- whether the file should only be opened in read-only mode, even if the file is writableencryptionKey
- the encryption key, or null if encryption is not used
-
close
public void close()
Close this store.
-
sync
public void sync()
Flush all changes.
-
size
public long size()
Get the file size.- Returns:
- the file size
-
truncate
public void truncate(long size)
Truncate the file.- Parameters:
size
- the new file size
-
getFile
public 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
-
getEncryptedFile
public 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
-
getWriteCount
public 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
-
getWriteBytes
public long getWriteBytes()
Get the number of written bytes since this store was opened.- Returns:
- the number of write operations
-
getReadCount
public 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
-
getReadBytes
public long getReadBytes()
Get the number of read bytes since this store was opened.- Returns:
- the number of write operations
-
isReadOnly
public boolean isReadOnly()
-
getDefaultRetentionTime
public int getDefaultRetentionTime()
Get the default retention time for this store in milliseconds.- Returns:
- the retention time
-
markUsed
public void markUsed(long pos, int length)
Mark the space as in use.- Parameters:
pos
- the position in byteslength
- the number of bytes
-
free
public void free(long pos, int length)
Mark the space as free.- Parameters:
pos
- the position in byteslength
- the number of bytes
-
getFillRate
public int getFillRate()
-
getProjectedFillRate
public int getProjectedFillRate(int vacatedBlocks)
Calculates a prospective fill rate, which store would have after rewrite of sparsely populated chunk(s) and evacuation of still live data into a new chunk.- Parameters:
vacatedBlocks
- number of blocks vacated- Returns:
- prospective fill rate (0 - 100)
-
clear
public void clear()
Mark the file as empty.
-
getFileName
public String getFileName()
Get the file name.- Returns:
- the file name
-
-