Skip to content

Commit

Permalink
OAK-8640: Allow to only copy last journal entry in the SegmentStoreMi…
Browse files Browse the repository at this point in the history
…grator

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1867372 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
trekawek committed Sep 23, 2019
1 parent fc76969 commit b7952f4
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class SegmentStoreMigrator implements Closeable {

private final boolean appendMode;

private final boolean onlyLastJournalEntry;

private ExecutorService executor = Executors.newFixedThreadPool(READ_THREADS + 1);

private SegmentStoreMigrator(Builder builder) {
Expand All @@ -78,6 +80,7 @@ private SegmentStoreMigrator(Builder builder) {
this.sourceName = builder.sourceName;
this.targetName = builder.targetName;
this.appendMode = builder.appendMode;
this.onlyLastJournalEntry = builder.onlyLastJournalEntry;
}

public void migrate() throws IOException, ExecutionException, InterruptedException {
Expand All @@ -94,13 +97,22 @@ private void migrateJournal() throws IOException {
return;
}
List<String> journal = new ArrayList<>();
try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
String line;
while ((line = reader.readLine()) != null) {
journal.add(line);
if (onlyLastJournalEntry) {
try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
String line = reader.readLine();
if (line != null) {
journal.add(line);
}
}
} else {
try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
String line;
while ((line = reader.readLine()) != null) {
journal.add(line);
}
}
Collections.reverse(journal);
}
Collections.reverse(journal);
try (JournalFileWriter writer = target.getJournalFile().openJournalWriter()) {
writer.truncate();
for (String line : journal) {
Expand Down Expand Up @@ -236,6 +248,8 @@ public static class Builder {

private boolean appendMode;

private boolean onlyLastJournalEntry;

public Builder withSource(File dir) {
this.source = new TarPersistence(dir);
this.sourceName = storeDescription(SegmentStoreType.TAR, dir.getPath());
Expand Down Expand Up @@ -277,6 +291,11 @@ public Builder setAppendMode() {
return this;
}

public Builder withOnlyLastJournalEntry() {
this.onlyLastJournalEntry = onlyLastJournalEntry;
return this;
}

public SegmentStoreMigrator build() {
return new SegmentStoreMigrator(this);
}
Expand Down

0 comments on commit b7952f4

Please sign in to comment.