4848import java .util .Iterator ;
4949import java .util .List ;
5050import java .util .Map ;
51+ import java .util .Optional ;
5152import java .util .Set ;
5253import java .util .concurrent .CountDownLatch ;
5354import java .util .concurrent .Executor ;
@@ -160,7 +161,7 @@ public boolean isRemoteClusterServerEnabled() {
160161 private final Map <ProjectId , Map <String , RemoteClusterConnection >> remoteClusters ;
161162 private final RemoteClusterCredentialsManager remoteClusterCredentialsManager ;
162163 private final ProjectResolver projectResolver ;
163- private final boolean inSkippableContext ;
164+ private final boolean isCpsEnabled ;
164165
165166 @ FixForMultiProject (description = "Inject the ProjectResolver instance." )
166167 RemoteClusterService (Settings settings , TransportService transportService ) {
@@ -182,7 +183,7 @@ public boolean isRemoteClusterServerEnabled() {
182183 * TODO: This is not the right way to check if we're in CPS context and is more of a temporary measure since
183184 * the functionality to do it the right way is not yet ready -- replace this code when it's ready.
184185 */
185- this .inSkippableContext = settings .getAsBoolean ("serverless.cross_project.enabled" , false );
186+ this .isCpsEnabled = settings .getAsBoolean ("serverless.cross_project.enabled" , false );
186187 }
187188
188189 /**
@@ -293,22 +294,28 @@ void ensureConnected(String clusterAlias, ActionListener<Void> listener) {
293294 }
294295
295296 /**
296- * Returns whether the cluster identified by the provided alias is configured to be skipped when unavailable
297+ * Returns whether the cluster identified by the provided alias is configured to be skipped when unavailable.
298+ * @param clusterAlias Name of the cluster
299+ * @return A boolean optional that denotes if the cluster is configured to be skipped. In CPS-like environment,
300+ * it returns an empty value where we default/fall back to true.
297301 */
298- public boolean isSkipUnavailable (String clusterAlias ) {
299- return getRemoteClusterConnection (clusterAlias ).isSkipUnavailable ();
302+ public Optional <Boolean > isSkipUnavailable (String clusterAlias ) {
303+ if (isCpsEnabled ) {
304+ return Optional .empty ();
305+ } else {
306+ return Optional .of (getRemoteClusterConnection (clusterAlias ).isSkipUnavailable ());
307+ }
300308 }
301309
302310 /**
303- * Returns whether we're in a skippable context. Skippable context is true when either in CPS environment
304- * or skip_unavailable is set to true for the specified cluster .
311+ * Signifies if an error can be skipped for the specified cluster based on skip_unavailable, or,
312+ * allow_partial_search_results if in CPS-like environment .
305313 * @param clusterAlias Name of the cluster
306314 * @param allowPartialSearchResults If partial results can be served for the search request.
307315 * @return boolean
308316 */
309317 public boolean shouldSkipOnFailure (String clusterAlias , Boolean allowPartialSearchResults ) {
310- return (inSkippableContext && (allowPartialSearchResults != null && allowPartialSearchResults ))
311- || getRemoteClusterConnection (clusterAlias ).isSkipUnavailable ();
318+ return isSkipUnavailable (clusterAlias ).orElseGet (() -> allowPartialSearchResults != null && allowPartialSearchResults );
312319 }
313320
314321 public Transport .Connection getConnection (String cluster ) {
@@ -675,7 +682,9 @@ public RemoteClusterClient getRemoteClusterClient(
675682 return new RemoteClusterAwareClient (transportService , clusterAlias , responseExecutor , switch (disconnectedStrategy ) {
676683 case RECONNECT_IF_DISCONNECTED -> true ;
677684 case FAIL_IF_DISCONNECTED -> false ;
678- case RECONNECT_UNLESS_SKIP_UNAVAILABLE -> transportService .getRemoteClusterService ().isSkipUnavailable (clusterAlias ) == false ;
685+ case RECONNECT_UNLESS_SKIP_UNAVAILABLE -> transportService .getRemoteClusterService ()
686+ .isSkipUnavailable (clusterAlias )
687+ .orElse (true ) == false ;
679688 });
680689 }
681690
0 commit comments