Skip to content

Commit

Permalink
GEODE-2853: Change of locator list request interval
Browse files Browse the repository at this point in the history
If you connect to a Geode cluster using a locator from the client, the
locator list request will be executed at regular intervals in the
background thread. I want to tune this interval. I understand that this
interval can be changed by the ping-interval of the Pool attribute.
However, I think that ping-interval originally sets the ping interval
for health check to the cache server. Therefore, it is not possible to
change the locator list request interval without changing the health
check interval to the cache server. So,I want to add a java system
property that can change the locator list request interval.

The locator list request interval is determined by the following
priority order.

  1. java system property "gemfire.LOCATOR_UPDATE_INTERVAL"
  2. ping-interval of the Pool attribute

In addition, when changing this time, the background thread is activated
only when this value is a positive value.
  • Loading branch information
masaki-yamakawa authored and bschuchardt committed May 15, 2017
1 parent 5585b73 commit a7441ae
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.geode.cache.client.internal.locator.QueueConnectionResponse;
import org.apache.geode.cache.client.internal.locator.ServerLocationRequest;
import org.apache.geode.cache.client.internal.locator.ServerLocationResponse;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.ServerLocation;
import org.apache.geode.distributed.internal.tcpserver.TcpClient;
import org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID;
Expand Down Expand Up @@ -92,7 +93,7 @@ public int compare(InetSocketAddress o1, InetSocketAddress o2) {
private AtomicReference<LocatorList> onlineLocators = new AtomicReference<LocatorList>();
protected InternalPool pool;
private final int connectionTimeout;
private long pingInterval;
private long locatorUpdateInterval;
private volatile LocatorDiscoveryCallback locatorCallback = new LocatorDiscoveryCallbackAdapter();
private volatile boolean isBalanced = true;
/**
Expand Down Expand Up @@ -307,10 +308,16 @@ protected void updateLocatorList(LocatorListResponse response) {
public void start(InternalPool pool) {
this.pool = pool;
pool.getStats().setInitialContacts(((LocatorList) locators.get()).size());
this.pingInterval = pool.getPingInterval();
this.locatorUpdateInterval = Long.getLong(
DistributionConfig.GEMFIRE_PREFIX + "LOCATOR_UPDATE_INTERVAL", pool.getPingInterval());

pool.getBackgroundProcessor().scheduleWithFixedDelay(new UpdateLocatorListTask(), 0,
pingInterval, TimeUnit.MILLISECONDS);
if (locatorUpdateInterval > 0) {
pool.getBackgroundProcessor().scheduleWithFixedDelay(new UpdateLocatorListTask(), 0,
locatorUpdateInterval, TimeUnit.MILLISECONDS);
logger.info(LocalizedMessage.create(
LocalizedStrings.AutoConnectionSourceImpl_UPDATE_LOCATOR_LIST_TASK_STARTED_WITH_INTERVAL_0,
new Object[] {this.locatorUpdateInterval}));
}
}

public void stop() {
Expand Down Expand Up @@ -344,6 +351,10 @@ private synchronized void reportDeadLocator(InetSocketAddress l, Exception ex) {
}
}

long getLocatorUpdateInterval() {
return this.locatorUpdateInterval;
}

/**
* A list of locators, which remembers the last known good locator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5812,6 +5812,9 @@ public class LocalizedStrings {
new StringId(4480, "Communication with locator {0} failed with {1}.");
public static final StringId AutoConnectionSourceImpl_LOCATOR_0_IS_NOT_RUNNING =
new StringId(4481, "locator {0} is not running.");
public static final StringId AutoConnectionSourceImpl_UPDATE_LOCATOR_LIST_TASK_STARTED_WITH_INTERVAL_0 =
new StringId(4482,
"AutoConnectionSource UpdateLocatorListTask started with interval={0} ms.");
public static final StringId AutoConnectionSourceImpl_COULD_NOT_CREATE_A_NEW_CONNECTION_TO_SERVER_0 =
new StringId(4484, "Could not create a new connection to server: {0}");
public static final StringId DistributionAdvisor_0_SEC_HAVE_ELAPSED_WHILE_WAITING_FOR_CURRENT_OPERATIONS_TO_DISTRIBUTE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,40 @@ public void testClientMembershipListener() throws Exception {
Assert.assertEquals(0, serverListener.getJoins());
}

@Test
public void testUpdateLocatorListInterval() throws Exception {
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);

int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
String hostName = NetworkUtils.getServerHostName(vm0.getHost());
vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));

Properties props = new Properties();
long updateLocatorInterval;

vm1.invoke("StartBridgeClient", () -> startBridgeClient("group1",
NetworkUtils.getServerHostName(vm0.getHost()), locatorPort, props));
checkUpdateLocatorListInterval(vm1, 200);
stopBridgeMemberVM(vm1);

updateLocatorInterval = 0;
props.setProperty(DistributionConfig.GEMFIRE_PREFIX + "LOCATOR_UPDATE_INTERVAL",
String.valueOf(updateLocatorInterval));
vm1.invoke("StartBridgeClient", () -> startBridgeClient("group2",
NetworkUtils.getServerHostName(vm0.getHost()), locatorPort, props));
checkUpdateLocatorListInterval(vm1, updateLocatorInterval);
stopBridgeMemberVM(vm1);

updateLocatorInterval = 543;
props.setProperty(DistributionConfig.GEMFIRE_PREFIX + "LOCATOR_UPDATE_INTERVAL",
String.valueOf(updateLocatorInterval));
vm1.invoke("StartBridgeClient", () -> startBridgeClient("group2",
NetworkUtils.getServerHostName(vm0.getHost()), locatorPort, props));
checkUpdateLocatorListInterval(vm1, updateLocatorInterval);
}

protected Object getInVM(VM vm, final Serializable key) {
return getInVM(vm, REGION_NAME, key);
}
Expand Down Expand Up @@ -535,6 +569,15 @@ public void run() {
});
}

protected void checkUpdateLocatorListInterval(VM vm, final long expected) {
vm.invoke(() -> {
PoolImpl pool = (PoolImpl) PoolManager.find(POOL_NAME);
long actual = AutoConnectionSourceImpl.class.cast(pool.getConnectionSource())
.getLocatorUpdateInterval();
Assert.assertEquals(expected, actual);
});
}

protected void addBridgeListener(VM vm) {
vm.invoke(new SerializableRunnable("Add membership listener") {
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ public void run() throws Exception {
}
}

protected void startBridgeClient(final String group, final String host, final int port,
Properties systemProperties) throws Exception {
systemProperties.entrySet().forEach(
entry -> System.setProperty(entry.getKey().toString(), entry.getValue().toString()));
startBridgeClient(group, host, port, new String[] {REGION_NAME});
}

protected void startBridgeClient(final String group, final String host, final int port)
throws Exception {
startBridgeClient(group, host, port, new String[] {REGION_NAME});
Expand Down

0 comments on commit a7441ae

Please sign in to comment.