title: Bulkloading by ingesting external SST files layout: post author: IslamAbdelRahman
One of the basic operations of RocksDB is writing to RocksDB, Writes happen when user call (DB::Put, DB::Write, DB::Delete ... ), but what happens when you write to RocksDB ? .. this is a brief description of what happens.
But what if we can skip these steps and add data to the lowest possible level directly ? This is what bulk-loading does
This is bulk-loading, and in specific use-cases it allow users to achieve faster data loading and better write-amplification.
and doing it is as simple as
Options options;
SstFileWriter sst_file_writer(EnvOptions(), options, options.comparator);
Status s = sst_file_writer.Open(file_path);
assert(s.ok());
// 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);
assert(s.ok());
}
// Ingest the external SST file into the DB
s = db_->IngestExternalFile({"/home/usr/file1.sst"}, IngestExternalFileOptions());
assert(s.ok());
You can find more details about how to generate SST files and ingesting them into RocksDB in this wiki page
There are multiple use cases where bulkloading could be useful, for example