Skip to content

Commit

Permalink
Remove Lucene Precommit from PersistentCache (#66324) (#66331)
Browse files Browse the repository at this point in the history
There is nothing gained from doing the precommit step explicitly here.
Also, we can just reuse the same map entries statically.
  • Loading branch information
original-brownbear authored Dec 15, 2020
1 parent 26caaa4 commit a460564
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -212,9 +214,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
void commit() throws IOException {
ensureOpen();
try {
for (CacheIndexWriter writer : writers) {
writer.prepareCommit();
}
for (CacheIndexWriter writer : writers) {
writer.commit();
}
Expand Down Expand Up @@ -457,16 +456,14 @@ void deleteCacheFile(String cacheFileId) throws IOException {
indexWriter.deleteDocuments(term);
}

void prepareCommit() throws IOException {
logger.debug("preparing commit");
final Map<String, String> commitData = new HashMap<>(1);
commitData.put(NODE_VERSION_COMMIT_KEY, Integer.toString(Version.CURRENT.id));
indexWriter.setLiveCommitData(commitData.entrySet());
indexWriter.prepareCommit();
}
private static final Set<Map.Entry<String, String>> LUCENE_COMMIT_DATA = Collections.singletonMap(
NODE_VERSION_COMMIT_KEY,
Integer.toString(Version.CURRENT.id)
).entrySet();

void commit() throws IOException {
logger.debug("committing");
indexWriter.setLiveCommitData(LUCENE_COMMIT_DATA);
indexWriter.commit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,8 @@ public void testCacheIndexWriter() throws Exception {

boolean commit = false;
if (frequently()) {
writer.prepareCommit();
if (frequently()) {
writer.commit();
commit = true;
}
writer.commit();
commit = true;
}

if (commit) {
Expand Down

0 comments on commit a460564

Please sign in to comment.