private void truncatePrefixInBackground(final long startIndex, final long firstIndexKept) {
        // delete logs in background.
        ThreadPoolsFactory.runInThread(this.groupId, () -> {
            long startMs = Utils.monotonicMs();
            this.readLock.lock();
            try {
                RocksDB db = this.db;
                if (db == null) {
                    LOG.warn(
                        "DB is null while truncating prefixed logs in data path: {}, the range is: [{}, {})",
                        this.path, startIndex, firstIndexKept);
                    return;
                }
                onTruncatePrefix(startIndex, firstIndexKept);
                // Note https://github.com/facebook/rocksdb/wiki/Delete-A-Range-Of-Keys
                final byte[] startKey = getKeyBytes(startIndex);
                final byte[] endKey = getKeyBytes(firstIndexKept);
                // deleteRange to delete all keys in range.
                db.deleteRange(this.defaultHandle, startKey, endKey);
                db.deleteRange(this.confHandle, startKey, endKey);
                // deleteFilesInRanges to speedup reclaiming disk space on write-heavy load.
                db.deleteFilesInRanges(this.defaultHandle, Arrays.asList(startKey, endKey), false);
                db.deleteFilesInRanges(this.confHandle, Arrays.asList(startKey, endKey), false);
            } catch (final RocksDBException | IOException e) {
                LOG.error("Fail to truncatePrefix in data path: {}, firstIndexKept={}.", this.path, firstIndexKept, e);
            } finally {
                this.readLock.unlock();
                LOG.info("Truncated prefix logs in data path: {} from log index {} to {}, cost {} ms.",
                    this.path, startIndex, firstIndexKept, Utils.monotonicMs() - startMs);
            }
        });
    }
Execute write batch template.

@param template write batch template
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/impl/RocksDBLogStorage.java