Class ODirectMemoryOnlyDiskCache

java.lang.Object
com.orientechnologies.orient.core.storage.cache.OAbstractWriteCache
com.orientechnologies.orient.core.storage.memory.ODirectMemoryOnlyDiskCache
All Implemented Interfaces:
OReadCache, OWriteCache

public final class ODirectMemoryOnlyDiskCache extends OAbstractWriteCache implements OReadCache, OWriteCache
Since:
6/24/14
Author:
Andrey Lomakin (a.lomakin-at-orientdb.com)
  • Method Details

    • getRootDirectory

      public final Path getRootDirectory()
      Directory which contains all files managed by write cache.
      Specified by:
      getRootDirectory in interface OWriteCache
      Returns:
      Directory which contains all files managed by write cache or null in case of in memory database.
    • addFile

      public final long addFile(String fileName, OWriteCache writeCache)
      Specified by:
      addFile in interface OReadCache
    • fileIdByName

      public final long fileIdByName(String fileName)
      Description copied from interface: OWriteCache
      Returns id associated with given file or value < 0 if such file does not exist.
      Specified by:
      fileIdByName in interface OWriteCache
      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 final int internalFileId(long fileId)
      Description copied from interface: OWriteCache
      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.
      Specified by:
      internalFileId in interface OWriteCache
      Parameters:
      fileId - External file id.
      Returns:
      Internal file id.
    • externalFileId

      public final long externalFileId(int fileId)
      Description copied from interface: OWriteCache
      Converts 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:
      externalFileId in interface OWriteCache
      Parameters:
      fileId - Internal file id.
      Returns:
      External file id.
      See Also:
    • bookFileId

      public final long bookFileId(String fileName)
      Specified by:
      bookFileId in interface OWriteCache
    • addBackgroundExceptionListener

      public final void addBackgroundExceptionListener(OBackgroundExceptionListener listener)
      Description copied from interface: OWriteCache
      Adds listener which is triggered if exception is cast inside background flush data thread.
      Specified by:
      addBackgroundExceptionListener in interface OWriteCache
      Parameters:
      listener - Listener to trigger
    • removeBackgroundExceptionListener

      public final void removeBackgroundExceptionListener(OBackgroundExceptionListener listener)
      Description copied from interface: OWriteCache
      Removes listener which is triggered if exception is cast inside background flush data thread.
      Specified by:
      removeBackgroundExceptionListener in interface OWriteCache
      Parameters:
      listener - Listener to remove
    • checkCacheOverflow

      public final void checkCacheOverflow()
      Specified by:
      checkCacheOverflow in interface OWriteCache
    • addFile

      public final long addFile(String fileName, long fileId, OWriteCache writeCache)
      Specified by:
      addFile in interface OReadCache
    • loadForWrite

      public final OCacheEntry loadForWrite(long fileId, long pageIndex, OWriteCache writeCache, boolean verifyChecksums, OLogSequenceNumber startLSN)
      Specified by:
      loadForWrite in interface OReadCache
    • loadForRead

      public final OCacheEntry loadForRead(long fileId, long pageIndex, OWriteCache writeCache, boolean verifyChecksums)
      Specified by:
      loadForRead in interface OReadCache
    • silentLoadForRead

      public OCacheEntry silentLoadForRead(long extFileId, int pageIndex, OWriteCache writeCache, boolean verifyChecksums)
      Specified by:
      silentLoadForRead in interface OReadCache
    • allocateNewPage

      public final OCacheEntry allocateNewPage(long fileId, OWriteCache writeCache, OLogSequenceNumber startLSN)
      Specified by:
      allocateNewPage in interface OReadCache
    • allocateNewPage

      public int allocateNewPage(long fileId)
      Specified by:
      allocateNewPage in interface OWriteCache
    • releaseFromWrite

      public final void releaseFromWrite(OCacheEntry cacheEntry, OWriteCache writeCache, boolean changed)
      Specified by:
      releaseFromWrite in interface OReadCache
    • releaseFromRead

      public final void releaseFromRead(OCacheEntry cacheEntry)
      Specified by:
      releaseFromRead in interface OReadCache
    • getFilledUpTo

      public final long getFilledUpTo(long fileId)
      Specified by:
      getFilledUpTo in interface OWriteCache
    • flush

      public final void flush(long fileId)
      Specified by:
      flush in interface OWriteCache
    • close

      public final void close(long fileId, boolean flush)
      Specified by:
      close in interface OWriteCache
    • deleteFile

      public final void deleteFile(long fileId)
      Specified by:
      deleteFile in interface OWriteCache
    • renameFile

      public final void renameFile(long fileId, String newFileName)
      Specified by:
      renameFile in interface OWriteCache
    • truncateFile

      public final void truncateFile(long fileId)
      Specified by:
      truncateFile in interface OWriteCache
    • flush

      public final void flush()
      Specified by:
      flush in interface OWriteCache
    • close

      public final long[] close()
      Specified by:
      close in interface OWriteCache
    • clear

      public final void clear()
      Specified by:
      clear in interface OReadCache
    • delete

      public final long[] delete()
      Specified by:
      delete in interface OWriteCache
    • replaceFileId

      public void replaceFileId(long fileId, long newFileId) throws IOException
      Specified by:
      replaceFileId in interface OWriteCache
      Throws:
      IOException
    • deleteStorage

      public final void deleteStorage(OWriteCache writeCache)
      Specified by:
      deleteStorage in interface OReadCache
    • closeStorage

      public final void closeStorage(OWriteCache writeCache)
      Closes all files inside of write cache and flushes all associated data.
      Specified by:
      closeStorage in interface OReadCache
      Parameters:
      writeCache - Write cache to close.
    • changeMaximumAmountOfMemory

      public void changeMaximumAmountOfMemory(long calculateReadCacheMaxMemory)
      Specified by:
      changeMaximumAmountOfMemory in interface OReadCache
    • checkStoredPages

      public final OPageDataVerificationError[] checkStoredPages(OCommandOutputListener commandOutputListener)
      Specified by:
      checkStoredPages in interface OWriteCache
    • exists

      public final boolean exists(String name)
      Specified by:
      exists in interface OWriteCache
    • exists

      public final boolean exists(long fileId)
      Specified by:
      exists in interface OWriteCache
    • restoreModeOn

      public void restoreModeOn()
      Specified by:
      restoreModeOn in interface OWriteCache
    • restoreModeOff

      public void restoreModeOff()
      Specified by:
      restoreModeOff in interface OWriteCache
    • fileNameById

      public final String fileNameById(long fileId)
      Specified by:
      fileNameById in interface OWriteCache
    • nativeFileNameById

      public final String nativeFileNameById(long fileId)
      Description copied from interface: OWriteCache
      Obtains 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:
      nativeFileNameById in interface OWriteCache
      Parameters:
      fileId - the file id to obtain the native file name of.
      Returns:
      the obtained native file name or null if the passed file id doesn't correspond to any file.
    • getUsedMemory

      public final long getUsedMemory()
      Specified by:
      getUsedMemory in interface OReadCache
    • checkLowDiskSpace

      public final boolean checkLowDiskSpace()
      Specified by:
      checkLowDiskSpace in interface OWriteCache
    • addPageIsBrokenListener

      public final void addPageIsBrokenListener(OPageIsBrokenListener listener)
      Not implemented because has no sense
      Specified by:
      addPageIsBrokenListener in interface OWriteCache
    • removePageIsBrokenListener

      public final void removePageIsBrokenListener(OPageIsBrokenListener listener)
      Not implemented because has no sense
      Specified by:
      removePageIsBrokenListener in interface OWriteCache
    • loadFile

      public final long loadFile(String fileName)
      Description copied from interface: OWriteCache
      Registers new file in write cache and returns file id assigned to this file.

      File id consist of two parts:

      1. Internal id is permanent and can not be changed during life of storage OWriteCache.internalFileId(long)
      2. 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:
      loadFile in interface OWriteCache
      Parameters:
      fileName - Name of file to register inside storage.
      Returns:
      Id of registered file
    • addFile

      public final long addFile(String fileName)
      Specified by:
      addFile in interface OWriteCache
    • addFile

      public final long addFile(String fileName, long fileId)
      Specified by:
      addFile in interface OWriteCache
    • store

      public final void store(long fileId, long pageIndex, OCachePointer dataPointer)
      Specified by:
      store in interface OWriteCache
    • syncDataFiles

      public final void syncDataFiles(long segmentId, byte[] lastMetadata)
      Specified by:
      syncDataFiles in interface OWriteCache
    • flushTillSegment

      public final void flushTillSegment(long segmentId)
      Specified by:
      flushTillSegment in interface OWriteCache
    • getMinimalNotFlushedSegment

      public final Long getMinimalNotFlushedSegment()
      Specified by:
      getMinimalNotFlushedSegment in interface OWriteCache
    • updateDirtyPagesTable

      public final void updateDirtyPagesTable(OCachePointer pointer, OLogSequenceNumber startLSN)
      Specified by:
      updateDirtyPagesTable in interface OWriteCache
    • create

      public void create()
      Specified by:
      create in interface OWriteCache
    • open

      public void open()
      Specified by:
      open in interface OWriteCache
    • load

      public final OCachePointer load(long fileId, long startPageIndex, OModifiableBoolean cacheHit, boolean verifyChecksums)
      Specified by:
      load in interface OWriteCache
    • getExclusiveWriteCachePagesSize

      public final long getExclusiveWriteCachePagesSize()
      Specified by:
      getExclusiveWriteCachePagesSize in interface OWriteCache
    • truncateFile

      public final void truncateFile(long fileId, OWriteCache writeCache)
      Specified by:
      truncateFile in interface OReadCache
    • getId

      public final int getId()
      Specified by:
      getId in interface OWriteCache
    • files

      public final Map<String,Long> files()
      Specified by:
      files in interface OWriteCache
    • pageSize

      public final int pageSize()
      Description copied from interface: OWriteCache
      DO NOT DELETE THIS METHOD IT IS USED IN ENTERPRISE STORAGE
      Specified by:
      pageSize in interface OWriteCache
      Returns:
      Size of page inside of cache.
    • fileIdsAreEqual

      public final boolean fileIdsAreEqual(long firsId, long secondId)
      Description copied from interface: OWriteCache
      DO NOT DELETE THIS METHOD IT IS USED IN ENTERPRISE STORAGE

      Takes 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:
      fileIdsAreEqual in interface OWriteCache
    • restoreFileById

      public final String restoreFileById(long fileId)
      Description copied from interface: OWriteCache
      Finds 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:
      restoreFileById in interface OWriteCache
      Parameters:
      fileId - If of file which should be restored
      Returns:
      Name of restored file or null if such name does not exist
    • closeFile

      public final void closeFile(long fileId, boolean flush, OWriteCache writeCache)
      Specified by:
      closeFile in interface OReadCache
    • deleteFile

      public final void deleteFile(long fileId, OWriteCache writeCache)
      Specified by:
      deleteFile in interface OReadCache