void flush() throws RocksDBException {

        // flush segments first, as this is consistent with the store always writing to
        // older segments/stores before later ones
        try (final WriteBatch segmentsBatch = new WriteBatch()) {
            final List<WriteBufferSegmentWithDbFallback> allSegments = restoreClient.getReverseSegments(Long.MIN_VALUE);
            if (allSegments.size() > 0) {
                // collect entries into write batch
                for (final WriteBufferSegmentWithDbFallback bufferSegment : allSegments) {
                    final LogicalKeyValueSegment dbSegment = bufferSegment.dbSegment();
                    for (final Map.Entry<Bytes, byte[]> segmentEntry : bufferSegment.getAll().entrySet()) {
                        dbSegment.addToBatch(
                            new KeyValue<>(segmentEntry.getKey().get(), segmentEntry.getValue()),
                            segmentsBatch);
                    }
                }

                // write to db. all the logical segments share the same physical store,
                // so we can use any segment to perform the write
                allSegments.get(0).dbSegment().write(segmentsBatch);
            }
        } catch (final RocksDBException e) {
            log.error("Error restoring batch to RocksDBVersionedStore segments store.");
            throw e;
        }
        segmentsWriteBuffer.clear();

        // flush latest value store
        try (final WriteBatch latestValueBatch = new WriteBatch()) {
            // collect entries into write batch
            for (final Map.Entry<Bytes, Optional<byte[]>> latestValueEntry : latestValueWriteBuffer.entrySet()) {
                final byte[] value = latestValueEntry.getValue().orElse(null);
                dbClient.addToLatestValueBatch(
                    new KeyValue<>(latestValueEntry.getKey().get(), value),
                    latestValueBatch);
            }

            // write to db
            dbClient.writeLatestValues(latestValueBatch);
        } catch (final RocksDBException e) {
            log.error("Error restoring batch to RocksDBVersionedStore latest value store.");
            throw e;
        }
        latestValueWriteBuffer.clear();
    }
Flushes the contents of the write buffer into the persistent store, and clears the write
buffer in the process.
@throws RocksDBException if a failure occurs adding to or writing a {@link WriteBatch}
streams/src/main/java/org/apache/kafka/streams/state/internals/RocksDBVersionedStoreRestoreWriteBuffer.java