You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2019/04/19 11:38:14 UTC
[ignite] branch master updated: IGNITE-11649 Java thin client:
Fixed failover for single server configuration - Fixes #6386.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 0b266d6 IGNITE-11649 Java thin client: Fixed failover for single server configuration - Fixes #6386.
0b266d6 is described below
commit 0b266d673fcc843ffc5139ddbe567030718cabfa
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Fri Apr 19 14:31:46 2019 +0300
IGNITE-11649 Java thin client: Fixed failover for single server configuration - Fixes #6386.
---
.../internal/client/thin/ReliableChannel.java | 19 +++++-----
.../org/apache/ignite/client/ReliabilityTest.java | 43 +++++++++++++++++++++-
2 files changed, 51 insertions(+), 11 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
index 06d93b1..8edcc16 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
@@ -131,9 +131,6 @@ final class ReliableChannel implements AutoCloseable {
try {
for (int i = 0; i < totalSrvs; i++) {
try {
- if (failure != null)
- changeServer();
-
if (ch == null)
ch = chFactory.apply(new ClientChannelConfiguration(clientCfg).setAddress(primary)).get();
@@ -150,6 +147,8 @@ final class ReliableChannel implements AutoCloseable {
failure = e;
else
failure.addSuppressed(e);
+
+ changeServer();
}
}
}
@@ -222,14 +221,14 @@ final class ReliableChannel implements AutoCloseable {
backups.addLast(primary);
primary = backups.removeFirst();
+ }
- try {
- ch.close();
- }
- catch (Exception ignored) {
- }
-
- ch = null;
+ try {
+ ch.close();
+ }
+ catch (Exception ignored) {
}
+
+ ch = null;
}
}
diff --git a/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java b/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java
index f019fd9..9f933c8 100644
--- a/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/client/ReliabilityTest.java
@@ -17,6 +17,7 @@
package org.apache.ignite.client;
+import java.lang.management.ManagementFactory;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -28,14 +29,19 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.cache.Cache;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.query.Query;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.ScanQuery;
-import org.apache.ignite.internal.processors.platform.client.ClientStatus;
import org.apache.ignite.configuration.ClientConfiguration;
import org.apache.ignite.internal.client.thin.ClientServerError;
+import org.apache.ignite.internal.processors.odbc.ClientListenerProcessor;
+import org.apache.ignite.internal.processors.platform.client.ClientStatus;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.mxbean.ClientProcessorMXBean;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Rule;
import org.junit.Test;
@@ -127,6 +133,41 @@ public class ReliabilityTest {
}
}
+ /**
+ * Test single server failover.
+ */
+ @Test
+ public void testSingleServerFailover() throws Exception {
+ try (LocalIgniteCluster cluster = LocalIgniteCluster.start(1);
+ IgniteClient client = Ignition.startClient(new ClientConfiguration()
+ .setAddresses(cluster.clientAddresses().iterator().next()))
+ ) {
+ ObjectName mbeanName = U.makeMBeanName(Ignition.allGrids().get(0).name(), "Clients",
+ ClientListenerProcessor.class.getSimpleName());
+
+ ClientProcessorMXBean mxBean = MBeanServerInvocationHandler.newProxyInstance(
+ ManagementFactory.getPlatformMBeanServer(), mbeanName, ClientProcessorMXBean.class,true);
+
+ ClientCache<Integer, Integer> cache = client.createCache("cache");
+
+ // Before fail.
+ cache.put(0, 0);
+
+ // Fail.
+ mxBean.dropAllConnections();
+
+ try {
+ cache.put(0, 0);
+ }
+ catch (Exception expected) {
+ // No-op.
+ }
+
+ // Recover after fail.
+ cache.put(0, 0);
+ }
+ }
+
/** */
@FunctionalInterface
private interface Assertion {