Bug 6361: Make LispSouthboundHandler stateless 73/46973/4
authorLorand Jakab <lojakab@cisco.com>
Fri, 14 Oct 2016 22:36:38 +0000 (01:36 +0300)
committerLorand Jakab <lojakab@cisco.com>
Mon, 17 Oct 2016 19:59:42 +0000 (22:59 +0300)
This fixes the performance regression that's currently visible in our
graphs, for both types of Map-Registers.

Change-Id: I402a71d76f2f391fb46a31dd86b091dc35ad879c
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
Signed-off-by: Miroslav Toth <mirtoth@cisco.com>
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundHandler.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundServiceTest.java

index 8dfc1a3fb1e4e9c0c13a0554076ff9999ba715ed..538e0f37ddef747a26b3c9d6c9ef6b1fa5e3d579 100644 (file)
@@ -34,9 +34,14 @@ import java.nio.ByteBuffer;
 import java.util.concurrent.ThreadFactory;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
+import org.opendaylight.lispflowmapping.inmemorydb.HashMapDb;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
+import org.opendaylight.lispflowmapping.mapcache.SimpleMapCache;
+import org.opendaylight.lispflowmapping.southbound.lisp.AuthenticationKeyDataListener;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispXtrSouthboundHandler;
+import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
 import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
@@ -54,6 +59,8 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
             LISPFLOWMAPPING_ENTITY_NAME);
 
     private volatile String bindingAddress;
+    private SimpleMapCache smc;
+    private MapRegisterCache mapRegisterCache = new MapRegisterCache();
     private boolean mapRegisterCacheEnabled;
     private long mapRegisterCacheTimeout;
 
@@ -73,6 +80,8 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     private ThreadFactory threadFactory = new DefaultThreadFactory("lisp-sb");
     private EventLoopGroup eventLoopGroup;
     private DataBroker dataBroker;
