You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "mlbiscoc (via GitHub)" <gi...@apache.org> on 2023/05/02 20:30:41 UTC

[GitHub] [solr] mlbiscoc commented on a diff in pull request #1620: SOLR-16470: Create V2 equivalent of V1 Replication: Get IndexVersion

mlbiscoc commented on code in PR #1620:
URL: https://github.com/apache/solr/pull/1620#discussion_r1183021546


##########
solr/core/src/java/org/apache/solr/handler/replication/ReplicationAPIBase.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.replication;
+
+import java.io.IOException;
+import org.apache.solr.api.JerseyResource;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.handler.ReplicationHandler;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+
+/** A common parent for "replication" (i.e. replication-level) APIs. */
+public abstract class ReplicationAPIBase extends JerseyResource {
+
+  protected final CoreContainer coreContainer;
+  protected final SolrQueryRequest solrQueryRequest;
+  protected final SolrQueryResponse solrQueryResponse;
+
+  public ReplicationAPIBase(
+      CoreContainer coreContainer,
+      SolrQueryRequest solrQueryRequest,
+      SolrQueryResponse solrQueryResponse) {
+    this.coreContainer = coreContainer;
+    this.solrQueryRequest = solrQueryRequest;
+    this.solrQueryResponse = solrQueryResponse;
+  }
+
+  protected CoreReplicationAPI.GetIndexResponse fetchIndexVersion(String coreName)
+      throws IOException {
+
+    if (coreContainer.getCore(coreName) == null) {
+      throw new SolrException(
+          SolrException.ErrorCode.BAD_REQUEST, "Solr core " + coreName + " does not exist");
+    }
+
+    ReplicationHandler replicationHandler =
+        (ReplicationHandler)
+            coreContainer.getCore(coreName).getRequestHandler(ReplicationHandler.PATH);

Review Comment:
   @gerlowskija This is my first attempt and progress at creating a new V2 api for indexversion and would love your feedback. One of the issues I ran into was this replicationHandler being called in the V2 endpoint. 
   
   It wasn't entirely obvious to me on how to move the replicationHandler logic into the v2 API as there were a few fields that were needed inside the replicationHandler in order to retrieve the indexversion because of race conditions. So I retrieved the handler from the core but I'm not sure if this is the best solution.
   
   Was hoping I could get some guidance on this?



##########
solr/core/src/java/org/apache/solr/handler/replication/ReplicationAPIBase.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.handler.replication;
+
+import java.io.IOException;
+import org.apache.solr.api.JerseyResource;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.handler.ReplicationHandler;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+
+/** A common parent for "replication" (i.e. replication-level) APIs. */
+public abstract class ReplicationAPIBase extends JerseyResource {
+
+  protected final CoreContainer coreContainer;
+  protected final SolrQueryRequest solrQueryRequest;
+  protected final SolrQueryResponse solrQueryResponse;
+
+  public ReplicationAPIBase(
+      CoreContainer coreContainer,
+      SolrQueryRequest solrQueryRequest,
+      SolrQueryResponse solrQueryResponse) {
+    this.coreContainer = coreContainer;
+    this.solrQueryRequest = solrQueryRequest;
+    this.solrQueryResponse = solrQueryResponse;
+  }
+
+  protected CoreReplicationAPI.GetIndexResponse fetchIndexVersion(String coreName)
+      throws IOException {
+
+    if (coreContainer.getCore(coreName) == null) {
+      throw new SolrException(
+          SolrException.ErrorCode.BAD_REQUEST, "Solr core " + coreName + " does not exist");
+    }
+
+    ReplicationHandler replicationHandler =
+        (ReplicationHandler)
+            coreContainer.getCore(coreName).getRequestHandler(ReplicationHandler.PATH);

Review Comment:
   @gerlowskija This is my first attempt and current progress at creating a new V2 api for indexversion and would love your feedback. One of the issues I ran into was this replicationHandler being called in the V2 endpoint. 
   
   It wasn't entirely obvious to me on how to move the replicationHandler logic into the v2 API as there were a few fields that were needed inside the replicationHandler in order to retrieve the indexversion because of race conditions. So I retrieved the handler from the core but I'm not sure if this is the best solution.
   
   Was hoping I could get some guidance on this?



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org