From 61d0b63208b5a8a85ca0c61d2cfaad469125e23f Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Thu, 22 Jan 2026 12:56:22 -0800 Subject: [PATCH 1/7] Still need to fix loading a new indexWriter --- .../unreleased/solr-18083-fix-read-only-behavior.yml | 9 +++++++++ .../src/java/org/apache/solr/cloud/RecoveryStrategy.java | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/solr-18083-fix-read-only-behavior.yml diff --git a/changelog/unreleased/solr-18083-fix-read-only-behavior.yml b/changelog/unreleased/solr-18083-fix-read-only-behavior.yml new file mode 100644 index 000000000000..5606d08b7ac3 --- /dev/null +++ b/changelog/unreleased/solr-18083-fix-read-only-behavior.yml @@ -0,0 +1,9 @@ +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc +title: Fix normal operation errors for readOnly collections +type: other # added, changed, fixed, deprecated, removed, dependency_update, security, other +authors: + - name: Houston Putman + nick: HoustonPutman +links: + - name: SOLR-18083 + url: https://issues.apache.org/jira/browse/SOLR-18083 diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java index 0b8c2a744dab..5a774e2f6a9a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java @@ -231,8 +231,9 @@ private void replicate(String nodeName, SolrCore core, ZkNodeProps leaderprops) log.info("Attempting to replicate from core [{}] on node [{}].", leaderCore, leaderBaseUrl); - // send commit if replica could be a leader - if (replicaType.leaderEligible) { + // send commit if replica could be a leader. + // if the collection is in readOnly mode, all replicas are already commited, so do not send a commit (which will fail because the collection cannot be written to) + if (replicaType.leaderEligible && !zkController.getClusterState().getCollection(coreDescriptor.getCollectionName()).isReadOnly()) { commitOnLeader(leaderBaseUrl, leaderCore); } From 3f6cdf8e159cb83a4456ba5b9f0212412af103f3 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Fri, 23 Jan 2026 17:07:16 -0800 Subject: [PATCH 2/7] Make read only check better --- .../src/java/org/apache/solr/cloud/RecoveryStrategy.java | 7 ++++--- .../java/org/apache/solr/handler/RequestHandlerUtils.java | 1 + .../java/org/apache/solr/update/CommitUpdateCommand.java | 5 ++++- .../update/processor/DistributedZkUpdateProcessor.java | 7 ++++++- .../java/org/apache/solr/common/params/UpdateParams.java | 3 +++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java index 5a774e2f6a9a..9f7cb74e1fb5 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java @@ -231,9 +231,8 @@ private void replicate(String nodeName, SolrCore core, ZkNodeProps leaderprops) log.info("Attempting to replicate from core [{}] on node [{}].", leaderCore, leaderBaseUrl); - // send commit if replica could be a leader. - // if the collection is in readOnly mode, all replicas are already commited, so do not send a commit (which will fail because the collection cannot be written to) - if (replicaType.leaderEligible && !zkController.getClusterState().getCollection(coreDescriptor.getCollectionName()).isReadOnly()) { + // send commit if replica could be a leader + if (replicaType.leaderEligible) { commitOnLeader(leaderBaseUrl, leaderCore); } @@ -304,6 +303,8 @@ private void commitOnLeader(String leaderBaseUrl, String coreName) // ureq.getParams().set(UpdateParams.OPEN_SEARCHER, onlyLeaderIndexes); // Why do we need to open searcher if "onlyLeaderIndexes"? ureq.getParams().set(UpdateParams.OPEN_SEARCHER, false); + // If the leader is readOnly, do not fail since the core is already committed. + ureq.getParams().set(UpdateParams.FAIL_ON_READ_ONLY, false); ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true).process(client); } } diff --git a/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java b/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java index 7b5d791ae423..7a04edad33ed 100644 --- a/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java +++ b/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java @@ -99,6 +99,7 @@ public static void updateCommit(CommitUpdateCommand cmd, SolrParams params) { cmd.maxOptimizeSegments = params.getInt(UpdateParams.MAX_OPTIMIZE_SEGMENTS, cmd.maxOptimizeSegments); cmd.prepareCommit = params.getBool(UpdateParams.PREPARE_COMMIT, cmd.prepareCommit); + cmd.failOnReadOnly = params.getBool(UpdateParams.FAIL_ON_READ_ONLY, cmd.failOnReadOnly); } /** diff --git a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java index 6a749af2ac91..470740583eee 100644 --- a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java +++ b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java @@ -39,6 +39,7 @@ public class CommitUpdateCommand extends UpdateCommand { public boolean expungeDeletes = false; public boolean softCommit = false; public boolean prepareCommit = false; + public boolean failOnReadOnly = true; // fail the commit if the core or collection is readOnly /** * User provided commit data. Can be let to null if there is none. It is possible to commit this @@ -97,7 +98,9 @@ public String toString() { .append(",softCommit=") .append(softCommit) .append(",prepareCommit=") - .append(prepareCommit); + .append(prepareCommit) + .append(",failOnReadOnly=") + .append(failOnReadOnly); if (commitData != null) { sb.append(",commitData=").append(commitData); } diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java index 34532421bf56..160405f8d02f 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java @@ -161,7 +161,12 @@ public void processCommit(CommitUpdateCommand cmd) throws IOException { assert TestInjection.injectFailUpdateRequests(); if (isReadOnly()) { - throw new SolrException(ErrorCode.FORBIDDEN, "Collection " + collection + " is read-only."); + if (cmd.failOnReadOnly) { + throw new SolrException(ErrorCode.FORBIDDEN, "Collection " + collection + " is read-only."); + } else { + // Committing on a readOnly core/collection is a no-op, since the core was committed when becoming read-only and hasn't had any updates since. + return; + } } List nodes = null; diff --git a/solr/solrj/src/java/org/apache/solr/common/params/UpdateParams.java b/solr/solrj/src/java/org/apache/solr/common/params/UpdateParams.java index f14252fb9708..df6b11f1f3a3 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/UpdateParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/UpdateParams.java @@ -46,6 +46,9 @@ public interface UpdateParams { /** expert: calls IndexWriter.prepareCommit */ public static String PREPARE_COMMIT = "prepareCommit"; + /** Fail a commit when the core or collection is in read-only mode */ + public static String FAIL_ON_READ_ONLY = "failOnReadOnly"; + /** Rollback update commands */ public static String ROLLBACK = "rollback"; From 5cffa98b1df59e708aac287dbbe05bb7812ad5f7 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Mon, 26 Jan 2026 18:04:37 -0800 Subject: [PATCH 3/7] Let some parts of solr fetch an index writer for a read-only core --- .../src/java/org/apache/solr/core/SolrCore.java | 2 +- .../java/org/apache/solr/handler/IndexFetcher.java | 4 ++-- .../apache/solr/handler/ReplicationHandler.java | 2 +- .../apache/solr/update/DefaultSolrCoreState.java | 5 +++-- .../java/org/apache/solr/update/SolrCoreState.java | 14 +++++++++++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 24c7dc83b0c9..5e246e69ff15 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -2476,7 +2476,7 @@ public RefCounted openNewSearcher( true, directoryFactory); } else { - RefCounted writer = getSolrCoreState().getIndexWriter(this); + RefCounted writer = getSolrCoreState().getIndexWriter(this, true); DirectoryReader newReader = null; try { newReader = indexReaderFactory.newReader(writer.get(), this); diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 704806028075..9987d93722c1 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -530,7 +530,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel // we just clear ours and commit log.info("New index in Leader. Deleting mine..."); RefCounted iw = - solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(solrCore); + solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(solrCore, true); try { iw.get().deleteAll(); } finally { @@ -624,7 +624,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel // are successfully deleted solrCore.getUpdateHandler().newIndexWriter(true); RefCounted writer = - solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null); + solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null, true); try { IndexWriter indexWriter = writer.get(); int c = 0; diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java index cdc5de9313bb..7f50064ffe1d 100644 --- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java @@ -1378,7 +1378,7 @@ public void inform(SolrCore core) { // ensure the writer is initialized so that we have a list of commit points RefCounted iw = - core.getUpdateHandler().getSolrCoreState().getIndexWriter(core); + core.getUpdateHandler().getSolrCoreState().getIndexWriter(core, true); iw.decref(); } catch (IOException e) { diff --git a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java index 767c1ad0b77c..4feb43abd9d1 100644 --- a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java +++ b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java @@ -106,8 +106,9 @@ private void closeIndexWriter(IndexWriterCloser closer) { } @Override - public RefCounted getIndexWriter(SolrCore core) throws IOException { - if (core != null && (!core.indexEnabled || core.readOnly)) { + public RefCounted getIndexWriter(SolrCore core, boolean readOnlyCompatible) + throws IOException { + if (core != null && (!core.indexEnabled || (!readOnlyCompatible && core.readOnly))) { throw new SolrException( SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Indexing is temporarily disabled"); } diff --git a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java index 4d6f02d229fb..5016f9fdbb6f 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java +++ b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java @@ -178,7 +178,19 @@ public void deregisterInFlightUpdate() { * * @throws IOException If there is a low-level I/O error. */ - public abstract RefCounted getIndexWriter(SolrCore core) throws IOException; + public RefCounted getIndexWriter(SolrCore core) throws IOException { + return getIndexWriter(core, false); + } + + /** + * Get the current IndexWriter. If a new IndexWriter must be created, use the settings from the + * given {@link SolrCore}. Be very careful using the {@code readOnlyCompatible} flag, by default + * it should be false if the returned indexWriter will be used for writing. + * + * @throws IOException If there is a low-level I/O error. + */ + public abstract RefCounted getIndexWriter(SolrCore core, boolean readOnlyCompatible) + throws IOException; /** * Rollback the current IndexWriter. When creating the new IndexWriter use the settings from the From 42fa1da3f471aac6cecab925aa997118eda87688 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Mon, 26 Jan 2026 18:09:52 -0800 Subject: [PATCH 4/7] tidy and fix a small bug --- solr/core/src/java/org/apache/solr/handler/IndexFetcher.java | 2 +- .../solr/update/processor/DistributedZkUpdateProcessor.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 9987d93722c1..7e44992da161 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -537,7 +537,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel iw.decref(); } assert TestInjection.injectDelayBeforeFollowerCommitRefresh(); - if (skipCommitOnLeaderVersionZero) { + if (skipCommitOnLeaderVersionZero || solrCore.readOnly) { openNewSearcherAndUpdateCommitPoint(); } else { SolrQueryRequest req = new LocalSolrQueryRequest(solrCore, new ModifiableSolrParams()); diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java index 160405f8d02f..1bb785ad8b2e 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java @@ -164,7 +164,8 @@ public void processCommit(CommitUpdateCommand cmd) throws IOException { if (cmd.failOnReadOnly) { throw new SolrException(ErrorCode.FORBIDDEN, "Collection " + collection + " is read-only."); } else { - // Committing on a readOnly core/collection is a no-op, since the core was committed when becoming read-only and hasn't had any updates since. + // Committing on a readOnly core/collection is a no-op, since the core was committed when + // becoming read-only and hasn't had any updates since. return; } } From b1cba8bec6da8c0b4748fecc526018052e48ca33 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Tue, 27 Jan 2026 15:23:02 -0800 Subject: [PATCH 5/7] Make some waits conditional on not being readOnly These waits are letting updates get processed, which is not an issue for read only collections/cores. --- .../apache/solr/cloud/RecoveryStrategy.java | 20 ++++++++++--------- .../cloud/ShardLeaderElectionContext.java | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java index 9f7cb74e1fb5..bf023d3cb090 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java @@ -659,15 +659,17 @@ public final void doSyncOrReplicateRecovery(SolrCore core) throws Exception { break; } - // we wait a bit so that any updates on the leader - // that started before they saw recovering state - // are sure to have finished (see SOLR-7141 for - // discussion around current value) - // TODO since SOLR-11216, we probably won't need this - try { - Thread.sleep(waitForUpdatesWithStaleStatePauseMilliSeconds); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + if (!core.readOnly) { + // we wait a bit so that any updates on the leader + // that started before they saw recovering state + // are sure to have finished (see SOLR-7141 for + // discussion around current value) + // TODO since SOLR-11216, we probably won't need this + try { + Thread.sleep(waitForUpdatesWithStaleStatePauseMilliSeconds); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } // first thing we just try to sync diff --git a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java index 16a29f89a586..96401345503b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java +++ b/solr/core/src/java/org/apache/solr/cloud/ShardLeaderElectionContext.java @@ -195,7 +195,7 @@ void runLeaderProcess(boolean weAreReplacement) throws KeeperException, Interrup // first cancel any current recovery core.getUpdateHandler().getSolrCoreState().cancelRecovery(); - if (weAreReplacement) { + if (weAreReplacement && !core.readOnly) { // wait a moment for any floating updates to finish try { Thread.sleep(2500); From e6d11400004c589758d117d6d1367dbe7e4ecacf Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Wed, 28 Jan 2026 13:53:32 -0800 Subject: [PATCH 6/7] Address some review comments --- changelog/unreleased/solr-18083-fix-read-only-behavior.yml | 4 ++-- .../java/org/apache/solr/update/CommitUpdateCommand.java | 7 ++++--- .../solr/update/processor/DistributedUpdateProcessor.java | 2 +- .../update/processor/DistributedZkUpdateProcessor.java | 2 ++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/changelog/unreleased/solr-18083-fix-read-only-behavior.yml b/changelog/unreleased/solr-18083-fix-read-only-behavior.yml index 5606d08b7ac3..2aae02026c58 100644 --- a/changelog/unreleased/solr-18083-fix-read-only-behavior.yml +++ b/changelog/unreleased/solr-18083-fix-read-only-behavior.yml @@ -1,6 +1,6 @@ # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc -title: Fix normal operation errors for readOnly collections -type: other # added, changed, fixed, deprecated, removed, dependency_update, security, other +title: Fix operational issues with readOnly collections, such as restarting SolrNodes and replicating from the leader. +type: fixed # added, changed, fixed, deprecated, removed, dependency_update, security, other authors: - name: Houston Putman nick: HoustonPutman diff --git a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java index 470740583eee..2e4d0be5fb2a 100644 --- a/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java +++ b/solr/core/src/java/org/apache/solr/update/CommitUpdateCommand.java @@ -98,9 +98,10 @@ public String toString() { .append(",softCommit=") .append(softCommit) .append(",prepareCommit=") - .append(prepareCommit) - .append(",failOnReadOnly=") - .append(failOnReadOnly); + .append(prepareCommit); + if (!failOnReadOnly) { + sb.append(",failOnReadOnly=").append(failOnReadOnly); + } if (commitData != null) { sb.append(",commitData=").append(commitData); } diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java index 82424a5f06a4..fe6f44501e71 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java @@ -127,7 +127,7 @@ public static DistribPhase parseParam(final String param) { protected final SolrQueryResponse rsp; private final AtomicUpdateDocumentMerger docMerger; - private final UpdateLog ulog; + protected final UpdateLog ulog; private final VersionInfo vinfo; private final boolean versionsStored; private boolean returnVersions; diff --git a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java index 1bb785ad8b2e..12c2695a29d2 100644 --- a/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java +++ b/solr/core/src/java/org/apache/solr/update/processor/DistributedZkUpdateProcessor.java @@ -166,6 +166,8 @@ public void processCommit(CommitUpdateCommand cmd) throws IOException { } else { // Committing on a readOnly core/collection is a no-op, since the core was committed when // becoming read-only and hasn't had any updates since. + assert ulog == null || !ulog.hasUncommittedChanges() + : "Uncommitted changes found when trying to commit on a read-only collection"; return; } } From 977be7bdd396eabb776c5b2b0f6c1943c18aa4ea Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Wed, 28 Jan 2026 13:58:10 -0800 Subject: [PATCH 7/7] Change flag to failOnReadOnly --- solr/core/src/java/org/apache/solr/core/SolrCore.java | 2 +- .../src/java/org/apache/solr/handler/IndexFetcher.java | 4 ++-- .../java/org/apache/solr/handler/ReplicationHandler.java | 2 +- .../java/org/apache/solr/update/DefaultSolrCoreState.java | 4 ++-- .../src/java/org/apache/solr/update/SolrCoreState.java | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 5e246e69ff15..4e73bd530f36 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -2476,7 +2476,7 @@ public RefCounted openNewSearcher( true, directoryFactory); } else { - RefCounted writer = getSolrCoreState().getIndexWriter(this, true); + RefCounted writer = getSolrCoreState().getIndexWriter(this, false); DirectoryReader newReader = null; try { newReader = indexReaderFactory.newReader(writer.get(), this); diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 7e44992da161..c9878048dbbc 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -530,7 +530,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel // we just clear ours and commit log.info("New index in Leader. Deleting mine..."); RefCounted iw = - solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(solrCore, true); + solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(solrCore, false); try { iw.get().deleteAll(); } finally { @@ -624,7 +624,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel // are successfully deleted solrCore.getUpdateHandler().newIndexWriter(true); RefCounted writer = - solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null, true); + solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null, false); try { IndexWriter indexWriter = writer.get(); int c = 0; diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java index 7f50064ffe1d..e803bdd1d6b8 100644 --- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java @@ -1378,7 +1378,7 @@ public void inform(SolrCore core) { // ensure the writer is initialized so that we have a list of commit points RefCounted iw = - core.getUpdateHandler().getSolrCoreState().getIndexWriter(core, true); + core.getUpdateHandler().getSolrCoreState().getIndexWriter(core, false); iw.decref(); } catch (IOException e) { diff --git a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java index 4feb43abd9d1..e7c9474f5084 100644 --- a/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java +++ b/solr/core/src/java/org/apache/solr/update/DefaultSolrCoreState.java @@ -106,9 +106,9 @@ private void closeIndexWriter(IndexWriterCloser closer) { } @Override - public RefCounted getIndexWriter(SolrCore core, boolean readOnlyCompatible) + public RefCounted getIndexWriter(SolrCore core, boolean failOnReadOnly) throws IOException { - if (core != null && (!core.indexEnabled || (!readOnlyCompatible && core.readOnly))) { + if (core != null && (!core.indexEnabled || (core.readOnly && failOnReadOnly))) { throw new SolrException( SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Indexing is temporarily disabled"); } diff --git a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java index 5016f9fdbb6f..23adf63bd979 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrCoreState.java +++ b/solr/core/src/java/org/apache/solr/update/SolrCoreState.java @@ -179,17 +179,17 @@ public void deregisterInFlightUpdate() { * @throws IOException If there is a low-level I/O error. */ public RefCounted getIndexWriter(SolrCore core) throws IOException { - return getIndexWriter(core, false); + return getIndexWriter(core, true); } /** * Get the current IndexWriter. If a new IndexWriter must be created, use the settings from the - * given {@link SolrCore}. Be very careful using the {@code readOnlyCompatible} flag, by default - * it should be false if the returned indexWriter will be used for writing. + * given {@link SolrCore}. Be very careful using the {@code failOnReadOnly=false} flag, by default + * it should be true if the returned indexWriter will be used for writing. * * @throws IOException If there is a low-level I/O error. */ - public abstract RefCounted getIndexWriter(SolrCore core, boolean readOnlyCompatible) + public abstract RefCounted getIndexWriter(SolrCore core, boolean failOnReadOnly) throws IOException; /**