Skip to content

Commit

Permalink
SOLR-16475 Make the default replica placement plugin configurable (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
janhoy authored Jan 6, 2023
1 parent 061e301 commit 15dac22
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 9 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Improvements
* SOLR-15478: A v2 equivalent of CLUSTERSTATUS command is now available at `GET /api/cluster`. Collection listing,
previously at this path, can still be accessed at `GET /api/collections`. (Joshua Ouma via Jason Gerlowski)

* SOLR-16475: Make the default replica placement plugin configurable as system property on startup (janhoy)

* SOLR-13626: Document the SystemInfoHandler in the Ref Guide. (Tony Cook via Eric Pugh)

* SOLR-15479: A v2 equivalent of the RENAME command is now available at `POST /api/collections/collName/rename`. (Anakhe Ajayi via Jason Gerlowski)
Expand Down
5 changes: 5 additions & 0 deletions solr/bin/solr
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,11 @@ if [[ -n "${SOLR_MODULES:-}" ]] ; then
SOLR_OPTS+=("-Dsolr.modules=$SOLR_MODULES")
fi

# Default placement plugin
if [[ -n "${SOLR_PLACEMENTPLUGIN_DEFAULT:-}" ]] ; then
SOLR_OPTS+=("-Dsolr.placementplugin.default=$SOLR_PLACEMENTPLUGIN_DEFAULT")
fi

: ${SOLR_SERVER_DIR:=$DEFAULT_SERVER_DIR}

if [ ! -e "$SOLR_SERVER_DIR" ]; then
Expand Down
5 changes: 5 additions & 0 deletions solr/bin/solr.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ IF DEFINED SOLR_MODULES (
set "SOLR_OPTS=%SOLR_OPTS% -Dsolr.modules=%SOLR_MODULES%"
)

REM Default placement plugin
IF DEFINED SOLR_PLACEMENTPLUGIN_DEFAULT (
set "SOLR_OPTS=%SOLR_OPTS% -Dsolr.placementplugin.default=%SOLR_PLACEMENTPLUGIN_DEFAULT%"
)

IF "%SOLR_SERVER_DIR%"=="" set "SOLR_SERVER_DIR=%DEFAULT_SERVER_DIR%"

IF NOT EXIST "%SOLR_SERVER_DIR%" (
Expand Down
6 changes: 5 additions & 1 deletion solr/bin/solr.in.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,8 @@ REM then enable the following setting to address CVE-2021-44228
REM set SOLR_OPTS=%SOLR_OPTS% -Dlog4j2.formatMsgNoLookups=true

REM The bundled plugins in the "modules" folder can easily be enabled as a comma-separated list in SOLR_MODULES variable
REM set SOLR_MODULES=extraction,ltr
REM set SOLR_MODULES=extraction,ltr

REM Configure the default replica placement plugin to use if one is not configured in cluster properties
REM See https://solr.apache.org/guide/solr/latest/configuration-guide/replica-placement-plugins.html for details
REM set SOLR_PLACEMENTPLUGIN_DEFAULT=simple
4 changes: 4 additions & 0 deletions solr/bin/solr.in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,7 @@

# The bundled plugins in the "modules" folder can easily be enabled as a comma-separated list in SOLR_MODULES variable
# SOLR_MODULES=extraction,ltr

# Configure the default replica placement plugin to use if one is not configured in cluster properties
# See https://solr.apache.org/guide/solr/latest/configuration-guide/replica-placement-plugins.html for details
#SOLR_PLACEMENTPLUGIN_DEFAULT=simple
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
import org.apache.solr.client.solrj.cloud.VersionedData;
import org.apache.solr.cluster.placement.PlacementPlugin;
import org.apache.solr.cluster.placement.impl.PlacementPluginAssignStrategy;
import org.apache.solr.cluster.placement.plugins.AffinityPlacementFactory;
import org.apache.solr.cluster.placement.plugins.MinimizeCoresPlacementFactory;
import org.apache.solr.cluster.placement.plugins.RandomPlacementFactory;
import org.apache.solr.cluster.placement.plugins.SimplePlacementFactory;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.ClusterState;
Expand All @@ -63,6 +66,7 @@
public class Assign {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final String SYSTEM_COLL_PREFIX = ".sys.";
public static final String PLACEMENTPLUGIN_DEFAULT_SYSPROP = "solr.placementplugin.default";

public static String getCounterNodePath(String collection) {
return ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection + "/counter";
Expand Down Expand Up @@ -562,8 +566,37 @@ public static AssignStrategy createAssignStrategy(CoreContainer coreContainer) {
coreContainer.getPlacementPluginFactory().createPluginInstance();
if (placementPlugin == null) {
// Otherwise use the default
// TODO: Replace this with a better options, such as the AffinityPlacementFactory
placementPlugin = (new SimplePlacementFactory()).createPluginInstance();
String defaultPluginId = System.getProperty(PLACEMENTPLUGIN_DEFAULT_SYSPROP);
if (defaultPluginId != null) {
switch (defaultPluginId.toLowerCase(Locale.ROOT)) {
case "simple":
placementPlugin = (new SimplePlacementFactory()).createPluginInstance();
break;
case "affinity":
placementPlugin = (new AffinityPlacementFactory()).createPluginInstance();
break;
case "minimizecores":
placementPlugin = (new MinimizeCoresPlacementFactory()).createPluginInstance();
break;
case "random":
placementPlugin = (new RandomPlacementFactory()).createPluginInstance();
break;
default:
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
"Invalid value for system property '"
+ PLACEMENTPLUGIN_DEFAULT_SYSPROP
+ "'. Supported values are 'simple', 'random', 'affinity' and 'minimizecores'");
}
log.info(
"Default replica placement plugin set in {} to {}",
PLACEMENTPLUGIN_DEFAULT_SYSPROP,
defaultPluginId);
} else {
// TODO: Consider making the ootb default AffinityPlacementFactory, see
// https://issues.apache.org/jira/browse/SOLR-16492
placementPlugin = (new SimplePlacementFactory()).createPluginInstance();
}
}
return new PlacementPluginAssignStrategy(placementPlugin);
}
Expand Down
7 changes: 3 additions & 4 deletions solr/packaging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ assemble.dependsOn installDist

task downloadBats(type: NpmTask) {
group = 'Build Dependency Download'
args = ["install", "[email protected]",
"ztombol/bats-support#v0.2.0",
"ztombol/bats-assert#v0.3.0",
"ztombol/bats-file#v0.2.0",
args = ["install", "https://github.com/bats-core/bats-core#v1.8.2",
"https://github.com/bats-core/bats-assert#v2.0.0",
"https://github.com/bats-core/bats-file#v0.3.0",
]

inputs.files("${project.ext.nodeProjectDir}/package.json")
Expand Down
2 changes: 1 addition & 1 deletion solr/packaging/test/bats_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# The SOLR_HOME directory will be cleared when the next test file is executed.
# - "setup" should use "common_setup" if a Solr process is NOT being started in that same "setup" function.
common_setup() {
bats_require_minimum_version 1.8.0
bats_require_minimum_version 1.8.2

if [ -z ${BATS_LIB_PREFIX:-} ]; then
# Debugging help, if you want to run bats directly, try to detect where libraries might be
Expand Down
47 changes: 47 additions & 0 deletions solr/packaging/test/test_placement_plugin.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bats

# 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.

load bats_helper

setup() {
common_clean_setup
}

teardown() {
# save a snapshot of SOLR_HOME for failed tests
save_home_on_failure

delete_all_collections
solr stop -all >/dev/null 2>&1
}

@test "Affinity placement plugin using sysprop" {
run solr start -c -Dsolr.placementplugin.default=affinity
solr assert -c http://localhost:8983/solr -t 3000
run solr create_collection -c COLL_NAME
collection_exists COLL_NAME
assert_file_contains ${SOLR_LOGS_DIR}/solr.log 'Default replica placement plugin set in solr\.placementplugin\.default to affinity'
}

@test "Affinity placement plugin using ENV" {
export SOLR_PLACEMENTPLUGIN_DEFAULT=random
run solr start -c
solr assert -c http://localhost:8983/solr -t 3000
run solr create_collection -c COLL_NAME
collection_exists COLL_NAME
assert_file_contains ${SOLR_LOGS_DIR}/solr.log 'Default replica placement plugin set in solr\.placementplugin\.default to random'
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ The configuration entry may also contain a `config` element if the plugin implem

== Placement Plugins Included with Solr
The following placement plugins are available out-of-the-box in Solr 9.0.
If no placement plugin is defined, Solr will default to using the <<#simpleplacementfactory,SimplePlacementPlugin>>.
If no placement plugin is defined in cluster properties, Solr will default to using
the plugin configured in system property `solr.placementplugin.default` or environment
variable `SOLR_PLACEMENTPLUGIN_DEFAULT`. Supported values are `simple`, `random`, `affinity`
and `minimizecores`. If no such property or environment variable is set,
the <<#simpleplacementfactory,SimplePlacementPlugin>> is used.

In order to use a plugin its configuration must be added using the `/cluster/plugin` API.
For example, in order to use the `AffinityPlacementFactory` plugin the following command should be executed:
Expand Down

0 comments on commit 15dac22

Please sign in to comment.