clear old migration rule (#6896)

This commit is contained in:
ken.lj 2020-11-11 15:17:07 +08:00 committed by GitHub
parent 69c80f631f
commit 0fa09cc34f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -52,7 +52,7 @@ public class DefaultMigrationAddressComparator implements MigrationAddressCompar
String rawThreshold = null;
Float configedThreshold = rule == null ? null : rule.getThreshold(invoker.getUrl().getServiceKey());
if (configedThreshold != null) {
if (configedThreshold != null && configedThreshold >= 0) {
rawThreshold = String.valueOf(configedThreshold);
}
rawThreshold = StringUtils.isNotEmpty(rawThreshold) ? rawThreshold : ConfigurationUtils.getDynamicProperty(MIGRATION_THRESHOLD, DEFAULT_THRESHOLD_STRING);

View File

@ -48,7 +48,7 @@ public class MigrationRuleHandler<T> {
MigrationStep step = (migrationInvoker instanceof ServiceDiscoveryMigrationInvoker)
? MigrationStep.FORCE_APPLICATION
: MigrationStep.INTERFACE_FIRST;
Float threshold = 0f;
Float threshold = -1f;
if (StringUtils.isEmpty(rawRule)) {
logger.error("Find empty migration rule, will ignore.");
return;
@ -58,12 +58,19 @@ public class MigrationRuleHandler<T> {
try {
rule = MigrationRule.parse(rawRule);
// FIXME, consumerURL.getHost() might not exactly the ip expected.
if (CollectionUtils.isEmpty(rule.getTargetIps()) || rule.getTargetIps().contains(consumerURL.getHost())) {
if (CollectionUtils.isEmpty(rule.getTargetIps())) {
setMigrationRule(rule);
step = rule.getStep(consumerURL.getServiceKey());
threshold = rule.getThreshold(consumerURL.getServiceKey());
} else {
logger.info("Migration rule ignored, rule target ips " + rule.getTargetIps() + " and local ip " + consumerURL.getHost() + " do not match");
if (rule.getTargetIps().contains(consumerURL.getHost())) {
setMigrationRule(rule);
step = rule.getStep(consumerURL.getServiceKey());
threshold = rule.getThreshold(consumerURL.getServiceKey());
} else {
setMigrationRule(null); // clear previous rule
logger.info("New migration rule ignored and previous migration rule cleared, new target ips " + rule.getTargetIps() + " and local ip " + consumerURL.getHost() + " do not match");
}
}
} catch (Exception e) {
logger.error("Parse migration rule error, will use default step " + step, e);
@ -89,10 +96,10 @@ public class MigrationRuleHandler<T> {
public void setCurrentStepAndThreshold(MigrationStep currentStep, Float currentThreshold) {
this.currentStep = currentStep;
this.currentThreshold = currentThreshold;
this.migrationInvoker.setMigrationStep(currentStep);
}
public void setMigrationRule(MigrationRule rule) {
this.migrationInvoker.setMigrationStep(currentStep);
this.migrationInvoker.setMigrationRule(rule);
}
}