Committed by
Gerrit Code Review
Copycat transport enhancements
Change-Id: I50e9eb0f419b2aa10deff6d54f58649688788faa
Showing
7 changed files
with
109 additions
and
154 deletions
... | @@ -15,29 +15,19 @@ | ... | @@ -15,29 +15,19 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.primitives.impl; | 16 | package org.onosproject.store.primitives.impl; |
17 | 17 | ||
18 | -import io.atomix.catalyst.serializer.CatalystSerializable; | 18 | +import java.util.Arrays; |
19 | + | ||
19 | import io.atomix.catalyst.serializer.Serializer; | 20 | import io.atomix.catalyst.serializer.Serializer; |
20 | import io.atomix.catalyst.serializer.TypeSerializerFactory; | 21 | import io.atomix.catalyst.serializer.TypeSerializerFactory; |
21 | import io.atomix.copycat.client.Query; | 22 | import io.atomix.copycat.client.Query; |
22 | -import io.atomix.manager.state.GetResource; | ||
23 | -import io.atomix.manager.state.GetResourceKeys; | ||
24 | -import io.atomix.resource.ResourceQuery; | ||
25 | -import io.atomix.variables.state.ValueCommands; | ||
26 | - | ||
27 | -import java.io.IOException; | ||
28 | -import java.net.URL; | ||
29 | -import java.util.Arrays; | ||
30 | -import java.util.Enumeration; | ||
31 | -import java.util.Scanner; | ||
32 | 23 | ||
33 | import org.onlab.util.Match; | 24 | import org.onlab.util.Match; |
25 | +import org.onosproject.cluster.Leader; | ||
26 | +import org.onosproject.cluster.Leadership; | ||
34 | import org.onosproject.cluster.NodeId; | 27 | import org.onosproject.cluster.NodeId; |
35 | import org.onosproject.event.Change; | 28 | import org.onosproject.event.Change; |
36 | import org.onosproject.store.primitives.MapUpdate; | 29 | import org.onosproject.store.primitives.MapUpdate; |
37 | import org.onosproject.store.primitives.TransactionId; | 30 | import org.onosproject.store.primitives.TransactionId; |
38 | -import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapCommands; | ||
39 | -import org.onosproject.store.primitives.resources.impl.AtomixConsistentMapState; | ||
40 | -import org.onosproject.store.primitives.resources.impl.AtomixLeaderElectorCommands; | ||
41 | import org.onosproject.store.primitives.resources.impl.CommitResult; | 31 | import org.onosproject.store.primitives.resources.impl.CommitResult; |
42 | import org.onosproject.store.primitives.resources.impl.MapEntryUpdateResult; | 32 | import org.onosproject.store.primitives.resources.impl.MapEntryUpdateResult; |
43 | import org.onosproject.store.primitives.resources.impl.PrepareResult; | 33 | import org.onosproject.store.primitives.resources.impl.PrepareResult; |
... | @@ -47,7 +37,6 @@ import org.onosproject.store.service.MapEvent; | ... | @@ -47,7 +37,6 @@ import org.onosproject.store.service.MapEvent; |
47 | import org.onosproject.store.service.MapTransaction; | 37 | import org.onosproject.store.service.MapTransaction; |
48 | import org.onosproject.store.service.Versioned; | 38 | import org.onosproject.store.service.Versioned; |
49 | 39 | ||
50 | -import com.google.common.base.Throwables; | ||
51 | import com.google.common.collect.Maps; | 40 | import com.google.common.collect.Maps; |
52 | 41 | ||
53 | /** | 42 | /** |
... | @@ -65,113 +54,31 @@ public final class CatalystSerializers { | ... | @@ -65,113 +54,31 @@ public final class CatalystSerializers { |
65 | org.onosproject.store.service.Serializer.using(Arrays.asList((KryoNamespaces.API)), | 54 | org.onosproject.store.service.Serializer.using(Arrays.asList((KryoNamespaces.API)), |
66 | MapEntryUpdateResult.class, | 55 | MapEntryUpdateResult.class, |
67 | MapEntryUpdateResult.Status.class, | 56 | MapEntryUpdateResult.Status.class, |
68 | - MapUpdate.class, | ||
69 | - MapUpdate.Type.class, | ||
70 | - MapTransaction.class, | ||
71 | Transaction.State.class, | 57 | Transaction.State.class, |
72 | - TransactionId.class, | ||
73 | PrepareResult.class, | 58 | PrepareResult.class, |
74 | CommitResult.class, | 59 | CommitResult.class, |
75 | RollbackResult.class, | 60 | RollbackResult.class, |
76 | - AtomixConsistentMapCommands.Get.class, | ||
77 | - AtomixConsistentMapCommands.ContainsKey.class, | ||
78 | - AtomixConsistentMapCommands.ContainsValue.class, | ||
79 | - AtomixConsistentMapCommands.Size.class, | ||
80 | - AtomixConsistentMapCommands.IsEmpty.class, | ||
81 | - AtomixConsistentMapCommands.KeySet.class, | ||
82 | - AtomixConsistentMapCommands.EntrySet.class, | ||
83 | - AtomixConsistentMapCommands.Values.class, | ||
84 | - AtomixConsistentMapCommands.UpdateAndGet.class, | ||
85 | - AtomixConsistentMapCommands.TransactionPrepare.class, | ||
86 | - AtomixConsistentMapCommands.TransactionCommit.class, | ||
87 | - AtomixConsistentMapCommands.TransactionRollback.class, | ||
88 | - AtomixLeaderElectorCommands.GetLeadership.class, | ||
89 | - AtomixLeaderElectorCommands.GetAllLeaderships.class, | ||
90 | - AtomixLeaderElectorCommands.GetElectedTopics.class, | ||
91 | - AtomixLeaderElectorCommands.Run.class, | ||
92 | - AtomixLeaderElectorCommands.Withdraw.class, | ||
93 | - AtomixLeaderElectorCommands.Anoint.class, | ||
94 | - GetResource.class, | ||
95 | - GetResourceKeys.class, | ||
96 | - ResourceQuery.class, | ||
97 | - ValueCommands.Get.class, | ||
98 | - ValueCommands.Set.class, | ||
99 | Query.ConsistencyLevel.class)); | 61 | Query.ConsistencyLevel.class)); |
100 | // ONOS classes | 62 | // ONOS classes |
101 | serializer.register(Change.class, factory); | 63 | serializer.register(Change.class, factory); |
64 | + serializer.register(Leader.class, factory); | ||
65 | + serializer.register(Leadership.class, factory); | ||
102 | serializer.register(NodeId.class, factory); | 66 | serializer.register(NodeId.class, factory); |
103 | serializer.register(Match.class, factory); | 67 | serializer.register(Match.class, factory); |
104 | serializer.register(MapEntryUpdateResult.class, factory); | 68 | serializer.register(MapEntryUpdateResult.class, factory); |
105 | serializer.register(MapEntryUpdateResult.Status.class, factory); | 69 | serializer.register(MapEntryUpdateResult.Status.class, factory); |
106 | - serializer.register(MapTransaction.class, factory); | ||
107 | serializer.register(Transaction.State.class, factory); | 70 | serializer.register(Transaction.State.class, factory); |
108 | serializer.register(PrepareResult.class, factory); | 71 | serializer.register(PrepareResult.class, factory); |
109 | serializer.register(CommitResult.class, factory); | 72 | serializer.register(CommitResult.class, factory); |
110 | serializer.register(RollbackResult.class, factory); | 73 | serializer.register(RollbackResult.class, factory); |
111 | serializer.register(TransactionId.class, factory); | 74 | serializer.register(TransactionId.class, factory); |
112 | serializer.register(MapUpdate.class, factory); | 75 | serializer.register(MapUpdate.class, factory); |
76 | + serializer.register(MapUpdate.Type.class, factory); | ||
77 | + serializer.register(MapTransaction.class, factory); | ||
113 | serializer.register(Versioned.class, factory); | 78 | serializer.register(Versioned.class, factory); |
114 | serializer.register(MapEvent.class, factory); | 79 | serializer.register(MapEvent.class, factory); |
115 | serializer.register(Maps.immutableEntry("a", "b").getClass(), factory); | 80 | serializer.register(Maps.immutableEntry("a", "b").getClass(), factory); |
116 | - serializer.register(AtomixConsistentMapState.class, factory); | ||
117 | - | ||
118 | - serializer.register(ResourceQuery.class, factory); | ||
119 | - serializer.register(GetResource.class, factory); | ||
120 | - serializer.register(GetResourceKeys.class, factory); | ||
121 | - serializer.register(ValueCommands.Get.class, factory); | ||
122 | - serializer.register(ValueCommands.Set.class, factory); | ||
123 | 81 | ||
124 | - // ConsistentMap | ||
125 | - serializer.register(AtomixConsistentMapCommands.UpdateAndGet.class, factory); | ||
126 | - serializer.register(AtomixConsistentMapCommands.Clear.class); | ||
127 | - serializer.register(AtomixConsistentMapCommands.Listen.class); | ||
128 | - serializer.register(AtomixConsistentMapCommands.Unlisten.class); | ||
129 | - serializer.register(AtomixConsistentMapCommands.Get.class); | ||
130 | - serializer.register(AtomixConsistentMapCommands.ContainsKey.class); | ||
131 | - serializer.register(AtomixConsistentMapCommands.ContainsValue.class); | ||
132 | - serializer.register(AtomixConsistentMapCommands.EntrySet.class); | ||
133 | - serializer.register(AtomixConsistentMapCommands.IsEmpty.class); | ||
134 | - serializer.register(AtomixConsistentMapCommands.KeySet.class); | ||
135 | - serializer.register(AtomixConsistentMapCommands.Size.class); | ||
136 | - serializer.register(AtomixConsistentMapCommands.Values.class); | ||
137 | - serializer.register(AtomixConsistentMapCommands.TransactionPrepare.class); | ||
138 | - serializer.register(AtomixConsistentMapCommands.TransactionCommit.class); | ||
139 | - serializer.register(AtomixConsistentMapCommands.TransactionRollback.class); | ||
140 | - // LeaderElector | ||
141 | - serializer.register(AtomixLeaderElectorCommands.Run.class, factory); | ||
142 | - serializer.register(AtomixLeaderElectorCommands.Withdraw.class, factory); | ||
143 | - serializer.register(AtomixLeaderElectorCommands.Anoint.class, factory); | ||
144 | - serializer.register(AtomixLeaderElectorCommands.GetElectedTopics.class, factory); | ||
145 | - serializer.register(AtomixLeaderElectorCommands.GetElectedTopics.class, factory); | ||
146 | - serializer.register(AtomixLeaderElectorCommands.GetLeadership.class, factory); | ||
147 | - serializer.register(AtomixLeaderElectorCommands.GetAllLeaderships.class, factory); | ||
148 | - serializer.register(AtomixLeaderElectorCommands.Listen.class); | ||
149 | - serializer.register(AtomixLeaderElectorCommands.Unlisten.class); | ||
150 | - // Atomix types | ||
151 | - try { | ||
152 | - ClassLoader cl = CatalystSerializable.class.getClassLoader(); | ||
153 | - Enumeration<URL> urls = cl.getResources( | ||
154 | - String.format("META-INF/services/%s", CatalystSerializable.class.getName())); | ||
155 | - while (urls.hasMoreElements()) { | ||
156 | - URL url = urls.nextElement(); | ||
157 | - try (Scanner scanner = new Scanner(url.openStream(), "UTF-8")) { | ||
158 | - scanner.useDelimiter("\n").forEachRemaining(line -> { | ||
159 | - if (!line.trim().startsWith("#")) { | ||
160 | - line = line.trim(); | ||
161 | - if (line.length() > 0) { | ||
162 | - try { | ||
163 | - serializer.register(cl.loadClass(line)); | ||
164 | - } catch (ClassNotFoundException e) { | ||
165 | - Throwables.propagate(e); | ||
166 | - } | ||
167 | - } | ||
168 | - } | ||
169 | - }); | ||
170 | - } | ||
171 | - } | ||
172 | - } catch (IOException e) { | ||
173 | - Throwables.propagate(e); | ||
174 | - } | ||
175 | return serializer; | 82 | return serializer; |
176 | } | 83 | } |
177 | } | 84 | } | ... | ... |
... | @@ -17,9 +17,20 @@ package org.onosproject.store.primitives.impl; | ... | @@ -17,9 +17,20 @@ package org.onosproject.store.primitives.impl; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | 19 | ||
20 | +import java.net.InetAddress; | ||
21 | +import java.net.InetSocketAddress; | ||
22 | +import java.net.UnknownHostException; | ||
23 | +import java.util.Map; | ||
24 | + | ||
25 | +import org.onlab.packet.IpAddress; | ||
20 | import org.onosproject.cluster.PartitionId; | 26 | import org.onosproject.cluster.PartitionId; |
27 | +import org.onosproject.store.cluster.messaging.Endpoint; | ||
21 | import org.onosproject.store.cluster.messaging.MessagingService; | 28 | import org.onosproject.store.cluster.messaging.MessagingService; |
22 | 29 | ||
30 | +import com.google.common.base.Throwables; | ||
31 | +import com.google.common.collect.Maps; | ||
32 | + | ||
33 | +import io.atomix.catalyst.transport.Address; | ||
23 | import io.atomix.catalyst.transport.Client; | 34 | import io.atomix.catalyst.transport.Client; |
24 | import io.atomix.catalyst.transport.Server; | 35 | import io.atomix.catalyst.transport.Server; |
25 | import io.atomix.catalyst.transport.Transport; | 36 | import io.atomix.catalyst.transport.Transport; |
... | @@ -51,6 +62,8 @@ public class CopycatTransport implements Transport { | ... | @@ -51,6 +62,8 @@ public class CopycatTransport implements Transport { |
51 | private final Mode mode; | 62 | private final Mode mode; |
52 | private final PartitionId partitionId; | 63 | private final PartitionId partitionId; |
53 | private final MessagingService messagingService; | 64 | private final MessagingService messagingService; |
65 | + private static final Map<Address, Endpoint> EP_LOOKUP_CACHE = Maps.newConcurrentMap(); | ||
66 | + private static final Map<Endpoint, Address> ADDRESS_LOOKUP_CACHE = Maps.newConcurrentMap(); | ||
54 | 67 | ||
55 | public CopycatTransport(Mode mode, PartitionId partitionId, MessagingService messagingService) { | 68 | public CopycatTransport(Mode mode, PartitionId partitionId, MessagingService messagingService) { |
56 | this.mode = checkNotNull(mode); | 69 | this.mode = checkNotNull(mode); |
... | @@ -70,4 +83,42 @@ public class CopycatTransport implements Transport { | ... | @@ -70,4 +83,42 @@ public class CopycatTransport implements Transport { |
70 | return new CopycatTransportServer(partitionId, | 83 | return new CopycatTransportServer(partitionId, |
71 | messagingService); | 84 | messagingService); |
72 | } | 85 | } |
86 | + | ||
87 | + /** | ||
88 | + * Maps {@link Address address} to {@link Endpoint endpoint}. | ||
89 | + * @param address | ||
90 | + * @return end point | ||
91 | + */ | ||
92 | + public static Endpoint toEndpoint(Address address) { | ||
93 | + return EP_LOOKUP_CACHE.computeIfAbsent(address, a -> { | ||
94 | + try { | ||
95 | + Endpoint endpoint = new Endpoint(IpAddress.valueOf(InetAddress.getByName(a.host())), a.port()); | ||
96 | + ADDRESS_LOOKUP_CACHE.putIfAbsent(endpoint, address); | ||
97 | + return endpoint; | ||
98 | + } catch (UnknownHostException e) { | ||
99 | + Throwables.propagate(e); | ||
100 | + return null; | ||
101 | + } | ||
102 | + }); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Maps {@link Endpoint endpoint} to {@link Address address}. | ||
107 | + * @param endpoint end point | ||
108 | + * @return address | ||
109 | + */ | ||
110 | + public static Address toAddress(Endpoint endpoint) { | ||
111 | + return ADDRESS_LOOKUP_CACHE.computeIfAbsent(endpoint, ep -> { | ||
112 | + try { | ||
113 | + InetAddress host = InetAddress.getByAddress(endpoint.host().toOctets()); | ||
114 | + int port = endpoint.port(); | ||
115 | + Address address = new Address(new InetSocketAddress(host, port)); | ||
116 | + EP_LOOKUP_CACHE.putIfAbsent(address, endpoint); | ||
117 | + return address; | ||
118 | + } catch (UnknownHostException e) { | ||
119 | + Throwables.propagate(e); | ||
120 | + return null; | ||
121 | + } | ||
122 | + }); | ||
123 | + } | ||
73 | } | 124 | } | ... | ... |
... | @@ -50,18 +50,23 @@ public class CopycatTransportClient implements Client { | ... | @@ -50,18 +50,23 @@ public class CopycatTransportClient implements Client { |
50 | @Override | 50 | @Override |
51 | public CompletableFuture<Connection> connect(Address remoteAddress) { | 51 | public CompletableFuture<Connection> connect(Address remoteAddress) { |
52 | ThreadContext context = ThreadContext.currentContextOrThrow(); | 52 | ThreadContext context = ThreadContext.currentContextOrThrow(); |
53 | - CopycatTransportConnection connection = new CopycatTransportConnection( | 53 | + return messagingService.sendAndReceive(CopycatTransport.toEndpoint(remoteAddress), |
54 | - nextConnectionId(), | 54 | + PartitionManager.HELLO_MESSAGE_SUBJECT, |
55 | - CopycatTransport.Mode.CLIENT, | 55 | + "hello".getBytes()) |
56 | - partitionId, | 56 | + .thenApplyAsync(r -> { |
57 | - remoteAddress, | 57 | + CopycatTransportConnection connection = new CopycatTransportConnection( |
58 | - messagingService, | 58 | + nextConnectionId(), |
59 | - context); | 59 | + CopycatTransport.Mode.CLIENT, |
60 | - if (mode == CopycatTransport.Mode.CLIENT) { | 60 | + partitionId, |
61 | - connection.setBidirectional(); | 61 | + remoteAddress, |
62 | - } | 62 | + messagingService, |
63 | - connections.add(connection); | 63 | + context); |
64 | - return CompletableFuture.supplyAsync(() -> connection, context.executor()); | 64 | + if (mode == CopycatTransport.Mode.CLIENT) { |
65 | + connection.setBidirectional(); | ||
66 | + } | ||
67 | + connections.add(connection); | ||
68 | + return connection; | ||
69 | + }, context.executor()); | ||
65 | } | 70 | } |
66 | 71 | ||
67 | @Override | 72 | @Override | ... | ... |
... | @@ -21,8 +21,6 @@ import java.io.DataInputStream; | ... | @@ -21,8 +21,6 @@ import java.io.DataInputStream; |
21 | import java.io.DataOutputStream; | 21 | import java.io.DataOutputStream; |
22 | import java.io.IOException; | 22 | import java.io.IOException; |
23 | import java.io.InputStream; | 23 | import java.io.InputStream; |
24 | -import java.net.InetAddress; | ||
25 | -import java.net.UnknownHostException; | ||
26 | import java.util.Map; | 24 | import java.util.Map; |
27 | import java.util.Objects; | 25 | import java.util.Objects; |
28 | import java.util.concurrent.CompletableFuture; | 26 | import java.util.concurrent.CompletableFuture; |
... | @@ -30,10 +28,8 @@ import java.util.concurrent.atomic.AtomicInteger; | ... | @@ -30,10 +28,8 @@ import java.util.concurrent.atomic.AtomicInteger; |
30 | import java.util.function.Consumer; | 28 | import java.util.function.Consumer; |
31 | 29 | ||
32 | import org.apache.commons.io.IOUtils; | 30 | import org.apache.commons.io.IOUtils; |
33 | -import org.onlab.packet.IpAddress; | ||
34 | import org.onlab.util.Tools; | 31 | import org.onlab.util.Tools; |
35 | import org.onosproject.cluster.PartitionId; | 32 | import org.onosproject.cluster.PartitionId; |
36 | -import org.onosproject.store.cluster.messaging.Endpoint; | ||
37 | import org.onosproject.store.cluster.messaging.MessagingService; | 33 | import org.onosproject.store.cluster.messaging.MessagingService; |
38 | 34 | ||
39 | import com.google.common.base.MoreObjects; | 35 | import com.google.common.base.MoreObjects; |
... | @@ -74,7 +70,6 @@ public class CopycatTransportConnection implements Connection { | ... | @@ -74,7 +70,6 @@ public class CopycatTransportConnection implements Connection { |
74 | private final AtomicInteger sendFailures = new AtomicInteger(0); | 70 | private final AtomicInteger sendFailures = new AtomicInteger(0); |
75 | private final AtomicInteger messagesReceived = new AtomicInteger(0); | 71 | private final AtomicInteger messagesReceived = new AtomicInteger(0); |
76 | private final AtomicInteger receiveFailures = new AtomicInteger(0); | 72 | private final AtomicInteger receiveFailures = new AtomicInteger(0); |
77 | - private final Map<Address, Endpoint> endpointLookupCache = Maps.newConcurrentMap(); | ||
78 | 73 | ||
79 | CopycatTransportConnection(long connectionId, | 74 | CopycatTransportConnection(long connectionId, |
80 | CopycatTransport.Mode mode, | 75 | CopycatTransport.Mode mode, |
... | @@ -120,7 +115,7 @@ public class CopycatTransportConnection implements Connection { | ... | @@ -120,7 +115,7 @@ public class CopycatTransportConnection implements Connection { |
120 | if (message instanceof ReferenceCounted) { | 115 | if (message instanceof ReferenceCounted) { |
121 | ((ReferenceCounted<?>) message).release(); | 116 | ((ReferenceCounted<?>) message).release(); |
122 | } | 117 | } |
123 | - messagingService.sendAndReceive(toEndpoint(remoteAddress), | 118 | + messagingService.sendAndReceive(CopycatTransport.toEndpoint(remoteAddress), |
124 | outboundMessageSubject, | 119 | outboundMessageSubject, |
125 | baos.toByteArray(), | 120 | baos.toByteArray(), |
126 | context.executor()) | 121 | context.executor()) |
... | @@ -240,17 +235,6 @@ public class CopycatTransportConnection implements Connection { | ... | @@ -240,17 +235,6 @@ public class CopycatTransportConnection implements Connection { |
240 | .toString(); | 235 | .toString(); |
241 | } | 236 | } |
242 | 237 | ||
243 | - private Endpoint toEndpoint(Address address) { | ||
244 | - return endpointLookupCache.computeIfAbsent(address, a -> { | ||
245 | - try { | ||
246 | - return new Endpoint(IpAddress.valueOf(InetAddress.getByName(a.host())), a.port()); | ||
247 | - } catch (UnknownHostException e) { | ||
248 | - Throwables.propagate(e); | ||
249 | - return null; | ||
250 | - } | ||
251 | - }); | ||
252 | - } | ||
253 | - | ||
254 | @SuppressWarnings("rawtypes") | 238 | @SuppressWarnings("rawtypes") |
255 | private final class InternalHandler { | 239 | private final class InternalHandler { |
256 | 240 | ... | ... |
... | @@ -16,13 +16,11 @@ | ... | @@ -16,13 +16,11 @@ |
16 | package org.onosproject.store.primitives.impl; | 16 | package org.onosproject.store.primitives.impl; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | 20 | ||
20 | import java.io.ByteArrayInputStream; | 21 | import java.io.ByteArrayInputStream; |
21 | import java.io.DataInputStream; | 22 | import java.io.DataInputStream; |
22 | import java.io.IOException; | 23 | import java.io.IOException; |
23 | -import java.net.InetAddress; | ||
24 | -import java.net.InetSocketAddress; | ||
25 | -import java.net.UnknownHostException; | ||
26 | import java.util.Map; | 24 | import java.util.Map; |
27 | import java.util.concurrent.CompletableFuture; | 25 | import java.util.concurrent.CompletableFuture; |
28 | import java.util.concurrent.atomic.AtomicBoolean; | 26 | import java.util.concurrent.atomic.AtomicBoolean; |
... | @@ -32,8 +30,8 @@ import org.apache.commons.io.IOUtils; | ... | @@ -32,8 +30,8 @@ import org.apache.commons.io.IOUtils; |
32 | import org.onlab.util.Tools; | 30 | import org.onlab.util.Tools; |
33 | import org.onosproject.cluster.PartitionId; | 31 | import org.onosproject.cluster.PartitionId; |
34 | import org.onosproject.store.cluster.messaging.MessagingService; | 32 | import org.onosproject.store.cluster.messaging.MessagingService; |
33 | +import org.slf4j.Logger; | ||
35 | 34 | ||
36 | -import com.google.common.base.Throwables; | ||
37 | import com.google.common.collect.Maps; | 35 | import com.google.common.collect.Maps; |
38 | 36 | ||
39 | import io.atomix.catalyst.transport.Address; | 37 | import io.atomix.catalyst.transport.Address; |
... | @@ -47,6 +45,7 @@ import io.atomix.catalyst.util.concurrent.ThreadContext; | ... | @@ -47,6 +45,7 @@ import io.atomix.catalyst.util.concurrent.ThreadContext; |
47 | */ | 45 | */ |
48 | public class CopycatTransportServer implements Server { | 46 | public class CopycatTransportServer implements Server { |
49 | 47 | ||
48 | + private final Logger log = getLogger(getClass()); | ||
50 | private final AtomicBoolean listening = new AtomicBoolean(false); | 49 | private final AtomicBoolean listening = new AtomicBoolean(false); |
51 | private CompletableFuture<Void> listenFuture = new CompletableFuture<>(); | 50 | private CompletableFuture<Void> listenFuture = new CompletableFuture<>(); |
52 | private final PartitionId partitionId; | 51 | private final PartitionId partitionId; |
... | @@ -73,28 +72,23 @@ public class CopycatTransportServer implements Server { | ... | @@ -73,28 +72,23 @@ public class CopycatTransportServer implements Server { |
73 | messagingService.registerHandler(messageSubject, (sender, payload) -> { | 72 | messagingService.registerHandler(messageSubject, (sender, payload) -> { |
74 | try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(payload))) { | 73 | try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(payload))) { |
75 | long connectionId = input.readLong(); | 74 | long connectionId = input.readLong(); |
76 | - AtomicBoolean newConnection = new AtomicBoolean(false); | 75 | + AtomicBoolean newConnectionCreated = new AtomicBoolean(false); |
77 | CopycatTransportConnection connection = connections.computeIfAbsent(connectionId, k -> { | 76 | CopycatTransportConnection connection = connections.computeIfAbsent(connectionId, k -> { |
78 | - newConnection.set(true); | 77 | + newConnectionCreated.set(true); |
79 | - try { | 78 | + CopycatTransportConnection newConnection = new CopycatTransportConnection(connectionId, |
80 | - InetAddress senderHost = InetAddress.getByAddress(sender.host().toOctets()); | 79 | + CopycatTransport.Mode.SERVER, |
81 | - int senderPort = sender.port(); | 80 | + partitionId, |
82 | - Address senderAddress = new Address(new InetSocketAddress(senderHost, senderPort)); | 81 | + CopycatTransport.toAddress(sender), |
83 | - return new CopycatTransportConnection(connectionId, | 82 | + messagingService, |
84 | - CopycatTransport.Mode.SERVER, | 83 | + getOrCreateContext(context)); |
85 | - partitionId, | 84 | + log.debug("Created new incoming connection {}", connectionId); |
86 | - senderAddress, | 85 | + newConnection.closeListener(c -> connections.remove(connectionId, c)); |
87 | - messagingService, | 86 | + return newConnection; |
88 | - getOrCreateContext(context)); | ||
89 | - } catch (UnknownHostException e) { | ||
90 | - Throwables.propagate(e); | ||
91 | - return null; | ||
92 | - } | ||
93 | }); | 87 | }); |
94 | byte[] request = IOUtils.toByteArray(input); | 88 | byte[] request = IOUtils.toByteArray(input); |
95 | return CompletableFuture.supplyAsync( | 89 | return CompletableFuture.supplyAsync( |
96 | () -> { | 90 | () -> { |
97 | - if (newConnection.get()) { | 91 | + if (newConnectionCreated.get()) { |
98 | listener.accept(connection); | 92 | listener.accept(connection); |
99 | } | 93 | } |
100 | return connection; | 94 | return connection; | ... | ... |
... | @@ -57,6 +57,7 @@ import com.google.common.collect.Maps; | ... | @@ -57,6 +57,7 @@ import com.google.common.collect.Maps; |
57 | public class PartitionManager extends AbstractListenerManager<PartitionEvent, PartitionEventListener> | 57 | public class PartitionManager extends AbstractListenerManager<PartitionEvent, PartitionEventListener> |
58 | implements PartitionService, PartitionAdminService { | 58 | implements PartitionService, PartitionAdminService { |
59 | 59 | ||
60 | + public static final String HELLO_MESSAGE_SUBJECT = "partition-manager-hello"; | ||
60 | private final Logger log = getLogger(getClass()); | 61 | private final Logger log = getLogger(getClass()); |
61 | 62 | ||
62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 63 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -72,6 +73,8 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa | ... | @@ -72,6 +73,8 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa |
72 | 73 | ||
73 | @Activate | 74 | @Activate |
74 | public void activate() { | 75 | public void activate() { |
76 | + messagingService.registerHandler(HELLO_MESSAGE_SUBJECT, | ||
77 | + (ep, input) -> CompletableFuture.completedFuture(input)); | ||
75 | eventDispatcher.addSink(PartitionEvent.class, listenerRegistry); | 78 | eventDispatcher.addSink(PartitionEvent.class, listenerRegistry); |
76 | 79 | ||
77 | metadataService.getClusterMetadata() | 80 | metadataService.getClusterMetadata() |
... | @@ -92,6 +95,7 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa | ... | @@ -92,6 +95,7 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa |
92 | } | 95 | } |
93 | 96 | ||
94 | public void deactivate() { | 97 | public void deactivate() { |
98 | + messagingService.unregisterHandler(HELLO_MESSAGE_SUBJECT); | ||
95 | eventDispatcher.removeSink(PartitionEvent.class); | 99 | eventDispatcher.removeSink(PartitionEvent.class); |
96 | 100 | ||
97 | CompletableFuture<Void> closeFuture = CompletableFuture.allOf(partitions.values() | 101 | CompletableFuture<Void> closeFuture = CompletableFuture.allOf(partitions.values() |
... | @@ -151,4 +155,4 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa | ... | @@ -151,4 +155,4 @@ public class PartitionManager extends AbstractListenerManager<PartitionEvent, Pa |
151 | .map(Optional::get) | 155 | .map(Optional::get) |
152 | .collect(Collectors.toList()); | 156 | .collect(Collectors.toList()); |
153 | } | 157 | } |
154 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
158 | +} | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.primitives.impl; | 16 | package org.onosproject.store.primitives.impl; |
17 | 17 | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
18 | import io.atomix.Atomix; | 19 | import io.atomix.Atomix; |
19 | import io.atomix.AtomixClient; | 20 | import io.atomix.AtomixClient; |
20 | import io.atomix.catalyst.transport.Transport; | 21 | import io.atomix.catalyst.transport.Transport; |
... | @@ -38,6 +39,7 @@ import org.onosproject.store.service.AsyncDistributedSet; | ... | @@ -38,6 +39,7 @@ import org.onosproject.store.service.AsyncDistributedSet; |
38 | import org.onosproject.store.service.AsyncLeaderElector; | 39 | import org.onosproject.store.service.AsyncLeaderElector; |
39 | import org.onosproject.store.service.DistributedQueue; | 40 | import org.onosproject.store.service.DistributedQueue; |
40 | import org.onosproject.store.service.Serializer; | 41 | import org.onosproject.store.service.Serializer; |
42 | +import org.slf4j.Logger; | ||
41 | 43 | ||
42 | import com.google.common.base.Supplier; | 44 | import com.google.common.base.Supplier; |
43 | import com.google.common.base.Suppliers; | 45 | import com.google.common.base.Suppliers; |
... | @@ -48,6 +50,8 @@ import com.google.common.collect.ImmutableSet; | ... | @@ -48,6 +50,8 @@ import com.google.common.collect.ImmutableSet; |
48 | */ | 50 | */ |
49 | public class StoragePartitionClient implements DistributedPrimitiveCreator, Managed<StoragePartitionClient> { | 51 | public class StoragePartitionClient implements DistributedPrimitiveCreator, Managed<StoragePartitionClient> { |
50 | 52 | ||
53 | + private final Logger log = getLogger(getClass()); | ||
54 | + | ||
51 | private final StoragePartition partition; | 55 | private final StoragePartition partition; |
52 | private final Transport transport; | 56 | private final Transport transport; |
53 | private final io.atomix.catalyst.serializer.Serializer serializer; | 57 | private final io.atomix.catalyst.serializer.Serializer serializer; |
... | @@ -82,7 +86,13 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -82,7 +86,13 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
82 | .withTransport(transport) | 86 | .withTransport(transport) |
83 | .build(); | 87 | .build(); |
84 | } | 88 | } |
85 | - return client.open().thenApply(v -> null); | 89 | + return client.open().whenComplete((r, e) -> { |
90 | + if (e == null) { | ||
91 | + log.info("Successfully started client for partition {}", partition.getId()); | ||
92 | + } else { | ||
93 | + log.info("Failed to start client for partition {}", partition.getId(), e); | ||
94 | + } | ||
95 | + }).thenApply(v -> null); | ||
86 | } | 96 | } |
87 | 97 | ||
88 | @Override | 98 | @Override |
... | @@ -156,4 +166,4 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana | ... | @@ -156,4 +166,4 @@ public class StoragePartitionClient implements DistributedPrimitiveCreator, Mana |
156 | public boolean isClosed() { | 166 | public boolean isClosed() { |
157 | return client.isClosed(); | 167 | return client.isClosed(); |
158 | } | 168 | } |
159 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
169 | +} | ... | ... |
-
Please register or login to post a comment