-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segment Replication - PIT/Scroll compatibility.
This change makes updates to make PIT/Scroll queries compatibile with Segment Replication. It does this by refcounting files when a new reader is created, and discarding those files after a reader is closed. Signed-off-by: Marc Handalian <handalm@amazon.com>
- Loading branch information
Showing
6 changed files
with
288 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/opensearch/index/store/ReplicaFileDeleter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* This class is a version of Lucene's ReplicaFileDeleter class used to keep track of | ||
* segment files that should be preserved on replicas between replication events. | ||
* The difference is this component does not actually perform any deletions, it only handles refcounts. | ||
* Our deletions are made through Store.java. | ||
* | ||
* https://github.com/apache/lucene/blob/main/lucene/replicator/src/java/org/apache/lucene/replicator/nrt/ReplicaFileDeleter.java | ||
* | ||
* @opensearch.internal | ||
*/ | ||
final class ReplicaFileDeleter { | ||
|
||
private final Map<String, Integer> refCounts = new HashMap<>(); | ||
|
||
public synchronized void incRef(Collection<String> fileNames) { | ||
for (String fileName : fileNames) { | ||
refCounts.merge(fileName, 1, Integer::sum); | ||
} | ||
} | ||
|
||
public synchronized void decRef(Collection<String> fileNames) { | ||
for (String fileName : fileNames) { | ||
Integer curCount = refCounts.get(fileName); | ||
assert curCount != null : "fileName=" + fileName; | ||
assert curCount > 0; | ||
if (curCount == 1) { | ||
refCounts.remove(fileName); | ||
} else { | ||
refCounts.put(fileName, curCount - 1); | ||
} | ||
} | ||
} | ||
|
||
public synchronized Integer getRefCount(String fileName) { | ||
return refCounts.get(fileName); | ||
} | ||
|
||
public synchronized boolean skipDelete(String fileName) { | ||
return refCounts.containsKey(fileName); | ||
} | ||
} |
Oops, something went wrong.