+    private AuthenticationKeyDataListener authenticationKeyDataListener;
+    private DataStoreBackEnd dsbe;
 
     public LispSouthboundPlugin(final DataBroker dataBroker,
             final NotificationPublishService notificationPublishService,
@@ -86,16 +95,23 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     public void init() {
         LOG.info("LISP (RFC6830) Southbound Plugin is initializing...");
         synchronized (startLock) {
+            this.smc = new SimpleMapCache(new HashMapDb());
+            this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, smc);
+            this.dsbe = new DataStoreBackEnd(dataBroker);
+
             lispSouthboundHandler = new LispSouthboundHandler(this);
             lispSouthboundHandler.setDataBroker(dataBroker);
-            lispSouthboundHandler.setNotificationProvider(this.notificationPublishService);
-            lispSouthboundHandler.setMapRegisterCacheEnabled(mapRegisterCacheEnabled);
+            lispSouthboundHandler.setNotificationProvider(notificationPublishService);
+            lispSouthboundHandler.setSimpleMapCache(smc);
+            lispSouthboundHandler.setMapRegisterCache(mapRegisterCache);
             lispSouthboundHandler.setMapRegisterCacheTimeout(mapRegisterCacheTimeout);
-            lispSouthboundHandler.init();
+            lispSouthboundHandler.setAuthenticationKeyDataListener(authenticationKeyDataListener);
+            lispSouthboundHandler.setDataStoreBackEnd(dsbe);
+            lispSouthboundHandler.setStats(statistics);
             lispSouthboundHandler.restoreDaoFromDatastore();
 
             lispXtrSouthboundHandler = new LispXtrSouthboundHandler();
-            lispXtrSouthboundHandler.setNotificationProvider(this.notificationPublishService);
+            lispXtrSouthboundHandler.setNotificationProvider(notificationPublishService);
 
             if (Epoll.isAvailable()) {
                 eventLoopGroup = new EpollEventLoopGroup(0, threadFactory);
@@ -332,4 +348,15 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
         return SERVICE_GROUP_IDENTIFIER;
     }
 
+    public MapRegisterCache getMapRegisterCache() {
+        return mapRegisterCache;
+    }
+
+    public boolean isMapRegisterCacheEnabled() {
+        return mapRegisterCacheEnabled;
+    }
+
+    public long getMapRegisterCacheTimeout() {
+        return mapRegisterCacheTimeout;
+    }
 }
index 2261b43149759cb70950684b7d879c47c97fc65c..8e7b49acbe7ecae00f5682cc5246d445ede26a2c 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.lispflowmapping.southbound.lisp;
 
-import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
@@ -24,7 +23,6 @@ import java.util.Objects;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
-import org.opendaylight.lispflowmapping.inmemorydb.HashMapDb;
 import org.opendaylight.lispflowmapping.lisp.authentication.ILispAuthentication;
 import org.opendaylight.lispflowmapping.lisp.authentication.LispAuthenticationUtil;
 import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
@@ -76,7 +74,6 @@ import org.slf4j.LoggerFactory;
 public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramPacket>
         implements ILispSouthboundService, AutoCloseable {
     private MapRegisterCache mapRegisterCache;
-    private boolean mapRegisterCacheEnabled = true;
     private long mapRegisterCacheTimeout;
 
     private DataBroker dataBroker;
@@ -95,11 +92,6 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
 
     public LispSouthboundHandler(LispSouthboundPlugin lispSbPlugin) {
         this.lispSbPlugin = lispSbPlugin;
-        if (lispSbPlugin != null) {
-            this.lispSbStats = lispSbPlugin.getStats();
-        }
-        this.mapRegisterCache = new MapRegisterCache();
-        this.smc = new SimpleMapCache(new HashMapDb());
     }
 
     public void handlePacket(DatagramPacket msg) {
@@ -196,7 +188,7 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
             Map.Entry<MapRegisterCacheKey, byte[]> artificialEntry = null;
             MapRegisterCacheKey cacheKey = null;
             MapRegisterCacheValue cacheValue = null;
-            if (mapRegisterCacheEnabled) {
+            if (lispSbPlugin.isMapRegisterCacheEnabled()) {
                 artificialEntry = MapRegisterPartialDeserializer.deserializePartially(inBuffer, sourceAddress);
                 cacheKey = artificialEntry == null ? null : artificialEntry.getKey();
                 cacheValue = resolveCacheValue(artificialEntry);
@@ -517,7 +509,6 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
 
     @Override
     public void close() throws Exception {
-        authenticationKeyDataListener.closeDataChangeListener();
     }
 
     public void setSimpleMapCache(final SimpleMapCache smc) {
@@ -536,8 +527,16 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
         this.mapRegisterCache = mapRegisterCache;
     }
 
-    public void setMapRegisterCacheEnabled(final boolean mapRegisterCacheEnabled) {
-        this.mapRegisterCacheEnabled = mapRegisterCacheEnabled;
+    public void setAuthenticationKeyDataListener(AuthenticationKeyDataListener authenticationKeyDataListener) {
+        this.authenticationKeyDataListener = authenticationKeyDataListener;
+    }
+
+    public void setDataStoreBackEnd(DataStoreBackEnd dsbe) {
+        this.dsbe = dsbe;
+    }
+
+    public void setStats(LispSouthboundStats lispSbStats) {
+        this.lispSbStats = lispSbStats;
     }
 
     /**
@@ -557,13 +556,6 @@ public class LispSouthboundHandler extends SimpleChannelInboundHandler<DatagramP
         }
     }
 
-    public void init() {
-        Preconditions.checkNotNull(dataBroker);
-        Preconditions.checkNotNull(smc);
-        this.authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBroker, smc);
-        dsbe = new DataStoreBackEnd(dataBroker);
-    }
-
     public void setIsMaster(boolean isReadFromChannelEnabled) {
         this.isReadFromChannelEnabled = isReadFromChannelEnabled;
     }
index 031e306ab471ffadffa9db4eb36da0acd9e036c8..a11063920913a413eec7ee6f42f8b5541d14d050 100644 (file)
@@ -42,6 +42,7 @@ import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
 import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
@@ -98,6 +99,7 @@ public class LispSouthboundServiceTest extends BaseTestCase {
     private MappingRecordBuilder mappingRecordBuilder;
     private MapRegisterCache mapRegisterCache;
     private LispSouthboundPlugin mockLispSouthboundPlugin;
+    private LispSouthboundStats lispSouthboundStats;
     private static final long CACHE_RECORD_TIMEOUT = 90000;
 
     private static SimpleMapCache smc;
@@ -151,15 +153,19 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         // mapServer = context.mock(IMapServer.class);
         mockLispSouthboundPlugin = mock(LispSouthboundPlugin.class);
         Mockito.when(mockLispSouthboundPlugin.getStats()).thenReturn(Mockito.mock(LispSouthboundStats.class));
+        Mockito.when(mockLispSouthboundPlugin.isMapRegisterCacheEnabled()).thenReturn(true);
         testedLispService = new LispSouthboundHandler(mockLispSouthboundPlugin);
         testedLispService.setMapRegisterCacheTimeout(90000);
         mapRegisterCache = new MapRegisterCache();
         testedLispService.setMapRegisterCache(mapRegisterCache);
         testedLispService.setDataBroker(Mockito.mock(DataBroker.class));
         testedLispService.setSimpleMapCache(smc);
-        testedLispService.init();
+        testedLispService.setAuthenticationKeyDataListener(Mockito.mock(AuthenticationKeyDataListener.class));
+        testedLispService.setDataStoreBackEnd(Mockito.mock(DataStoreBackEnd.class));
         nps = context.mock(NotificationPublishService.class);
         testedLispService.setNotificationProvider(nps);
+        lispSouthboundStats = new LispSouthboundStats();
+        testedLispService.setStats(lispSouthboundStats);
         lispNotificationSaver = new ValueSaverAction<Notification>();
         // mapRegisterSaver = new ValueSaverAction<MapRegister>();
         // mapRequestSaver = new ValueSaverAction<MapRequest>();