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@1867459 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
trekawek committed Sep 24, 2019
1 parent d3d3647 commit 47ca39b
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlobDirectory;

import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.oak.commons.Buffer;
import org.apache.jackrabbit.oak.segment.azure.AzurePersistence;
import org.apache.jackrabbit.oak.segment.azure.tool.ToolUtils.SegmentStoreType;
Expand Down Expand Up @@ -97,22 +98,20 @@ private void migrateJournal() throws IOException {
return;
}
List<String> journal = new ArrayList<>();
if (onlyLastJournalEntry) {
try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
String line = reader.readLine();
if (line != null) {

try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
String line;
while ((line = reader.readLine()) != null) {
if (StringUtils.isNotBlank(line)) {
journal.add(line);
}
}
} else {
try (JournalFileReader reader = source.getJournalFile().openJournalReader()) {
String line;
while ((line = reader.readLine()) != null) {
journal.add(line);
if (!journal.isEmpty() && onlyLastJournalEntry) {
break;
}
}
Collections.reverse(journal);
}
Collections.reverse(journal);

try (JournalFileWriter writer = target.getJournalFile().openJournalWriter()) {
writer.truncate();
for (String line : journal) {
Expand Down Expand Up @@ -292,7 +291,7 @@ public Builder setAppendMode() {
}

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

Expand Down

0 comments on commit 47ca39b

Please sign in to comment.