Skip to content

Commit

Permalink
Merge pull request #285 from Zelldon/ck-filter-for-pos
Browse files Browse the repository at this point in the history
Filter log for position
  • Loading branch information
ChrisKujawa authored Aug 21, 2023
2 parents f30a059 + 419da41 commit 0869e70
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cli/src/main/java/io/zell/zdb/LogPrintCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.zell.zdb;

import io.zell.zdb.log.ApplicationRecord;
import io.zell.zdb.log.LogContentReader;
import java.nio.file.Path;
import java.util.concurrent.Callable;
Expand All @@ -40,6 +41,18 @@ public enum Format {
defaultValue = "JSON")
private Format format;

@Option(
names = {"--from", "--fromPosition"},
description = "Print's the complete log from the given position.",
defaultValue = "0")
private long fromPosition;

@Option(
names = {"--to", "--toPosition"},
description = "Print's the complete log to the given position.",
defaultValue = Long.MAX_VALUE + "")
private long toPosition;

@Override
public Integer call() {
final Path partitionPath = spec.findOption("-p").getValue();
Expand All @@ -50,8 +63,14 @@ public Integer call() {
System.out.println(logContent.asDotFile());
} else {
System.out.println("[");
for (LogContentReader it = logContentReader; it.hasNext(); ) {
final var record = it.next();
logContentReader.seekToPosition(fromPosition);
while (logContentReader.hasNext()) {
final var record = logContentReader.next();
if (record instanceof ApplicationRecord engineRecord) {
if (engineRecord.getLowestPosition() > toPosition) {
break;
}
}
System.out.println(record);
if (logContentReader.hasNext()) {
System.out.print(",");
Expand Down

0 comments on commit 0869e70

Please sign in to comment.