-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Creating and Ingesting SST files
RocksDB provide the user with APIs that can be used to create SST files that can be ingested later. This can be useful if you have a use case that need to load the data quickly, but the process of creating the data can be done offline.
rocksdb::SstFileWriter can be used to create SST file. After creating a SstFileWriter object you can open a file, insert rows into it and finish.
This is an example of how to create SST file in /home/usr/file1.sst
Options options;
const ImmutableCFOptions ioptions(options);
SstFileWriter sst_file_writer(EnvOptions(), ioptions, options.comparator);
// Path to where we will write the SST file
std::string file_path = "/home/usr/file1.sst";
// Open the file for writing
Status s = sst_file_writer.Open(file1);
if (!s.ok()) {
printf("Error while opening file %s, Error: %s\n", file_path.c_str(), s.ToString());
return 1;
}
// Insert rows into the SST file, note that inserted keys must be
// strictly increasing (based on options.comparator)
for (...) {
s = sst_file_writer.Add(key, value);
if (!s.ok()) {
printf("Error while adding Key: %s, Error: %s\n", key.c_str(), s.ToString());
return 1;
}
}
// Close the file
s = sst_file_writer.Finish();
if (!s.ok()) {
printf("Error while finishing file %s, Error: %s\n", file_path.c_str(), s.ToString());
return 1;
}
return 0;
Now we have our SST file located at /home/usr/file1.sst
.
Please note that:
- ImmutableCFOptions passed to SstFileWriter will be used to figure out the table type, compression options, etc that will be used to create the SST file.
- The Comparator that is passed to the SstFileWriter must be exactly the same as the Comparator used in the DB that this file will be ingested into.
- Rows must be inserted in a strictly increasing order.
You can learn more about the SstFileWriter by checking include/rocksdb/sst_file_writer.h
Ingesting an SST file is simple, all you need to do is to call DB::AddFile() and pass the file path
std::string file_path = "/home/usr/file1.sst";
Status s = db_->AddFile(file_path);
assert(s.ok());
Please notice there are some restrictions on the SST files that you can ingest into a DB:
- SST file must have been created using SstFileWriter.
- The Comparator used to create the SST file must match the Comparator used by the DB.
- Key range in the SST file dont overlap with existing keys or deleted keys in the DB.
- No snapshots are being held while ingesting the file.
You can learn more by checking DB::AddFile() in include/rocksdb/db.h
Do you have a use case that can benefit from using DB::AddFile() but the current restrictions are too tight ? Please let us know about your use case and what restrictions are blocking you.
Contents
- RocksDB Wiki
- Overview
- RocksDB FAQ
- Terminology
- Requirements
- Contributors' Guide
- Release Methodology
- RocksDB Users and Use Cases
- RocksDB Public Communication and Information Channels
-
Basic Operations
- Iterator
- Prefix seek
- SeekForPrev
- Tailing Iterator
- Compaction Filter
- Multi Column Family Iterator (Experimental)
- Read-Modify-Write (Merge) Operator
- Column Families
- Creating and Ingesting SST files
- Single Delete
- Low Priority Write
- Time to Live (TTL) Support
- Transactions
- Snapshot
- DeleteRange
- Atomic flush
- Read-only and Secondary instances
- Approximate Size
- User-defined Timestamp
- Wide Columns
- BlobDB
- Online Verification
- Options
- MemTable
- Journal
- Cache
- Write Buffer Manager
- Compaction
- SST File Formats
- IO
- Compression
- Full File Checksum and Checksum Handoff
- Background Error Handling
- Huge Page TLB Support
- Tiered Storage (Experimental)
- Logging and Monitoring
- Known Issues
- Troubleshooting Guide
- Tests
- Tools / Utilities
-
Implementation Details
- Delete Stale Files
- Partitioned Index/Filters
- WritePrepared-Transactions
- WriteUnprepared-Transactions
- How we keep track of live SST files
- How we index SST
- Merge Operator Implementation
- RocksDB Repairer
- Write Batch With Index
- Two Phase Commit
- Iterator's Implementation
- Simulation Cache
- [To Be Deprecated] Persistent Read Cache
- DeleteRange Implementation
- unordered_write
- Extending RocksDB
- RocksJava
- Lua
- Performance
- Projects Being Developed
- Misc