-
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.
Merge branch 'main' into updateNetflixGradle
Signed-off-by: Daniel (dB.) Doubrovkine <dblock@amazon.com>
- Loading branch information
Showing
7 changed files
with
94 additions
and
4 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 was deleted.
Oops, something went wrong.
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 @@ | ||
3681b1caf41af1da0c4a3ffec47ab4a3d907c190 |
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
88 changes: 88 additions & 0 deletions
88
server/src/test/java/org/opensearch/index/engine/NRTReplicationReaderManagerTests.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,88 @@ | ||
/* | ||
* 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.engine; | ||
|
||
import org.apache.lucene.index.DirectoryReader; | ||
import org.apache.lucene.index.SegmentInfos; | ||
import org.apache.lucene.index.StandardDirectoryReader; | ||
import org.apache.lucene.util.Version; | ||
import org.opensearch.common.lucene.index.OpenSearchDirectoryReader; | ||
import org.opensearch.index.store.Store; | ||
|
||
import java.io.IOException; | ||
|
||
public class NRTReplicationReaderManagerTests extends EngineTestCase { | ||
|
||
public void testCreateNRTreaderManager() throws IOException { | ||
try (final Store store = createStore()) { | ||
store.createEmpty(Version.LATEST); | ||
final DirectoryReader reader = DirectoryReader.open(store.directory()); | ||
final SegmentInfos initialInfos = ((StandardDirectoryReader) reader).getSegmentInfos(); | ||
NRTReplicationReaderManager readerManager = new NRTReplicationReaderManager( | ||
OpenSearchDirectoryReader.wrap(reader, shardId), | ||
(files) -> {}, | ||
(files) -> {} | ||
); | ||
assertEquals(initialInfos, readerManager.getSegmentInfos()); | ||
try (final OpenSearchDirectoryReader acquire = readerManager.acquire()) { | ||
assertNull(readerManager.refreshIfNeeded(acquire)); | ||
} | ||
|
||
// create an updated infos | ||
final SegmentInfos infos_2 = readerManager.getSegmentInfos().clone(); | ||
infos_2.changed(); | ||
|
||
readerManager.updateSegments(infos_2); | ||
assertEquals(infos_2, readerManager.getSegmentInfos()); | ||
try (final OpenSearchDirectoryReader acquire = readerManager.acquire()) { | ||
final StandardDirectoryReader standardReader = NRTReplicationReaderManager.unwrapStandardReader(acquire); | ||
assertEquals(infos_2, standardReader.getSegmentInfos()); | ||
} | ||
} | ||
} | ||
|
||
public void testUpdateSegmentsWhileRefreshing() throws IOException, InterruptedException { | ||
try (final Store store = createStore()) { | ||
store.createEmpty(Version.LATEST); | ||
final DirectoryReader reader = DirectoryReader.open(store.directory()); | ||
NRTReplicationReaderManager readerManager = new NRTReplicationReaderManager( | ||
OpenSearchDirectoryReader.wrap(reader, shardId), | ||
(files) -> {}, | ||
(files) -> {} | ||
); | ||
|
||
final SegmentInfos infos_2 = readerManager.getSegmentInfos().clone(); | ||
infos_2.changed(); | ||
|
||
Thread refreshThread = new Thread(() -> { | ||
try { | ||
readerManager.maybeRefresh(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
Thread updateThread = new Thread(() -> { | ||
try { | ||
readerManager.updateSegments(infos_2); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
refreshThread.start(); | ||
updateThread.start(); | ||
refreshThread.join(); | ||
updateThread.join(); | ||
try (final OpenSearchDirectoryReader acquire = readerManager.acquire()) { | ||
final StandardDirectoryReader standardReader = NRTReplicationReaderManager.unwrapStandardReader(acquire); | ||
assertEquals(infos_2.version, standardReader.getSegmentInfos().version); | ||
} | ||
assertEquals(infos_2, readerManager.getSegmentInfos()); | ||
} | ||
} | ||
} |