mirror of https://github.com/apache/lucene.git
SOLR-12665: Autoscaling policy not being refreshed due to caching
This commit is contained in:
parent
f3339d14c9
commit
a059c944c1
|
@ -235,6 +235,8 @@ Bug Fixes
|
|||
|
||||
* SOLR-12470: Search Rate Trigger multiple bug fixes, improvements and documentation updates. (ab)
|
||||
|
||||
* SOLR-12665: Autoscaling policy not being refreshed due to caching (noble)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -84,6 +84,20 @@ public class TestPolicyCloud extends SolrCloudTestCase {
|
|||
"{}".getBytes(StandardCharsets.UTF_8), true);
|
||||
}
|
||||
|
||||
public void testCreateCollection() throws Exception {
|
||||
String commands = "{ set-cluster-policy: [ {cores: '0', node: '#ANY'} ] }"; // disallow replica placement anywhere
|
||||
cluster.getSolrClient().request(createAutoScalingRequest(SolrRequest.METHOD.POST, commands));
|
||||
String collectionName = "testCreateCollection";
|
||||
expectThrows(HttpSolrClient.RemoteSolrException.class,
|
||||
() -> CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient()));
|
||||
|
||||
CollectionAdminRequest.deleteCollection(collectionName).processAndWait(cluster.getSolrClient(), 60);
|
||||
|
||||
commands = "{ set-cluster-policy: [ {cores: '<2', node: '#ANY'} ] }";
|
||||
cluster.getSolrClient().request(createAutoScalingRequest(SolrRequest.METHOD.POST, commands));
|
||||
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient());
|
||||
}
|
||||
|
||||
public void testDataProviderPerReplicaDetails() throws Exception {
|
||||
CollectionAdminRequest.createCollection("perReplicaDataColl", "conf", 1, 5)
|
||||
.process(cluster.getSolrClient());
|
||||
|
|
|
@ -350,7 +350,7 @@ public class AutoScalingConfig implements MapWriter {
|
|||
public Policy getPolicy() {
|
||||
if (policy == null) {
|
||||
if (jsonMap != null) {
|
||||
policy = new Policy(jsonMap);
|
||||
policy = new Policy(jsonMap, zkVersion);
|
||||
} else {
|
||||
policy = new Policy();
|
||||
}
|
||||
|
|
|
@ -93,13 +93,18 @@ public class Policy implements MapWriter {
|
|||
final List<Preference> clusterPreferences;
|
||||
final List<Pair<String, Type>> params;
|
||||
final List<String> perReplicaAttributes;
|
||||
final int zkVersion;
|
||||
|
||||
public Policy() {
|
||||
this(Collections.emptyMap());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Policy(Map<String, Object> jsonMap) {
|
||||
this(jsonMap, 0);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public Policy(Map<String, Object> jsonMap, int version) {
|
||||
this.zkVersion = version;
|
||||
int[] idx = new int[1];
|
||||
List<Preference> initialClusterPreferences = ((List<Map<String, Object>>) jsonMap.getOrDefault(CLUSTER_PREFERENCES, emptyList())).stream()
|
||||
.map(m -> new Preference(m, idx[0]++))
|
||||
|
@ -150,7 +155,8 @@ public class Policy implements MapWriter {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Policy(Map<String, List<Clause>> policies, List<Clause> clusterPolicy, List<Preference> clusterPreferences) {
|
||||
private Policy(Map<String, List<Clause>> policies, List<Clause> clusterPolicy, List<Preference> clusterPreferences, int version) {
|
||||
this.zkVersion = version;
|
||||
this.policies = policies != null ? Collections.unmodifiableMap(policies) : Collections.emptyMap();
|
||||
this.clusterPolicy = clusterPolicy != null ? Collections.unmodifiableList(clusterPolicy) : Collections.emptyList();
|
||||
this.clusterPreferences = clusterPreferences != null ? Collections.unmodifiableList(clusterPreferences) : DEFAULT_PREFERENCES;
|
||||
|
@ -177,19 +183,19 @@ public class Policy implements MapWriter {
|
|||
}
|
||||
|
||||
public Policy withPolicies(Map<String, List<Clause>> policies) {
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences);
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences, 0);
|
||||
}
|
||||
|
||||
public Policy withClusterPreferences(List<Preference> clusterPreferences) {
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences);
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences, 0);
|
||||
}
|
||||
|
||||
public Policy withClusterPolicy(List<Clause> clusterPolicy) {
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences);
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences, 0);
|
||||
}
|
||||
|
||||
public Policy withParams(List<String> params) {
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences);
|
||||
return new Policy(policies, clusterPolicy, clusterPreferences, 0);
|
||||
}
|
||||
|
||||
public List<Clause> getClusterPolicy() {
|
||||
|
|
|
@ -316,6 +316,7 @@ public class PolicyHelper {
|
|||
TimeSource timeSource = cloudManager.getTimeSource();
|
||||
synchronized (lockObj) {
|
||||
if (sessionWrapper.status == Status.NULL ||
|
||||
sessionWrapper.zkVersion != cloudManager.getDistribStateManager().getAutoScalingConfig().getZkVersion() ||
|
||||
TimeUnit.SECONDS.convert(timeSource.getTimeNs() - sessionWrapper.lastUpdateTime, TimeUnit.NANOSECONDS) > SESSION_EXPIRY) {
|
||||
//no session available or the session is expired
|
||||
return createSession(cloudManager);
|
||||
|
@ -408,6 +409,7 @@ public class PolicyHelper {
|
|||
public Status status;
|
||||
private final SessionRef ref;
|
||||
private AtomicInteger refCount = new AtomicInteger();
|
||||
public final long zkVersion;
|
||||
|
||||
public long getCreateTime() {
|
||||
return createTime;
|
||||
|
@ -424,6 +426,9 @@ public class PolicyHelper {
|
|||
this.session = session;
|
||||
this.status = Status.UNUSED;
|
||||
this.ref = ref;
|
||||
this.zkVersion = session == null ?
|
||||
0 :
|
||||
session.getPolicy().zkVersion;
|
||||
}
|
||||
|
||||
public Policy.Session get() {
|
||||
|
|
Loading…
Reference in New Issue