Package org.rocksdb

Class SstFileManager

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public final class SstFileManager
    extends RocksObject
    SstFileManager is used to track SST files in the DB and control their deletion rate. All SstFileManager public functions are thread-safe. SstFileManager is not extensible.
    • Field Detail

      • RATE_BYTES_PER_SEC_DEFAULT

        public static final long RATE_BYTES_PER_SEC_DEFAULT
        See Also:
        Constant Field Values
      • DELETE_EXISTING_TRASH_DEFAULT

        public static final boolean DELETE_EXISTING_TRASH_DEFAULT
        See Also:
        Constant Field Values
      • MAX_TRASH_DB_RATION_DEFAULT

        public static final double MAX_TRASH_DB_RATION_DEFAULT
        See Also:
        Constant Field Values
      • BYTES_MAX_DELETE_CHUNK_DEFAULT

        public static final long BYTES_MAX_DELETE_CHUNK_DEFAULT
        See Also:
        Constant Field Values
    • Constructor Detail

      • SstFileManager

        public SstFileManager​(Env env)
                       throws RocksDBException
        Create a new SstFileManager that can be shared among multiple RocksDB instances to track SST file and control there deletion rate.
        Parameters:
        env - the environment.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • SstFileManager

        public SstFileManager​(Env env,
                              Logger logger)
                       throws RocksDBException
        Create a new SstFileManager that can be shared among multiple RocksDB instances to track SST file and control there deletion rate.
        Parameters:
        env - the environment.
        logger - if not null, the logger will be used to log errors.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • SstFileManager

        public SstFileManager​(Env env,
                              Logger logger,
                              long rateBytesPerSec)
                       throws RocksDBException
        Create a new SstFileManager that can be shared among multiple RocksDB instances to track SST file and control there deletion rate.
        Parameters:
        env - the environment.
        logger - if not null, the logger will be used to log errors. == Deletion rate limiting specific arguments ==
        rateBytesPerSec - how many bytes should be deleted per second, If this value is set to 1024 (1 Kb / sec) and we deleted a file of size 4 Kb in 1 second, we will wait for another 3 seconds before we delete other files, Set to 0 to disable deletion rate limiting.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • SstFileManager

        public SstFileManager​(Env env,
                              Logger logger,
                              long rateBytesPerSec,
                              double maxTrashDbRatio)
                       throws RocksDBException
        Create a new SstFileManager that can be shared among multiple RocksDB instances to track SST file and control there deletion rate.
        Parameters:
        env - the environment.
        logger - if not null, the logger will be used to log errors. == Deletion rate limiting specific arguments ==
        rateBytesPerSec - how many bytes should be deleted per second, If this value is set to 1024 (1 Kb / sec) and we deleted a file of size 4 Kb in 1 second, we will wait for another 3 seconds before we delete other files, Set to 0 to disable deletion rate limiting.
        maxTrashDbRatio - if the trash size constitutes for more than this fraction of the total DB size we will start deleting new files passed to DeleteScheduler immediately.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • SstFileManager

        public SstFileManager​(Env env,
                              Logger logger,
                              long rateBytesPerSec,
                              double maxTrashDbRatio,
                              long bytesMaxDeleteChunk)
                       throws RocksDBException
        Create a new SstFileManager that can be shared among multiple RocksDB instances to track SST file and control there deletion rate.
        Parameters:
        env - the environment.
        logger - if not null, the logger will be used to log errors. == Deletion rate limiting specific arguments ==
        rateBytesPerSec - how many bytes should be deleted per second, If this value is set to 1024 (1 Kb / sec) and we deleted a file of size 4 Kb in 1 second, we will wait for another 3 seconds before we delete other files, Set to 0 to disable deletion rate limiting.
        maxTrashDbRatio - if the trash size constitutes for more than this fraction of the total DB size we will start deleting new files passed to DeleteScheduler immediately.
        bytesMaxDeleteChunk - if a single file is larger than delete chunk, ftruncate the file by this size each time, rather than dropping the whole file. 0 means to always delete the whole file.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
    • Method Detail

      • setMaxAllowedSpaceUsage

        public void setMaxAllowedSpaceUsage​(long maxAllowedSpace)
        Update the maximum allowed space that should be used by RocksDB, if the total size of the SST files exceeds maxAllowedSpace, writes to RocksDB will fail. Setting maxAllowedSpace to 0 will disable this feature; maximum allowed space will be infinite (Default value).
        Parameters:
        maxAllowedSpace - the maximum allowed space that should be used by RocksDB.
      • setCompactionBufferSize

        public void setCompactionBufferSize​(long compactionBufferSize)
        Set the amount of buffer room each compaction should be able to leave. In other words, at its maximum disk space consumption, the compaction should still leave compactionBufferSize available on the disk so that other background functions may continue, such as logging and flushing.
        Parameters:
        compactionBufferSize - the amount of buffer room each compaction should be able to leave.
      • isMaxAllowedSpaceReached

        public boolean isMaxAllowedSpaceReached()
        Determines if the total size of SST files exceeded the maximum allowed space usage.
        Returns:
        true when the maximum allows space usage has been exceeded.
      • isMaxAllowedSpaceReachedIncludingCompactions

        public boolean isMaxAllowedSpaceReachedIncludingCompactions()
        Determines if the total size of SST files as well as estimated size of ongoing compactions exceeds the maximums allowed space usage.
        Returns:
        true when the total size of SST files as well as estimated size of ongoing compactions exceeds the maximums allowed space usage.
      • getTotalSize

        public long getTotalSize()
        Get the total size of all tracked files.
        Returns:
        the total size of all tracked files.
      • getTrackedFiles

        public java.util.Map<java.lang.String,​java.lang.Long> getTrackedFiles()
        Gets all tracked files and their corresponding sizes.
        Returns:
        a map containing all tracked files and there corresponding sizes.
      • getDeleteRateBytesPerSecond

        public long getDeleteRateBytesPerSecond()
        Gets the delete rate limit.
        Returns:
        the delete rate limit (in bytes per second).
      • setDeleteRateBytesPerSecond

        public void setDeleteRateBytesPerSecond​(long deleteRate)
        Set the delete rate limit. Zero means disable delete rate limiting and delete files immediately.
        Parameters:
        deleteRate - the delete rate limit (in bytes per second).
      • getMaxTrashDBRatio

        public double getMaxTrashDBRatio()
        Get the trash/DB size ratio where new files will be deleted immediately.
        Returns:
        the trash/DB size ratio.
      • setMaxTrashDBRatio

        public void setMaxTrashDBRatio​(double ratio)
        Set the trash/DB size ratio where new files will be deleted immediately.
        Parameters:
        ratio - the trash/DB size ratio.