### Build python-rocksdb from Git Source Source: https://python-rocksdb.readthedocs.io/en/latest/installation Installs python-rocksdb directly from its Git repository. This method also sets up a virtual environment and installs necessary Python development headers. ```shell apt-get install python-virtualenv python-dev virtualenv venv source venv/bin/activate pip install git+git://github.com/twmht/python-rocksdb.git#egg=python-rocksdb ``` -------------------------------- ### Basic RocksDB Operations in Python Source: https://python-rocksdb.readthedocs.io/en/latest/index Demonstrates basic put and get operations using the python-rocksdb library. Requires the rocksdb library to be installed. It initializes a RocksDB database, puts a key-value pair, and retrieves the value. ```python import rocksdb db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True)) db.put(b"a", b"b") print db.get(b"a") ``` -------------------------------- ### Install python-rocksdb with Distro Package and PyPI Source: https://python-rocksdb.readthedocs.io/en/latest/installation Installs python-rocksdb using apt-get for dependencies and pip for the package itself. This method requires librocksdb-dev to be at least version 5.0. It also sets up a virtual environment. ```shell apt-get install python-virtualenv python-dev librocksdb-dev virtualenv venv source venv/bin/activate pip install python-rocksdb ``` -------------------------------- ### Systemwide RocksDB Installation Source: https://python-rocksdb.readthedocs.io/en/latest/installation Command to install the shared RocksDB library systemwide after building it from source. This places the shared library in `/usr/lib/` and header files in `/usr/include/rocksdb/`. ```shell make install-shared INSTALL_PATH=/usr ``` -------------------------------- ### Build RocksDB Core Library from Source Source: https://python-rocksdb.readthedocs.io/en/latest/installation Steps to build the core RocksDB library from its source code on Debian/Ubuntu systems. This involves installing build dependencies, cloning the repository, configuring with CMake, and compiling. Details for more advanced configurations can be found in the RocksDB INSTALL.md file. ```shell apt-get install build-essential libsnappy-dev zlib1g-dev libbz2-dev libgflags-dev git clone https://github.com/facebook/rocksdb.git cd rocksdb mkdir build && cd build cmake .. make ``` -------------------------------- ### Configure Local RocksDB Environment Variables Source: https://python-rocksdb.readthedocs.io/en/latest/installation Sets environment variables for C++ include paths, library paths, and loader paths to enable a local installation of RocksDB without systemwide permissions. ```shell export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:`pwd`/../include export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:`pwd` export LIBRARY_PATH=${LIBRARY_PATH}:`pwd` ``` -------------------------------- ### Get RocksDB Options in Python Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Retrieves the associated `rocksdb.Options` instance, providing access to the configuration settings for the RocksDB database. ```python options() Returns the associated `rocksdb.Options` instance. ``` -------------------------------- ### Uninstall Systemwide RocksDB Source: https://python-rocksdb.readthedocs.io/en/latest/installation Command to uninstall a systemwide installation of the RocksDB shared library. ```shell make uninstall INSTALL_PATH=/usr ``` -------------------------------- ### Basic Data Access (Put, Get, Delete) Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Illustrates the fundamental data access operations in RocksDB using python-rocksdb: storing data with `put`, retrieving data with `get`, and removing data with `delete`. All operations use byte strings. ```python # Store db.put(b"key", b"value") # Get db.get(b"key") # Delete db.delete(b"key") ``` -------------------------------- ### Snapshot Usage Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Demonstrates how to use snapshots to get a consistent view of the database at a specific point in time. Reads made using a snapshot are unaffected by subsequent writes or deletions. ```python self.db.put(b"a", b"1") self.db.put(b"b", b"2") snapshot = self.db.snapshot() self.db.put(b"a", b"2") self.db.delete(b"b") it = self.db.iteritems() it.seek_to_first() # prints {b'a': b'2'} print dict(it) it = self.db.iteritems(snapshot=snapshot) it.seek_to_first() # prints {b'a': b'1', b'b': b'2'} print dict(it) ``` -------------------------------- ### Get Operation Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Retrieves a value from the RocksDB database using a byte key. Assumes a database object 'db' is already initialized. ```python print db.get(b"a") ``` -------------------------------- ### Get Backup Information Source: https://python-rocksdb.readthedocs.io/en/latest/api/backup Retrieves information about all available backups. ```APIDOC ## Get Backup Information ### Description Returns a list containing information about all recorded backups. ### Method get_backup_info ### Response #### Success Response (200) - **backup_id** (int) - The unique identifier for the backup. - **timestamp** (int) - The Unix timestamp (seconds since epoch) when the backup was created. - **size** (int) - The size of the backup in bytes. ### Response Example ```json { "backup_id": 1, "timestamp": 1678886400, "size": 10485760 } ``` ```json [ { "backup_id": 1, "timestamp": 1678886400, "size": 10485760 }, { "backup_id": 2, "timestamp": 1678972800, "size": 12582912 } ] ``` ``` -------------------------------- ### Iterate and Filter Keys with itertools.takewhile (Python) Source: https://python-rocksdb.readthedocs.io/en/latest/changelog Demonstrates how to iterate through keys in a RocksDB database, seek to a specific key, and use `itertools.takewhile` to filter keys that start with a given prefix. This is a workaround for the removal of the `prefix` parameter in iterator methods. ```python from itertools import takewhile it = self.db.iterkeys() it.seek(b'00002') print list(takewhile(lambda key: key.startswith(b'00002'), it)) ``` ```python it = self.db.iteritems() it.seek(b'00002') print dict(takewhile(lambda item: item[0].startswith(b'00002'), it)) ``` -------------------------------- ### Initialize BackupEngine Source: https://python-rocksdb.readthedocs.io/en/latest/api/backup Creates a BackupEngine instance to manage backups for a single RocksDB database. Requires the path to the backup directory, which must be different from the database directory. ```python backup_engine = rocksdb.BackupEngine(backup_dir='/path/to/backups') ``` -------------------------------- ### Open RocksDB Database (Simple) Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Demonstrates the most basic way to open a RocksDB database using python-rocksdb. It initializes the database with default options, creating the database file if it doesn't exist. ```python import rocksdb db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True)) ``` -------------------------------- ### Open RocksDB Database (Production-Ready) Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Shows how to open a RocksDB database with advanced production-ready options. This includes configuring cache size, write buffer, file target size, and using a BlockBasedTableFactory with a Bloom filter for optimized performance. ```python import rocksdb opts = rocksdb.Options() opts.create_if_missing = True opts.max_open_files = 300000 opts.write_buffer_size = 67108864 opts.max_write_buffer_number = 3 opts.target_file_size_base = 67108864 opts.table_factory = rocksdb.BlockBasedTableFactory( filter_policy=rocksdb.BloomFilterPolicy(10), block_cache=rocksdb.LRUCache(2 * (1024 ** 3)), block_cache_compressed=rocksdb.LRUCache(500 * (1024 ** 2))) db = rocksdb.DB("test.db", opts) ``` -------------------------------- ### Create RocksDB Options with Constructor Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Demonstrates how to initialize a RocksDB Options object using keyword arguments in the constructor. This allows for setting specific configuration parameters like 'create_if_missing' upon object creation. ```python import rocksdb opts = rocksdb.Options(create_if_missing=True) ``` -------------------------------- ### Associative Merge Operator Example Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Provides an example of implementing an `AssociativeMergeOperator` for RocksDB. This merge operator increments a counter stored as a string, demonstrating efficient read-modify-write operations. ```python class AssocCounter(rocksdb.interfaces.AssociativeMergeOperator): def merge(self, key, existing_value, value): if existing_value: s = int(existing_value) + int(value) return (True, str(s).encode('ascii')) return (True, value) def name(self): return b'AssocCounter' opts = rocksdb.Options() opts.create_if_missing = True opts.merge_operator = AssocCounter() db = rocksdb.DB('test.db', opts) db.merge(b"a", b"1") db.merge(b"a", b"1") ``` -------------------------------- ### BackupEngine Initialization Source: https://python-rocksdb.readthedocs.io/en/latest/api/backup Initializes the BackupEngine to manage backups for a single database. ```APIDOC ## BackupEngine ### Description Initializes the BackupEngine to manage backups for a single database. ### Method __init__ ### Parameters #### Path Parameters * **backup_dir** (unicode) - Required - The directory where backup files will be stored. This must be different from the database directory. ### Request Example ```python # Example usage (not a direct request/response format) backup_engine = rocksdb.BackupEngine('path/to/backups') ``` ``` -------------------------------- ### Compaction Options Configuration Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Demonstrates how to configure universal compaction options, specifically the stop style. ```APIDOC ## Compaction Options Configuration ### Description Allows configuration of compaction strategies, including the method used to stop picking files into a single compaction. ### Method Update options object ### Endpoint N/A (Configuration within the RocksDB client) ### Parameters #### Request Body - **compaction_options_universal** (dict) - Optional - A dictionary to set universal compaction options. - **stop_style** (string) - Optional - The algorithm to stop picking files. Can be either `"similar_size"` or `"total_size"`. Defaults to `"total_size"`. ### Request Example ```python opts = rocksdb.Options() opts.compaction_options_universal = {'stop_style': 'similar_size'} ``` ### Response #### Success Response (200) N/A (Configuration is applied directly) #### Response Example N/A ``` -------------------------------- ### RocksDB Options Reference Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Reference for various RocksDB configuration options. ```APIDOC ## RocksDB Options Reference ### `max_sequential_skip_in_iterations` #### Description Specifies the number of keys (with the same userkey) that will be sequentially skipped before a reseek is issued during iteration. #### Type `int` #### Default `8` ### `memtable_factory` #### Description Sets the factory for creating MemTableRep objects. Supported factories include `rocksdb.VectorMemtableFactory`, `rocksdb.SkipListMemtableFactory`, `rocksdb.HashSkipListMemtableFactory`, and `rocksdb.HashLinkListMemtableFactory`. #### Default `rocksdb.SkipListMemtableFactory` ### `table_factory` #### Description Configures the factory for SST-Files (persistent data storage). Supported factories include `rocksdb.BlockBasedTableFactory`, `rocksdb.PlainTableFactory`, and `rocksdb.TotalOrderPlainTableFactory`. #### Default `rocksdb.BlockBasedTableFactory` ### `inplace_update_support` #### Description Enables thread-safe in-place updates. Requires specific conditions for updates to occur in-place. #### Type `bool` #### Default `False` ### `inplace_update_num_locks` #### Description Determines the number of locks used for in-place updates. #### Type `int` #### Default `10000` (if `inplace_update_support` is true, else 0) ### `comparator` #### Description Specifies the comparator used for ordering keys. The provided comparator must have the same name and ordering semantics as used in previous open calls for the same DB. #### Default `rocksdb.BytewiseComparator` ### `merge_operator` #### Description Assigns a merge operator for handling Merge operations. If no merge operator is provided, Merge operations will not be supported. The operator must have consistent naming and semantics with previous calls, unless it's the first time a merge operator is introduced. #### Default `None` ### `prefix_extractor` #### Description If set, uses a specified function to extract prefixes for keys, which are then included in the filter. This can optimize scan operations by reducing read-IOP costs when prefixes are provided. #### Default `None` ### `row_cache` #### Description Configures a global cache for table-level rows. If `None`, no row cache is used. Otherwise, it must be an instance of `rocksdb.LRUCache`. #### Default `None` ``` -------------------------------- ### Create a Backup Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Creates a backup of a live RocksDB database. The `flush_before_backup` option ensures the memtable is flushed before the backup is created. ```python import rocksdb # Assuming db is an initialized rocksdb.DB object db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True)) backup = rocksdb.BackupEngine("test.db/backups") backup.create_backup(db, flush_before_backup=True) ``` -------------------------------- ### Initialize RocksDB and Add Data Source: https://python-rocksdb.readthedocs.io/en/latest/tutorial/index Initializes a RocksDB database and adds key-value pairs. This is a prerequisite for backup operations. ```python import rocksdb db = rocksdb.DB("test.db", rocksdb.Options(create_if_missing=True)) db.put(b'a', b'v1') db.put(b'b', b'v2') db.put(b'c', b'v3') ``` -------------------------------- ### Purge Old RocksDB Backups Source: https://python-rocksdb.readthedocs.io/en/latest/api/backup Deletes older backups, retaining only the specified number of most recent backups. Backups are deleted starting from the oldest. ```python backup_engine.purge_old_backups(num_backups_to_keep=5) ``` -------------------------------- ### Get RocksDB Backup Information Source: https://python-rocksdb.readthedocs.io/en/latest/api/backup Retrieves a list of dictionaries containing information about all available backups. Each dictionary includes backup ID, timestamp, and size. ```python backup_info = backup_engine.get_backup_info() for info in backup_info: print(f"Backup ID: {info['backup_id']}, Timestamp: {info['timestamp']}, Size: {info['size']} bytes") ``` -------------------------------- ### Multi-Get Values by Keys from RocksDB Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Fetches values for multiple keys in a single operation, returning them as a dictionary. It accepts the same optional parameters as `get` for read consistency and caching. Raises an error if any single key fetch fails. ```python results = db.multi_get(keys, verify_checksums=False, fill_cache=True, snapshot=None, read_tier='all') ``` -------------------------------- ### RocksDB BackupEngine Methods Source: https://python-rocksdb.readthedocs.io/en/latest/genindex Documentation for methods related to the RocksDB BackupEngine, used for managing backups and restoring database states. ```APIDOC ## RocksDB BackupEngine Methods Documentation for methods related to the RocksDB BackupEngine, used for managing backups and restoring database states. ### BackupEngine Methods - **purge_old_backups()** (rocksdb.BackupEngine method): Removes old backup files. - **restore_backup()** (rocksdb.BackupEngine method): Restores the database from a specific backup. - **restore_latest_backup()** (rocksdb.BackupEngine method): Restores the database from the most recent backup. - **stop_backup()** (rocksdb.BackupEngine method): Stops an ongoing backup process. ``` -------------------------------- ### RocksDB Configuration Options Source: https://python-rocksdb.readthedocs.io/en/latest/api/options This section details various configuration options for RocksDB, covering aspects like WAL retention, manifest preallocation, key purging, memory mapping, file descriptor handling, statistics dumping, adaptive mutexes, and synchronization. ```APIDOC ## WAL Configuration ### Description Configuration related to Write-Ahead Logging (WAL) behavior, including time-to-live and size limits for WAL files. ### Parameters #### Query Parameters - **wal_ttl_seconds** (int) - Optional - Time-to-live for WAL files in seconds. If 0, TTL is disabled. - **wal_size_limit_mb** (int) - Optional - Maximum size limit for WAL files in megabytes. If 0, size limit is disabled. ### Usage Scenarios 1. If `wal_ttl_seconds` is 0 and `wal_size_limit_mb` is not 0, WAL files are checked every 10 minutes, and if their total size exceeds `wal_size_limit_mb`, the oldest files are deleted until the size limit is met. All empty files are also deleted. 2. If `wal_ttl_seconds` is not 0 and `wal_size_limit_mb` is 0, WAL files are checked every `wal_ttl_seconds / 2`, and files older than `wal_ttl_seconds` are deleted. 3. If both `wal_ttl_seconds` and `wal_size_limit_mb` are not 0, WAL files are checked every 10 minutes, and both TTL and size limit checks are performed, with TTL being checked first. ``` ```APIDOC ## Manifest Preallocation ### Description Configures the size in bytes to preallocate for manifest files using `fallocate`. This helps reduce random I/O and prevent overallocation on certain file systems. ### Parameters #### Query Parameters - **manifest_preallocation_size** (int) - Optional - Number of bytes to preallocate for manifest files. Defaults to 4MB (4194304 bytes). ``` ```APIDOC ## Purge Redundant KVs During Flush ### Description Determines whether duplicate or deleted keys should be purged when a memtable is flushed to storage. ### Parameters #### Query Parameters - **purge_redundant_kvs_while_flush** (bool) - Optional - If true, purges redundant keys during flush. Defaults to `True`. ``` ```APIDOC ## Memory Mapping Options ### Description Controls the use of memory mapping (mmap) for reading and writing SST (Sorted String Table) files. ### Parameters #### Query Parameters - **allow_mmap_reads** (bool) - Optional - If true, allows the OS to memory map files for reading SST tables. Defaults to `True`. - **allow_mmap_writes** (bool) - Optional - If true, allows the OS to memory map files for writing. Defaults to `False`. ``` ```APIDOC ## File Descriptor Handling ### Description Configures whether file descriptors should be closed on exec, preventing child processes from inheriting open file handles. ### Parameters #### Query Parameters - **is_fd_close_on_exec** (bool) - Optional - If true, disables child process inheritance of open files. Defaults to `True`. ``` ```APIDOC ## Skip Log Error on Recovery ### Description Allows skipping log corruption errors during recovery, which might result in the loss of recent changes. ### Parameters #### Query Parameters - **skip_log_error_on_recovery** (bool) - Optional - If true, skips log corruption errors during recovery. Defaults to `False`. ``` ```APIDOC ## Statistics Dump Period ### Description Specifies the interval in seconds for dumping RocksDB statistics to the log file. ### Parameters #### Query Parameters - **stats_dump_period_sec** (int) - Optional - Interval in seconds for dumping stats. If zero, statistics are not dumped periodically. Defaults to 3600 seconds (1 hour). ``` ```APIDOC ## Advise Random Access on Open ### Description Hints to the underlying file system that file access patterns will be random when opening SST files. ### Parameters #### Query Parameters - **advise_random_on_open** (bool) - Optional - If true, advises the file system for random access on file open. Defaults to `True`. ``` ```APIDOC ## Adaptive Mutex Usage ### Description Enables the use of an adaptive mutex, which spins in user space before resorting to kernel-level synchronization. This can reduce context switches when the mutex is not heavily contended but may waste CPU cycles if the mutex is frequently contended. ### Parameters #### Query Parameters - **use_adaptive_mutex** (bool) - Optional - If true, uses an adaptive mutex. Defaults to `False`. ``` ```APIDOC ## Bytes Per Sync ### Description Allows the operating system to incrementally sync files to disk asynchronously as they are being written. A request is issued for every `bytes_per_sync` written. ### Parameters #### Query Parameters - **bytes_per_sync** (int) - Optional - Number of bytes written before issuing an asynchronous sync request. If 0, this feature is turned off. Defaults to 0. ``` ```APIDOC ## Compaction Style ### Description Specifies the style of compaction to be used by RocksDB. ### Parameters #### Query Parameters - **compaction_style** (string) - Optional - The compaction style. Possible values: `"level"` (level-style), `"universal"` (universal-style), `"fifo"` (FIFO compaction), `"none"` (no compaction). Defaults to `"level"`. ``` ```APIDOC ## Compaction Priority ### Description Determines the priority of files to be picked for compaction within each level when using level-style compaction. ### Parameters #### Query Parameters - **compaction_pri** (Member of `rocksdb.CompactionPri`) - Optional - Priority for selecting files for compaction. Defaults to `rocksdb.CompactionPri.kByCompensatedSize`. ``` ```APIDOC ## Universal Compaction Options ### Description Provides specific options for configuring universal-style compaction. ### Parameters #### Request Body - **compaction_options_universal** (dict) - Optional - A dictionary containing universal compaction options. - **size_ratio** (int) - Optional - Percentage flexibility when comparing file sizes. Defaults to 1. - **min_merge_width** (int) - Optional - Minimum number of files in a single compaction run. Defaults to 2. - **max_merge_width** (int) - Optional - Maximum number of files in a single compaction run. Defaults to UINT_MAX. - **max_size_amplification_percent** (int) - Optional - Percentage defining the allowed size amplification. Defaults to 200. - **compression_size_percent** (int) - Optional - Threshold for compressing output files based on their relative size. Defaults to -1 (all files follow the general compression type). ``` -------------------------------- ### Get RocksDB Live Files Metadata in Python Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Returns a list containing metadata for all live files in the RocksDB database. Each metadata entry is a dictionary with details such as file name, level, size, key range, and sequence numbers. ```python get_live_files_metadata() Returns a list of all table files. It returns a list of dict’s were each dict has the following keys. `name` Name of the file `level` Level at which this file resides `size` File size in bytes `smallestkey` Smallest user defined key in the file `largestkey` Largest user defined key in the file `smallest_seqno` smallest seqno in file `largest_seqno` largest seqno in file ``` -------------------------------- ### RocksDB Configuration Options Source: https://python-rocksdb.readthedocs.io/en/latest/api/options This section details various configuration options for RocksDB, including parameters related to data storage, compactions, logging, and performance. ```APIDOC ## RocksDB Configuration Options ### Description Provides details on various configuration parameters for RocksDB. ### max_bytes_for_level_multiplier **Type:** `int` **Default:** `10` **Description:** Controls the multiplier for `max_bytes_for_level_base` across different levels. ### max_bytes_for_level_multiplier_additional **Type:** `[int]` **Default:** `[1, 1, 1, 1, 1, 1, 1]` **Description:** Specifies different max-size multipliers for various levels, which are then multiplied by `max_bytes_for_level_multiplier`. ### max_compaction_bytes **Type:** `int` **Default:** `target_file_size_base * 25` **Description:** Sets a threshold to limit the number of bytes in a single compaction. A value of 0 will be sanitized. Note: This is not guaranteed. ### use_fsync **Type:** `bool` **Default:** `False` **Description:** If `True`, every store to stable storage issues an `fsync`. If `False`, `fdatasync` is used. Set to `True` for filesystems like ext3 that may lose files after a reboot. ### db_log_dir **Type:** `unicode` **Default:** `""` **Description:** Specifies the directory for info log files. If empty, logs are in the data directory. If non-empty, the database's absolute path is used as a prefix for log file names. ### wal_dir **Type:** `unicode` **Default:** `""` **Description:** Sets the absolute directory path for write-ahead logs (WAL). If empty, logs are in the data directory. When the DB is destroyed, all files in `wal_dir` and the directory itself are deleted. ### delete_obsolete_files_period_micros **Type:** `int` **Default:** `21600000000` (6 hours) **Description:** The interval at which obsolete files are deleted. Compaction processes automatically delete out-of-scope files regardless of this setting. ### max_background_compactions **Type:** `int` **Default:** `1` **Description:** Maximum number of concurrent background compaction jobs submitted to the default LOW priority thread pool. ### max_background_flushes **Type:** `int` **Default:** `1` **Description:** Maximum number of concurrent background memtable flush jobs submitted to the HIGH priority thread pool. Setting this to a positive number separates flush jobs from major compactions, preventing stalls when sharing the same `Env`. ### max_log_file_size **Type:** `int` **Default:** `0` **Description:** The maximum size of an info log file. If `0`, all logs are written to a single file. ### log_file_time_to_roll **Type:** `int` **Default:** `0` **Description:** The time (in seconds) after which an info log file will roll over. A value of `0` disables this feature. ### keep_log_file_num **Type:** `int` **Default:** `1000` **Description:** The maximum number of info log files to retain. ### soft_rate_limit **Type:** `float` **Default:** `0` **Description:** Delays Puts by 0-1 ms when any level's compaction score exceeds this limit. Ignored if `0.0`. Constraint: `soft_rate_limit <= hard_rate_limit`. ### hard_rate_limit **Type:** `float` **Default:** `0` **Description:** Delays Puts by 1 ms at a time when any level's compaction score exceeds this limit. Ignored if `<= 1.0`. A value of `0` means disabled. ### rate_limit_delay_max_milliseconds **Type:** `int` **Default:** `1000` **Description:** The maximum time a `Put` operation will be stalled when `hard_rate_limit` is enforced. If `0`, there is no limit. ### max_manifest_file_size **Type:** `int` **Default:** `(2**64) - 1` **Description:** The manifest file is rolled over upon reaching this limit, and the older manifest file is deleted. The default value prevents roll-over. ### table_cache_numshardbits **Type:** `int` **Default:** `4` **Description:** The number of shards used for the table cache. ### arena_block_size **Type:** `int` **Default:** `0` **Description:** The size of one block in arena memory allocation. If `<= 0`, a suitable value is automatically calculated (typically 1/10 of `writer_buffer_size`). ### disable_auto_compactions **Type:** `bool` **Default:** `False` **Description:** Disables automatic compactions. Manual compactions can still be performed. ### wal_ttl_seconds, wal_size_limit_mb **Description:** These two fields affect how archived logs are deleted. If both are set to `0`, logs are deleted as soon as possible and do not get archived. ``` -------------------------------- ### HashSkipListMemtableFactory Initialization Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Initializes a HashSkipListMemtableFactory which employs a fixed array of buckets, each pointing to a skiplist. Requires prefix_extractor to be set in RocksDB options. Parameters control bucket count, skiplist height, and branching factor. ```python class HashSkipListMemtableFactory: def __init__(self, bucket_count=1000000, skiplist_height=4, skiplist_branching_factor=4): # Initializes HashSkipListMemtableFactory with customizable bucket count, skiplist height, and branching factor. pass ``` -------------------------------- ### Get Value by Key from RocksDB Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Retrieves the value associated with a given key. Optional parameters include `verify_checksums`, `fill_cache`, `snapshot` for consistent reads, and `read_tier` to control data fetching location. Returns `None` if the key is not found. ```python value = db.get(key, verify_checksums=False, fill_cache=True, snapshot=None, read_tier='all') ``` -------------------------------- ### File Management and Compaction Sizing Options Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Parameters that influence the number of open files and the size of files generated during compaction. ```APIDOC ## `max_open_files` ### Description Number of open files that can be used by the DB. You may need to increase this if your database has a large working set. Value -1 means files opened are always kept open. You can estimate number of files based on `target_file_size_base` and `target_file_size_multiplier` for level-based compaction. For universal-style compaction, you can usually set it to -1. ### Type int ### Default `5000` ## `target_file_size_base` ### Description Target file size for compaction. `target_file_size_base` is per-file size for level-1. Target file size for level L can be calculated by `target_file_size_base` * (`target_file_size_multiplier` ^ (L-1)). For example, if `target_file_size_base` is 2MB and `target_file_size_multiplier` is 10, then each file on level-1 will be 2MB, and each file on level 2 will be 20MB, and each file on level-3 will be 200MB. ### Type int ### Default `2097152` ## `target_file_size_multiplier` ### Description By default `target_file_size_multiplier` is 1, which means by default files in different levels will have similar size. ### Type int ### Default `1` ## `max_bytes_for_level_base` ### Description Control maximum total data size for a level. `_max_bytes_for_level_base_` is the max total for level-1. Maximum number of bytes for level L can be calculated as (`_max_bytes_for_level_base_`) * (`_max_bytes_for_level_multiplier_` ^ (L-1)). For example, if `_max_bytes_for_level_base_` is 20MB, and if `_max_bytes_for_level_multiplier_` is 10, total data size for level-1 will be 20MB, total file size for level-2 will be 200MB, and total file size for level-3 will be 2GB. ### Type int ``` -------------------------------- ### Get RocksDB Properties in Python Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Retrieves properties exported by the RocksDB database implementation. It returns a byte string with the property's value if understood, otherwise `None`. Supported properties include file counts, statistics, and memtable status. ```python get_property(_prop_) DB implementations can export properties about their state via this method. If “property” is a valid property understood by this DB implementation, a byte string with its value is returned. Otherwise `None` ``` -------------------------------- ### HashSkipListMemtableFactory Source: https://python-rocksdb.readthedocs.io/en/latest/api/options A Memtable factory using a hash of skip lists. ```APIDOC ### HashSkipListMemtableFactory #### Description This factory creates memtables with a fixed array of buckets, where each bucket points to a skiplist. If `rocksdb.Options.prefix_extractor` is not set, it defaults to using a skip-list. #### Initialization `__init__(self, bucket_count=1000000, skiplist_height=4, skiplist_branching_factor=4)` * **Parameters**: * **bucket_count** (Integer) - The number of buckets in the fixed array. * **skiplist_height** (Integer) - The maximum height of the skiplists. * **skiplist_branching_factor** (Integer) - The probabilistic size ratio between adjacent link lists in the skiplist. ``` -------------------------------- ### Check Key Existence in RocksDB Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Checks if a key might exist in the database, potentially avoiding IO operations for a lighter-weight check than `get`. The `fetch` parameter allows retrieving the value if found and in memory. Returns a tuple indicating existence and the value (if fetched). ```python exists, value = db.key_may_exist(key, fetch=False, verify_checksums=False, fill_cache=True, snapshot=None, read_tier='all') ``` -------------------------------- ### SkipListMemtableFactory Initialization Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Initializes a SkipListMemtableFactory that utilizes a skip list for storing keys. This factory does not require any parameters for initialization. ```python class SkipListMemtableFactory: def __init__(self): # Initializes SkipListMemtableFactory. pass ``` -------------------------------- ### Initialize RocksDB Database Source: https://python-rocksdb.readthedocs.io/en/latest/api/database Constructs a new DB object to interact with a RocksDB database. It requires the database name and options, with an optional flag for read-only access. The options object configures database-specific behaviors. ```python db = rocksdb.DB(db_name, rocksdb.Options(), read_only=False) ``` -------------------------------- ### Python: Configure RocksDB Create If Missing Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Sets the 'create_if_missing' option for RocksDB. If True, the database will be created if it does not exist. This is a boolean setting. ```python opts = rocksdb.Options() opts.create_if_missing = True ``` -------------------------------- ### RocksDB PlainTableFactory Initialization Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Initializes the PlainTableFactory for RocksDB, which is optimized for low query latency on memory. It requires proper configuration of `rocksdb.Options.prefix_extractor` to function correctly, utilizing prefix hashing for lookups. ```python rocksdb.PlainTableFactory(user_key_len=0, bloom_bits_per_key=10, hash_table_ratio=0.75, index_sparseness=10, huge_page_tlb_size=0, encoding_type='plain', full_scan_mode=False, store_index_in_file=False) ``` -------------------------------- ### Compression and Leveling Options Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Options for data compression and the number of levels in the database. ```APIDOC ## `compression` ### Description Compress blocks using the specified compression algorithm. This parameter can be changed dynamically. ### Type Member of `rocksdb.CompressionType` ### Default `rocksdb.CompressionType.snappy_compression` ## `num_levels` ### Description Number of levels for this database ### Type int ### Default `7` ``` -------------------------------- ### Database Creation Options Source: https://python-rocksdb.readthedocs.io/en/latest/api/options These options control how the RocksDB database is created and managed. ```APIDOC ## `create_if_missing` ### Description If `True`, the database will be created if it is missing. ### Type bool ### Default `False` ## `error_if_exists` ### Description If `True`, an error is raised if the database already exists. ### Type bool ### Default `False` ``` -------------------------------- ### BytewiseComparator Source: https://python-rocksdb.readthedocs.io/en/latest/api/options Details of the BytewiseComparator. ```APIDOC ## BytewiseComparator ### `BytewiseComparator` Class #### Description Wraps the RocksDB Bytewise Comparator, which uses lexicographical byte-wise ordering for keys. ```