Skip to content

Commit

Permalink
Merge branch 'main' into pr/2417
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed May 3, 2024
2 parents 42e01cb + cae69c7 commit cd73a1b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.apache.solr.common.params.CommonAdminParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.Utils;
Expand All @@ -94,6 +95,8 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final CollectionCommandContext ccc;

public static final String PRS_DEFAULT_PROP = "solr.prs.default";

public CreateCollectionCmd(CollectionCommandContext ccc) {
this.ccc = ccc;
}
Expand All @@ -109,7 +112,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList<Objec
final boolean waitForFinalState = message.getBool(WAIT_FOR_FINAL_STATE, false);
final String alias = message.getStr(ALIAS, collectionName);
log.info("Create collection {}", collectionName);
boolean prsDefault = Boolean.parseBoolean(System.getProperty("solr.prs.default", "false"));
boolean prsDefault = EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, false);
final boolean isPRS = message.getBool(CollectionStateProps.PER_REPLICA_STATE, prsDefault);
if (log.isInfoEnabled()) {
log.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package org.apache.solr.cloud;

import static org.apache.solr.cloud.SolrCloudTestCase.setPrsDefault;
import static org.apache.solr.cloud.SolrCloudTestCase.unsetPrsDefault;
import static org.apache.solr.cloud.SolrCloudTestCase.configurePrsDefault;

import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -40,8 +39,7 @@
import org.apache.solr.embedded.JettySolrRunner;
import org.apache.solr.handler.BackupStatusChecker;
import org.apache.solr.handler.ReplicationHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
Expand Down Expand Up @@ -71,14 +69,9 @@ protected boolean useTlogReplicas() {
// and it's TestInjection use
}

@After
public void _unsetPrsDefault() {
unsetPrsDefault();
}

@Before
public void _setPrsDefault() {
setPrsDefault();
@BeforeClass
public static void _setPrsDefault() {
configurePrsDefault();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.solr.cloud;

import static org.apache.solr.cloud.api.collections.CreateCollectionCmd.PRS_DEFAULT_PROP;

import com.carrotsearch.randomizedtesting.RandomizedTest;
import java.io.IOException;
import java.lang.annotation.ElementType;
Expand Down Expand Up @@ -51,12 +53,11 @@
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.EnvUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.embedded.JettySolrRunner;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -83,8 +84,6 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public static final String PRS_DEFAULT_PROP = System.getProperty("use.per-replica", null);

// this is an important timeout for test stability - can't be too short
public static final int DEFAULT_TIMEOUT = 45;

Expand All @@ -97,11 +96,12 @@ protected static SolrZkClient zkClient() {
return cluster.getZkStateReader().getZkClient();
}

/** if the system property is not specified, use a random value */
/**
* if the system property is not specified, default to false. The SystemProperty will be set in a
* beforeClass method.
*/
public static boolean isPRS() {
return PRS_DEFAULT_PROP == null
? random().nextBoolean()
: Boolean.parseBoolean(PRS_DEFAULT_PROP);
return EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, false);
}

/**
Expand All @@ -116,7 +116,9 @@ protected static MiniSolrCloudCluster.Builder configureCluster(int nodeCount) {
// By default the MiniSolrCloudCluster being built will randomly (seed based) decide which
// collection API strategy to use (distributed or Overseer based) and which cluster update
// strategy to use (distributed if collection API is distributed, but Overseer based or
// distributed randomly chosen if Collection API is Overseer based)
// distributed randomly chosen if Collection API is Overseer based), and whether to use PRS

configurePrsDefault();

boolean useDistributedCollectionConfigSetExecution = LuceneTestCase.random().nextInt(2) == 0;
boolean useDistributedClusterStateUpdate =
Expand All @@ -126,6 +128,17 @@ protected static MiniSolrCloudCluster.Builder configureCluster(int nodeCount) {
useDistributedCollectionConfigSetExecution, useDistributedClusterStateUpdate);
}

public static void configurePrsDefault() {
Class<?> target = RandomizedTest.getContext().getTargetClass();
boolean usePrs;
if (target != null && target.isAnnotationPresent(NoPrs.class)) {
usePrs = false;
} else {
usePrs = EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, LuceneTestCase.random().nextBoolean());
}
System.setProperty(PRS_DEFAULT_PROP, usePrs ? "true" : "false");
}

@AfterClass
public static void shutdownCluster() throws Exception {
if (cluster != null) {
Expand All @@ -137,34 +150,6 @@ public static void shutdownCluster() throws Exception {
}
}

@BeforeClass
public static void setPrsDefault() {
Class<?> target = RandomizedTest.getContext().getTargetClass();
if (target != null && target.isAnnotationPresent(NoPrs.class)) return;
if (isPRS()) {
System.setProperty("solr.prs.default", "true");
}
}

@After
public void _unsetPrsDefault() {
unsetPrsDefault();
}

@Before
public void _setPrsDefault() {
setPrsDefault();
}

@AfterClass
public static void unsetPrsDefault() {
Class<?> target = RandomizedTest.getContext().getTargetClass();
if (target != null && target.isAnnotationPresent(NoPrs.class)) return;
if (isPRS()) {
System.clearProperty("solr.prs.default");
}
}

@Before
public void checkClusterConfiguration() {}

Expand Down

0 comments on commit cd73a1b

Please sign in to comment.