Search in sources :

Example 1 with SnapshotKey

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;
}
Also used : ScanningSnapshotReader(io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) URIBuilder(org.apache.http.client.utils.URIBuilder) Mav(io.datarouter.web.handler.mav.Mav) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) ReflectionTool(io.datarouter.util.lang.ReflectionTool) TagCreator.a(j2html.TagCreator.a) DatarouterSnapshotWebExecutor(io.datarouter.filesystem.snapshot.web.DatarouterSnapshotExecutors.DatarouterSnapshotWebExecutor) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) Inject(javax.inject.Inject) DomContent(j2html.tags.DomContent) List(java.util.List) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) ScanningSnapshotReader(io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader) SnapshotGroups(io.datarouter.filesystem.snapshot.group.SnapshotGroups) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Param(io.datarouter.web.handler.types.Param) TagCreator.div(j2html.TagCreator.div) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 2 with SnapshotKey

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;
}
Also used : IntStream(java.util.stream.IntStream) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) Twin(io.datarouter.util.tuple.Twin) Mav(io.datarouter.web.handler.mav.Mav) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) ReflectionTool(io.datarouter.util.lang.ReflectionTool) ArrayList(java.util.ArrayList) ContainerTag(j2html.tags.ContainerTag) Inject(javax.inject.Inject) List(java.util.List) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) SnapshotGroups(io.datarouter.filesystem.snapshot.group.SnapshotGroups) BaseHandler(io.datarouter.web.handler.BaseHandler) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Param(io.datarouter.web.handler.types.Param) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) SnapshotIdReader(io.datarouter.filesystem.snapshot.reader.SnapshotIdReader) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) ArrayList(java.util.ArrayList) SnapshotRecord(io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord) SnapshotIdReader(io.datarouter.filesystem.snapshot.reader.SnapshotIdReader) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) Twin(io.datarouter.util.tuple.Twin)

Example 3 with SnapshotKey

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();
}
Also used : RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 4 with SnapshotKey

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));
    });
}
Also used : Scanner(io.datarouter.scanner.Scanner) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey) BranchBlock(io.datarouter.filesystem.snapshot.block.branch.BranchBlock) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) RootBlock(io.datarouter.filesystem.snapshot.block.root.RootBlock) SnapshotKey(io.datarouter.filesystem.snapshot.key.SnapshotKey) Function(java.util.function.Function) LeafBlock(io.datarouter.filesystem.snapshot.block.leaf.LeafBlock) ExecutorService(java.util.concurrent.ExecutorService) BranchBlock(io.datarouter.filesystem.snapshot.block.branch.BranchBlock) BlockKey(io.datarouter.filesystem.snapshot.block.BlockKey)

Example 5 with SnapshotKey

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);
    }
}
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

SnapshotKey (io.datarouter.filesystem.snapshot.key.SnapshotKey)12 SnapshotGroup (io.datarouter.filesystem.snapshot.group.SnapshotGroup)10 List (java.util.List)9 Scanner (io.datarouter.scanner.Scanner)8 ExecutorService (java.util.concurrent.ExecutorService)8 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 SnapshotWriteResult (io.datarouter.filesystem.snapshot.group.dto.SnapshotWriteResult)5 ScanningSnapshotReader (io.datarouter.filesystem.snapshot.reader.ScanningSnapshotReader)5 SnapshotWriterConfig (io.datarouter.filesystem.snapshot.writer.SnapshotWriterConfig)5 SnapshotLeafRecord (io.datarouter.filesystem.snapshot.reader.record.SnapshotLeafRecord)4 BaseHandler (io.datarouter.web.handler.BaseHandler)4 Arrays (java.util.Arrays)4 Set (java.util.Set)4 BlockKey (io.datarouter.filesystem.snapshot.block.BlockKey)3 SnapshotEntry (io.datarouter.filesystem.snapshot.entry.SnapshotEntry)3 SnapshotIdReader (io.datarouter.filesystem.snapshot.reader.SnapshotIdReader)3 SnapshotRecord (io.datarouter.filesystem.snapshot.reader.record.SnapshotRecord)3 ParallelScannerContext (io.datarouter.scanner.ParallelScannerContext)3 Directory (io.datarouter.storage.file.Directory)3