Search in sources :

Example 1 with SnapshotKeyAndNumRecords

use of io.datarouter.filesystem.snapshot.group.dto.SnapshotKeyAndNumRecords in project datarouter by hotpads.

the class SnapshotMerger method merge.

public void merge() {
    Map<SnapshotKey, SnapshotKeyAndNumRecords> summaryByKey = mergeGroup.keyReadOps(false).scanSnapshotKeysAndRootBlocks(readExec, 10).map(SnapshotKeyAndNumRecords::new).toMap(summary -> summary.key);
    while (summaryByKey.size() > 1) {
        SnapshotGroup outputGroup = summaryByKey.size() <= mergeFactor ? destinationGroup : mergeGroup;
        Scanner.of(summaryByKey.values()).minN(SnapshotKeyAndNumRecords.BY_NUM_RECORDS, mergeFactor).map(summary -> summary.key).flush(keys -> {
            SnapshotWriteResult result = combineSnapshots(keys, outputGroup);
            var newSummary = new SnapshotKeyAndNumRecords(result.toSnapshotKeyAndRoot());
            summaryByKey.put(result.key, newSummary);
        }).forEach(summaryByKey::remove);
    }
}
Also used : Scanner(io.datarouter.scanner.Scanner) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) Supplier(java.util.function.Supplier) SnapshotKeyAndNumRecords(io.datarouter.filesystem.snapshot.group.dto.SnapshotKeyAndNumRecords) SnapshotWriterConfig(io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig) List(java.util.List) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult) ScanningSnapshotReader(io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader) SnapshotLeafRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotLeafRecord) Map(java.util.Map) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) ExecutorService(java.util.concurrent.ExecutorService) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) SnapshotWriteResult(io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult) SnapshotKeyAndNumRecords(io.datarouter.filesystem.snapshot.group.dto.SnapshotKeyAndNumRecords) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup)

Aggregations

SnapshotGroup (io.datarouter.filesystem.snapshot.group.SnapshotGroup)1 SnapshotKeyAndNumRecords (io.datarouter.filesystem.snapshot.group.dto.SnapshotKeyAndNumRecords)1 SnapshotWriteResult (io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)1 SnapshotKey (io.datarouter.filesystem.snapshot.key.SnapshotKey)1 ScanningSnapshotReader (io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader)1 SnapshotLeafRecord (io.datarouter.filesystem.snapshot.reader.record.SnapshotLeafRecord)1 SnapshotWriterConfig (io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig)1 Scanner (io.datarouter.scanner.Scanner)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Supplier (java.util.function.Supplier)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1