From bdc071dee1d2bb76d2b7902fdb36e709462e0307 Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Mon, 11 Apr 2022 13:40:10 +0000 Subject: [PATCH] Adding comments and removing log statements Signed-off-by: Rishikesh1159 --- .../indices/replication/SegmentReplicationIT.java | 2 +- .../java/org/opensearch/index/engine/InternalEngine.java | 6 ++++-- .../opensearch/index/engine/OpenSearchReaderManager.java | 7 ------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java index f613c67524cab..b0a26b88f38e8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/replication/SegmentReplicationIT.java @@ -230,7 +230,7 @@ public void onFailure(Exception e) { }); } - public void testDelOps()throws Exception{ + public void testDeleteOperations()throws Exception{ final String nodeA = internalCluster().startNode(); final String nodeB = internalCluster().startNode(); diff --git a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java index fa32c81639e64..1ccd52f9652d8 100644 --- a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java @@ -702,11 +702,12 @@ private ExternalReaderManager createReaderManager(RefreshWarmerListener external } private DirectoryReader getDirectoryReader() throws IOException { - // for segment replication: replicas should create the reader from store, we don't want an open IW on replicas. + // for segment replication: replicas should create the reader from store and, we don't want an open IW on replicas. + // We should always wrap replicas with a SoftDeletesDirectoryReaderWrapper as we use soft deletes when segment replication is on for deletions if (engineConfig.isReadOnly()) { return new SoftDeletesDirectoryReaderWrapper(DirectoryReader.open(store.directory()), Lucene.SOFT_DELETES_FIELD); } - return DirectoryReader.open(indexWriter); + return DirectoryReader.open(indexWriter, true, true); } @Override @@ -2295,6 +2296,7 @@ public SegmentInfos getLatestSegmentInfos() { OpenSearchDirectoryReader reader = null; try { reader = externalReaderManager.internalReaderManager.acquire(); + // This is safe, as we always wrap Standard reader with a SoftDeletesDirectoryReaderWrapper for replicas when segment replication is enabled if (engineConfig.isReadOnly()) { return ((StandardDirectoryReader)((SoftDeletesDirectoryReaderWrapper) reader.getDelegate()).getDelegate()).getSegmentInfos(); } diff --git a/server/src/main/java/org/opensearch/index/engine/OpenSearchReaderManager.java b/server/src/main/java/org/opensearch/index/engine/OpenSearchReaderManager.java index 8e6ac4ec66486..91404ecf62de8 100644 --- a/server/src/main/java/org/opensearch/index/engine/OpenSearchReaderManager.java +++ b/server/src/main/java/org/opensearch/index/engine/OpenSearchReaderManager.java @@ -92,18 +92,11 @@ protected OpenSearchDirectoryReader refreshIfNeeded(OpenSearchDirectoryReader re // If not using NRT repl. if (currentInfos == null) { reader = (OpenSearchDirectoryReader) DirectoryReader.openIfChanged(referenceToRefresh); - if (reader != null) { - logger.info("Num docs primary {}", reader.getDelegate().numDocs()); - } } else { // Open a new reader, sharing any common segment readers with the old one: DirectoryReader innerReader = StandardDirectoryReader.open(referenceToRefresh.directory(), currentInfos, subs, null); final DirectoryReader softDeletesDirectoryReaderWrapper = new SoftDeletesDirectoryReaderWrapper(innerReader, Lucene.SOFT_DELETES_FIELD); - logger.info("Doc count {}", softDeletesDirectoryReaderWrapper.numDocs()); - logger.info("Deleted doc count {}", softDeletesDirectoryReaderWrapper.numDeletedDocs()); reader = OpenSearchDirectoryReader.wrap(softDeletesDirectoryReaderWrapper, referenceToRefresh.shardId()); - logger.info("reader Doc count {}", reader.numDocs()); - logger.info("reader Deleted doc count {}", reader.numDeletedDocs()); logger.trace("updated to SegmentInfosVersion=" + currentInfos.getVersion() + " reader=" + innerReader); } return reader;