Class OWOWCache
- All Implemented Interfaces:
OCachePointer.WritersListener,OWriteCache
- That we should give room for readers to read data during data write phase
- It provides much less synchronization overhead
Background thread is running by with predefined intervals. Such approach allows SSD GC to use pauses to make some clean up of half empty erase blocks. Also write cache is used for checking of free space left on disk and putting of database in "read mode" if space limit is reached and to perform fuzzy checkpoints. Write cache holds two different type of pages, pages which are shared with read cache and pages which belong only to write cache (so called exclusive pages). Files in write cache are accessed by id , there are two types of ids, internal used inside of write cache and external used outside of write cache. Presence of two types of ids is caused by the fact that read cache is global across all storages but each storage has its own write cache. So all ids of files should be global across whole read cache. External id is created from internal id by prefixing of internal id (in byte presentation) with bytes of write cache id which is unique across all storages opened inside of single JVM. Write cache accepts external ids as file ids and converts them to internal ids inside of its methods.
- Since:
- 7/23/13
- Author:
- Andrey Lomakin (a.lomakin-at-orientdb.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final longMarks pages which have a checksum stored.static final longMarks pages which have a checksum stored and data encrypted -
Constructor Summary
ConstructorsConstructorDescriptionOWOWCache(int pageSize, OByteBufferPool bufferPool, OWriteAheadLog writeAheadLog, DoubleWriteLog doubleWriteLog, long pagesFlushInterval, int shutdownTimeout, long exclusiveWriteCacheMaxSize, Path storagePath, String storageName, OBinarySerializer<String> stringSerializer, OClosableLinkedContainer<Long, OFile> files, int id, OChecksumMode checksumMode, byte[] iv, byte[] aesKey, boolean callFsync, ExecutorService executor) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds listener which is triggered if exception is cast inside background flush data thread.longlongvoidaddOnlyWriters(long fileId, long pageIndex) voidaddPageIsBrokenListener(OPageIsBrokenListener listener) Adds listener which is called by cache if corruption of file page is detected.intallocateNewPage(long fileId) longbookFileId(String fileName) voidbooleancheckStoredPages(OCommandOutputListener commandOutputListener) long[]close()voidclose(long fileId, boolean flush) voidcreate()long[]delete()voiddeleteFile(long fileId) executeDeleteFile(long externalFileId) executeFileFlush(Set<Integer> fileIdSet) voidexecuteFlush(CountDownLatch cacheBoundaryLatch, CountDownLatch completionLatch) executeFlushTillSegment(long segmentId) voidbooleanexists(long fileId) booleanlongexternalFileId(int fileId) Converts unique internal file id to external one.longfileIdByName(String fileName) Returns id associated with given file or value < 0 if such file does not exist.booleanfileIdsAreEqual(long firsId, long secondId) DO NOT DELETE THIS METHOD IT IS USED IN ENTERPRISE STORAGEfileNameById(long fileId) files()voidflush()voidflush(long fileId) voidflushTillSegment(long segmentId) longlonggetFilledUpTo(long fileId) intgetId()Directory which contains all files managed by write cache.intinternalFileId(long fileId) Returns internal file id which is unique and always the same for given file in contrary to external id which changes over close/open cycle of cache.load(long fileId, long startPageIndex, OModifiableBoolean cacheHit, boolean verifyChecksums) longRegisters new file in write cache and returns file id assigned to this file.voidLoads files already registered in storage.nativeFileNameById(long fileId) Obtains native file name by the given file id.voidopen()intpageSize()DO NOT DELETE THIS METHOD IT IS USED IN ENTERPRISE STORAGEvoidRemoves listener which is triggered if exception is cast inside background flush data thread.voidremoveOnlyWriters(long fileId, long pageIndex) voidRemoves listener which is called by cache if corruption of file page is detected.voidrenameFile(long fileId, String newFileName) voidreplaceFileId(long fileId, long newFileId) restoreFileById(long fileId) Finds if there was file in write cache with given id which is deleted right now.voidvoidvoidsetChecksumMode(OChecksumMode checksumMode) voidstore(long fileId, long pageIndex, OCachePointer dataPointer) voidsyncDataFiles(long segmentId, byte[] lastMetadata) voidtruncateFile(long fileId) voidupdateDirtyPagesTable(OCachePointer pointer, OLogSequenceNumber startLSN) Methods inherited from class com.orientechnologies.orient.core.storage.cache.OAbstractWriteCache
checkFileIdCompatibility, composeFileId, extractFileId, extractStorageId
-
Field Details
-
MAGIC_NUMBER_WITH_CHECKSUM
public static final long MAGIC_NUMBER_WITH_CHECKSUMMarks pages which have a checksum stored.- See Also:
-
MAGIC_NUMBER_WITH_CHECKSUM_ENCRYPTED
public static final long MAGIC_NUMBER_WITH_CHECKSUM_ENCRYPTEDMarks pages which have a checksum stored and data encrypted- See Also:
-
CHECKSUM_OFFSET
public static final int CHECKSUM_OFFSET- See Also:
-
-
Constructor Details
-
OWOWCache
public OWOWCache(int pageSize, OByteBufferPool bufferPool, OWriteAheadLog writeAheadLog, DoubleWriteLog doubleWriteLog, long pagesFlushInterval, int shutdownTimeout, long exclusiveWriteCacheMaxSize, Path storagePath, String storageName, OBinarySerializer<String> stringSerializer, OClosableLinkedContainer<Long, OFile> files, int id, OChecksumMode checksumMode, byte[] iv, byte[] aesKey, boolean callFsync, ExecutorService executor)
-
-
Method Details
-
loadRegisteredFiles
Loads files already registered in storage. Has to be called before usage of this cache- Throws:
IOExceptionInterruptedException
-
addBackgroundExceptionListener
Adds listener which is triggered if exception is cast inside background flush data thread.- Specified by:
addBackgroundExceptionListenerin interfaceOWriteCache- Parameters:
listener- Listener to trigger
-
removeBackgroundExceptionListener
Removes listener which is triggered if exception is cast inside background flush data thread.- Specified by:
removeBackgroundExceptionListenerin interfaceOWriteCache- Parameters:
listener- Listener to remove
-
getRootDirectory
Directory which contains all files managed by write cache.- Specified by:
getRootDirectoryin interfaceOWriteCache- Returns:
- Directory which contains all files managed by write cache or
nullin case of in memory database.
-
addPageIsBrokenListener
Description copied from interface:OWriteCacheAdds listener which is called by cache if corruption of file page is detected.- Specified by:
addPageIsBrokenListenerin interfaceOWriteCache
-
removePageIsBrokenListener
Description copied from interface:OWriteCacheRemoves listener which is called by cache if corruption of file page is detected.- Specified by:
removePageIsBrokenListenerin interfaceOWriteCache
-
bookFileId
- Specified by:
bookFileIdin interfaceOWriteCache
-
pageSize
public int pageSize()Description copied from interface:OWriteCacheDO NOT DELETE THIS METHOD IT IS USED IN ENTERPRISE STORAGE- Specified by:
pageSizein interfaceOWriteCache- Returns:
- Size of page inside of cache.
-
loadFile
Description copied from interface:OWriteCacheRegisters new file in write cache and returns file id assigned to this file.File id consist of two parts:
- Internal id is permanent and can not be changed during life of storage
OWriteCache.internalFileId(long) - Write cache id which is changed between storage open/close cycles
If file with the same name is deleted and then new file is created this file with have the same internal id.
- Specified by:
loadFilein interfaceOWriteCache- Parameters:
fileName- Name of file to register inside storage.- Returns:
- Id of registered file
- Throws:
IOException
- Internal id is permanent and can not be changed during life of storage
-
addFile
- Specified by:
addFilein interfaceOWriteCache- Throws:
IOException
-
fileIdByName
Description copied from interface:OWriteCacheReturns id associated with given file or value < 0 if such file does not exist.- Specified by:
fileIdByNamein interfaceOWriteCache- Parameters:
fileName- File name id of which has to be returned.- Returns:
- id associated with given file or value < 0 if such file does not exist.
-
internalFileId
public int internalFileId(long fileId) Description copied from interface:OWriteCacheReturns internal file id which is unique and always the same for given file in contrary to external id which changes over close/open cycle of cache.- Specified by:
internalFileIdin interfaceOWriteCache- Parameters:
fileId- External file id.- Returns:
- Internal file id.
-
externalFileId
public long externalFileId(int fileId) Description copied from interface:OWriteCacheConverts unique internal file id to external one. External id is combination of internal id and write cache id, which changes every time when cache is closed and opened again.- Specified by:
externalFileIdin interfaceOWriteCache- Parameters:
fileId- Internal file id.- Returns:
- External file id.
- See Also:
-
getMinimalNotFlushedSegment
- Specified by:
getMinimalNotFlushedSegmentin interfaceOWriteCache
-
updateDirtyPagesTable
- Specified by:
updateDirtyPagesTablein interfaceOWriteCache
-
create
public void create()- Specified by:
createin interfaceOWriteCache
-
open
public void open()- Specified by:
openin interfaceOWriteCache
-
addFile
- Specified by:
addFilein interfaceOWriteCache- Throws:
IOException
-
checkLowDiskSpace
- Specified by:
checkLowDiskSpacein interfaceOWriteCache- Throws:
IOException
-
syncDataFiles
- Specified by:
syncDataFilesin interfaceOWriteCache- Throws:
IOException
-
flushTillSegment
public void flushTillSegment(long segmentId) - Specified by:
flushTillSegmentin interfaceOWriteCache
-
exists
- Specified by:
existsin interfaceOWriteCache
-
exists
public boolean exists(long fileId) - Specified by:
existsin interfaceOWriteCache
-
restoreModeOn
- Specified by:
restoreModeOnin interfaceOWriteCache- Throws:
IOException
-
restoreModeOff
public void restoreModeOff()- Specified by:
restoreModeOffin interfaceOWriteCache
-
checkCacheOverflow
- Specified by:
checkCacheOverflowin interfaceOWriteCache- Throws:
InterruptedException
-
store
- Specified by:
storein interfaceOWriteCache
-
files
- Specified by:
filesin interfaceOWriteCache
-
load
public OCachePointer load(long fileId, long startPageIndex, OModifiableBoolean cacheHit, boolean verifyChecksums) throws IOException - Specified by:
loadin interfaceOWriteCache- Throws:
IOException
-
allocateNewPage
- Specified by:
allocateNewPagein interfaceOWriteCache- Throws:
IOException
-
addOnlyWriters
public void addOnlyWriters(long fileId, long pageIndex) - Specified by:
addOnlyWritersin interfaceOCachePointer.WritersListener
-
removeOnlyWriters
public void removeOnlyWriters(long fileId, long pageIndex) - Specified by:
removeOnlyWritersin interfaceOCachePointer.WritersListener
-
flush
public void flush(long fileId) - Specified by:
flushin interfaceOWriteCache
-
flush
public void flush()- Specified by:
flushin interfaceOWriteCache
-
getFilledUpTo
public long getFilledUpTo(long fileId) - Specified by:
getFilledUpToin interfaceOWriteCache
-
getExclusiveWriteCachePagesSize
public long getExclusiveWriteCachePagesSize()- Specified by:
getExclusiveWriteCachePagesSizein interfaceOWriteCache
-
deleteFile
- Specified by:
deleteFilein interfaceOWriteCache- Throws:
IOException
-
truncateFile
- Specified by:
truncateFilein interfaceOWriteCache- Throws:
IOException
-
fileIdsAreEqual
public boolean fileIdsAreEqual(long firsId, long secondId) Description copied from interface:OWriteCacheDO NOT DELETE THIS METHOD IT IS USED IN ENTERPRISE STORAGETakes two ids and checks whether they are equal from point of view of write cache. In other words methods checks whether two ids in reality contain the same internal ids.
- Specified by:
fileIdsAreEqualin interfaceOWriteCache
-
renameFile
- Specified by:
renameFilein interfaceOWriteCache- Throws:
IOException
-
replaceFileId
- Specified by:
replaceFileIdin interfaceOWriteCache- Throws:
IOException
-
close
- Specified by:
closein interfaceOWriteCache- Throws:
IOException
-
close
public void close(long fileId, boolean flush) - Specified by:
closein interfaceOWriteCache
-
restoreFileById
Description copied from interface:OWriteCacheFinds if there was file in write cache with given id which is deleted right now. If such file exists it creates new file with the same name at it was in deleted file.- Specified by:
restoreFileByIdin interfaceOWriteCache- Parameters:
fileId- If of file which should be restored- Returns:
- Name of restored file or
nullif such name does not exist - Throws:
IOException
-
checkStoredPages
- Specified by:
checkStoredPagesin interfaceOWriteCache
-
delete
- Specified by:
deletein interfaceOWriteCache- Throws:
IOException
-
fileNameById
- Specified by:
fileNameByIdin interfaceOWriteCache
-
nativeFileNameById
Description copied from interface:OWriteCacheObtains native file name by the given file id.Native file name is a file name of a "physical" on-disk file, it may differ from the "virtual" logical file name.
- Specified by:
nativeFileNameByIdin interfaceOWriteCache- Parameters:
fileId- the file id to obtain the native file name of.- Returns:
- the obtained native file name or
nullif the passed file id doesn't correspond to any file.
-
getId
public int getId()- Specified by:
getIdin interfaceOWriteCache
-
setChecksumMode
-
executeFindDirtySegment
-
executeFileFlush
- Throws:
InterruptedExceptionIOException
-
executeDeleteFile
public ORawPair<String,String> executeDeleteFile(long externalFileId) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
executePeriodicFlush
-
executeFlush
-
executeFlushTillSegment
- Throws:
InterruptedExceptionIOException
-