rahulgoswami commented on code in PR #3903:
URL: https://github.com/apache/solr/pull/3903#discussion_r2702149552
##########
solr/core/src/java/org/apache/solr/handler/admin/api/UpgradeCoreIndex.java:
##########
@@ -129,107 +125,107 @@ public UpgradeCoreIndexResponse upgradeCoreIndex(
coreName,
requestBody.async,
"upgrade-index",
- () -> {
- try (SolrCore core = coreContainer.getCore(coreName)) {
-
- // Set LatestVersionMergePolicy to prevent older segments from
- // participating in merges while we reindex. This is to prevent
any older version
- // segments from
- // merging with any newly formed segments created due to
reindexing and undoing the work
- // we are doing.
- RefCounted<IndexWriter> iwRef = null;
- MergePolicy originalMergePolicy = null;
- int numSegmentsEligibleForUpgrade = 0, numSegmentsUpgraded = 0;
- try {
- iwRef = core.getSolrCoreState().getIndexWriter(core);
-
- IndexWriter iw = iwRef.get();
-
- originalMergePolicy = iw.getConfig().getMergePolicy();
- iw.getConfig()
- .setMergePolicy(new
LatestVersionMergePolicy(iw.getConfig().getMergePolicy()));
-
- RefCounted<SolrIndexSearcher> ssearcherRef = core.getSearcher();
- try {
- List<LeafReaderContext> leafContexts =
- ssearcherRef.get().getTopReaderContext().leaves();
- DocValuesIteratorCache dvICache = new
DocValuesIteratorCache(ssearcherRef.get());
-
- UpdateRequestProcessorChain updateProcessorChain =
- getUpdateProcessorChain(core, requestBody.updateChain);
-
- for (LeafReaderContext lrc : leafContexts) {
- if (shouldUpgradeSegment(lrc)) {
- numSegmentsEligibleForUpgrade++;
- }
- }
- if (numSegmentsEligibleForUpgrade == 0) {
- response.core = coreName;
- response.upgradeStatus =
CoreIndexUpgradeStatus.NO_UPGRADE_NEEDED.toString();
- response.numSegmentsEligibleForUpgrade = 0;
- return response;
- }
-
- for (LeafReaderContext lrc : leafContexts) {
- if (!shouldUpgradeSegment(lrc)) {
- continue;
- }
- processSegment(lrc, updateProcessorChain, core,
ssearcherRef.get(), dvICache);
- numSegmentsUpgraded++;
- }
- } catch (Exception e) {
- log.error("Error while processing core: [{}}]", coreName, e);
- throw new CoreAdminAPIBaseException(e);
- } finally {
- // important to decrement searcher ref count after use since
we obtained it via the
- // SolrCore.getSearcher() method
- ssearcherRef.decref();
- }
-
- try {
- doCommit(core);
- } catch (IOException e) {
- throw new CoreAdminAPIBaseException(e);
- }
-
- boolean indexUpgraded = isIndexUpgraded(core);
-
- if (!indexUpgraded) {
- log.error(
- "Validation failed for core '{}'. Some data is still
present in the older (<{}.x) Lucene index format.",
- coreName,
- Version.LATEST.major);
- throw new CoreAdminAPIBaseException(
- new SolrException(
- SolrException.ErrorCode.SERVER_ERROR,
- "Validation failed for core '"
- + coreName
- + "'. Some data is still present in the older (<"
- + Version.LATEST.major
- + ".x) Lucene index format."));
- }
-
- response.core = coreName;
- response.upgradeStatus =
CoreIndexUpgradeStatus.UPGRADE_SUCCESSFUL.toString();
- response.numSegmentsEligibleForUpgrade =
numSegmentsEligibleForUpgrade;
- response.numSegmentsUpgraded = numSegmentsUpgraded;
- } catch (Exception ioEx) {
- throw new CoreAdminAPIBaseException(ioEx);
-
- } finally {
- // Restore original merge policy
- if (iwRef != null) {
- IndexWriter iw = iwRef.get();
- if (originalMergePolicy != null) {
- iw.getConfig().setMergePolicy(originalMergePolicy);
- }
- iwRef.decref();
- }
+ () -> performUpgrade(coreName, requestBody, response));
+ }
+
+ private UpgradeCoreIndexResponse performUpgrade(
+ String coreName, UpgradeCoreIndexRequestBody requestBody,
UpgradeCoreIndexResponse response) {
+
+ try (SolrCore core = coreContainer.getCore(coreName)) {
+
+ // Set LatestVersionMergePolicy to prevent older segments from
+ // participating in merges while we reindex. This is to prevent any
older version
+ // segments from
+ // merging with any newly formed segments created due to reindexing and
undoing the work
+ // we are doing.
+ RefCounted<IndexWriter> iwRef = null;
+ MergePolicy originalMergePolicy = null;
+ int numSegmentsEligibleForUpgrade = 0, numSegmentsUpgraded = 0;
+ try {
+ iwRef = core.getSolrCoreState().getIndexWriter(core);
+ IndexWriter iw = iwRef.get();
+
+ originalMergePolicy = iw.getConfig().getMergePolicy();
+ iw.getConfig()
+ .setMergePolicy(
+ new LatestVersionMergePolicy(
+ iw.getConfig().getMergePolicy())); // prevent older
segments from merging
+
+ RefCounted<SolrIndexSearcher> searcherRef = core.getSearcher();
+ try {
+ List<LeafReaderContext> leafContexts =
searcherRef.get().getRawReader().leaves();
Review Comment:
I took a hint from your earlier comment :)
>think the code here could learn some things from long lived code in
SolrIndexSplitter. It uses searcher.getRawReader().leaves() to bypass
ExitableDirectoryReader and uninverting.
But I see your point. UninvertingReader would give the ability to even
retain indexed-only fields (stored=false, docValues=false). I like it! Might
add that support later. Leaving the door open by switching to
searcher.getIndexReader() instead. thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]