revert to constant backoff

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2024-10-11 12:19:50 +05:30
parent 7ecc173187
commit 52c483d91d
3 changed files with 11 additions and 93 deletions

View File

@ -418,3 +418,9 @@ iscsi.session.cleanup.enabled=false
# Implicit host tags managed by agent.properties
# host.tags=
# Timeout(in seconds) for SSL handshake when agent connects to server
#ssl.handshake.timeout=
# Wait(in seconds) during agent reconnections
#backoff.seconds=

View File

@ -51,7 +51,7 @@ import com.cloud.utils.LogUtils;
import com.cloud.utils.ProcessUtil;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.backoff.BackoffAlgorithm;
import com.cloud.utils.backoff.impl.RangeTimeBackoff;
import com.cloud.utils.backoff.impl.ConstantTimeBackoff;
import com.cloud.utils.exception.CloudRuntimeException;
public class AgentShell implements IAgentShell, Daemon {
@ -405,12 +405,11 @@ public class AgentShell implements IAgentShell, Daemon {
_properties.put(cmdLineProp.getKey(), cmdLineProp.getValue());
}
s_logger.info("Defaulting to the range time backoff algorithm");
_backoff = new RangeTimeBackoff();
s_logger.info("Defaulting to the constant time backoff algorithm");
_backoff = new ConstantTimeBackoff();
Map<String, Object> map = new HashMap<>();
map.put("minSeconds", _properties.getProperty("backoff.min.seconds"));
map.put("maxSeconds", _properties.getProperty("backoff.max.seconds"));
_backoff.configure("RangeTimeBackoff", map);
map.put("seconds", _properties.getProperty("backoff.seconds"));
_backoff.configure("ConstantTimeBackoff", map);
}
private void launchAgent() throws ConfigurationException {

View File

@ -1,87 +0,0 @@
// 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.
package com.cloud.utils.backoff.impl;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class RangeTimeBackoffTest {
@Test
public void testWaitValidValue() {
RangeTimeBackoff backoff = new RangeTimeBackoff();
Map<String, Object> map = new HashMap<>();
int min = 1;
int max = 3;
map.put("minSeconds", String.valueOf(min));
map.put("maxSeconds", String.valueOf(max));
backoff.configure("RangeTimeBackoff", map);
long startTime = System.currentTimeMillis();
backoff.waitBeforeRetry();
long timeTaken = System.currentTimeMillis() - startTime;
Assert.assertTrue(timeTaken >= min * 1000L);
Assert.assertTrue(timeTaken <= max * 1000L);
}
private void checkTimeTakenBetweenDelta(long timeTaken, int value) {
long min = (value * 1000L) - 10L;
long max = (value* 1000L) + 10L;
Assert.assertTrue(min <= timeTaken && timeTaken <= max);
}
@Test
public void testWaitEmptyValue() {
RangeTimeBackoff backoff = new RangeTimeBackoff();
Map<String, Object> map = new HashMap<>();
map.put("minSeconds", "");
map.put("maxSeconds", "");
backoff.configure("RangeTimeBackoff", map);
long startTime = System.currentTimeMillis();
backoff.waitBeforeRetry();
checkTimeTakenBetweenDelta(System.currentTimeMillis() - startTime, RangeTimeBackoff.DEFAULT_MIN_TIME);
}
@Test
public void testWaitNullValue() {
RangeTimeBackoff backoff = new RangeTimeBackoff();
Map<String, Object> map = new HashMap<>();
backoff.configure("RangeTimeBackoff", map);
long startTime = System.currentTimeMillis();
backoff.waitBeforeRetry();
checkTimeTakenBetweenDelta(System.currentTimeMillis() - startTime, RangeTimeBackoff.DEFAULT_MIN_TIME);
}
@Test
public void testWaitVMinHigherThanMax() {
RangeTimeBackoff backoff = new RangeTimeBackoff();
Map<String, Object> map = new HashMap<>();
int min = 3;
int max = 2;
map.put("minSeconds", String.valueOf(min));
map.put("maxSeconds", String.valueOf(max));
backoff.configure("RangeTimeBackoff", map);
long startTime = System.currentTimeMillis();
backoff.waitBeforeRetry();
checkTimeTakenBetweenDelta(System.currentTimeMillis() - startTime, min);
}
}