use of io.datarouter.filesystem.snapshot.key.SnapshotKey in project datarouter by hotpads.
the class DatarouterSnapshotEntriesHandler method buildTable.
private DomContent buildTable(SnapshotKey snapshotKey, long offset, long limit) {
SnapshotGroup group = groups.getGroup(snapshotKey.groupId);
var reader = new ScanningSnapshotReader(snapshotKey, exec, 2, groups, 1);
SnapshotRecordStringDecoder decoder = ReflectionTool.create(group.getSnapshotEntryDecoderClass());
List<SnapshotRecordStrings> rows = reader.scan(0).skip(offset).limit(limit).map(decoder::decode).list();
var table = new J2HtmlTable<SnapshotRecordStrings>().withClasses("sortable table table-sm table-striped my-4 border").withColumn("id", row -> row.id).withColumn(decoder.keyName(), row -> row.key).withColumn(decoder.valueName(), row -> {
if (row.value == null) {
return "";
} else if (row.value.length() < 64) {
return row.value;
} else {
return row.value.subSequence(0, 64) + "...";
}
}).withHtmlColumn("details", row -> {
String href = new URIBuilder().setPath(request.getContextPath() + snapshotPaths.datarouter.snapshot.individual.entry.toSlashedString()).addParameter(DatarouterSnapshotEntryHandler.P_groupId, snapshotKey.groupId).addParameter(DatarouterSnapshotEntryHandler.P_snapshotId, snapshotKey.snapshotId).addParameter(DatarouterSnapshotEntryHandler.P_id, Long.toString(row.id)).toString();
return td(a("view").withHref(href));
}).build(rows);
return table;
}
use of io.datarouter.filesystem.snapshot.key.SnapshotKey in project datarouter by hotpads.
the class DatarouterSnapshotEntryHandler method buildTable.
private ContainerTag<?> buildTable(SnapshotKey snapshotKey, long id) {
SnapshotGroup group = groups.getGroup(snapshotKey.groupId);
var reader = new SnapshotIdReader(snapshotKey, groups);
SnapshotRecord record = reader.getRecord(id);
SnapshotRecordStringDecoder decoder = ReflectionTool.create(group.getSnapshotEntryDecoderClass());
SnapshotRecordStrings decoded = decoder.decode(record);
List<Twin<String>> rows = new ArrayList<>();
rows.add(new Twin<>("id", Long.toString(record.id)));
rows.add(new Twin<>(decoder.keyName(), decoded.key));
rows.add(new Twin<>(decoder.valueName(), decoded.value));
IntStream.range(0, decoded.columnValues.size()).mapToObj(column -> new Twin<>(decoder.columnValueName(column), decoded.columnValues.get(column))).forEach(rows::add);
var table = new J2HtmlTable<Twin<String>>().withClasses("sortable table table-sm table-striped my-4 border").withColumn("field", twin -> twin.getLeft()).withColumn("value", twin -> twin.getRight()).build(rows);
return table;
}
use of io.datarouter.filesystem.snapshot.key.SnapshotKey in project datarouter by hotpads.
the class DatarouterSnapshotHandler method summary.
@Handler
public Mav summary(@Param(P_groupId) String groupId, @Param(P_snapshotId) String snapshotId) {
var snapshotKey = new SnapshotKey(groupId, snapshotId);
RootBlock rootBlock = groups.getGroup(groupId).root(BlockKey.root(snapshotKey));
return pageFactory.startBuilder(request).withTitle("Datarouter Filesystem - Snapshot Groups").withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(buildSummary(rootBlock)).buildMav();
}
use of io.datarouter.filesystem.snapshot.key.SnapshotKey in project datarouter by hotpads.
the class ScanningBlockReader method scanLeafBlockKeys.
private Scanner<BlockKey> scanLeafBlockKeys(long fromRecordIdInclusive) {
BlockKey topBranchBlockKey = rootBlock.rootBranchBlockKey(snapshotKey);
BranchBlock topBranchBlock = blockLoader.branch(topBranchBlockKey);
return scanDescendantBranchBlocks(topBranchBlock, fromRecordIdInclusive).include(branchBlock -> branchBlock.level() == 0).concat(branchBlock -> {
return Scanner.iterate(0, i -> i + 1).limit(branchBlock.numRecords()).include(index -> branchBlock.recordId(index) >= fromRecordIdInclusive).map(branchBlock::childBlock).map(leafBlockId -> branchBlock.leafBlockKey(snapshotKey, leafBlockId));
});
}
use of io.datarouter.filesystem.snapshot.key.SnapshotKey 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);
}
}
Aggregations