This is an automated email from the ASF dual-hosted git repository. mmiller pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push: new 82fb30d Use ServerContext in LargestFirstMemoryManager 82fb30d is described below commit 82fb30d089886c944c473def83075e4405050eab Author: Mike Miller <mmil...@apache.org> AuthorDate: Fri Jul 17 10:47:39 2020 -0400 Use ServerContext in LargestFirstMemoryManager * Removal of Memorymanager interface and user property allowed use of serverContext instead of ServerConfFactory --- .../tabletserver/LargestFirstMemoryManager.java | 16 ++--- .../tserver/TabletServerResourceManager.java | 2 +- .../tserver/LargestFirstMemoryManagerTest.java | 71 +++++----------------- 3 files changed, 25 insertions(+), 64 deletions(-) diff --git a/server/base/src/main/java/org/apache/accumulo/server/tabletserver/LargestFirstMemoryManager.java b/server/base/src/main/java/org/apache/accumulo/server/tabletserver/LargestFirstMemoryManager.java index 7e8990c..a41ca6b 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/tabletserver/LargestFirstMemoryManager.java +++ b/server/base/src/main/java/org/apache/accumulo/server/tabletserver/LargestFirstMemoryManager.java @@ -28,7 +28,7 @@ import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.dataImpl.KeyExtent; -import org.apache.accumulo.server.conf.ServerConfiguration; +import org.apache.accumulo.server.ServerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +55,7 @@ public class LargestFirstMemoryManager { private double compactionThreshold; private long maxObserved; private final HashMap<TableId,Long> mincIdleThresholds = new HashMap<>(); - private ServerConfiguration config = null; + private ServerContext context = null; private static class TabletInfo { final KeyExtent extent; @@ -121,10 +121,10 @@ public class LargestFirstMemoryManager { } } - public void init(ServerConfiguration conf) { - this.config = conf; - maxMemory = conf.getSystemConfiguration().getAsBytes(Property.TSERV_MAXMEM); - maxConcurrentMincs = conf.getSystemConfiguration().getCount(Property.TSERV_MINC_MAXCONCURRENT); + public void init(ServerContext context) { + this.context = context; + maxMemory = context.getConfiguration().getAsBytes(Property.TSERV_MAXMEM); + maxConcurrentMincs = context.getConfiguration().getCount(Property.TSERV_MINC_MAXCONCURRENT); numWaitingMultiplier = TSERV_MINC_MAXCONCURRENT_NUMWAITING_MULTIPLIER; } @@ -137,14 +137,14 @@ public class LargestFirstMemoryManager { protected long getMinCIdleThreshold(KeyExtent extent) { TableId tableId = extent.getTableId(); if (!mincIdleThresholds.containsKey(tableId)) - mincIdleThresholds.put(tableId, config.getTableConfiguration(tableId) + mincIdleThresholds.put(tableId, context.getTableConfiguration(tableId) .getTimeInMillis(Property.TABLE_MINC_COMPACT_IDLETIME)); return mincIdleThresholds.get(tableId); } protected boolean tableExists(TableId tableId) { // make sure that the table still exists by checking if it has a configuration - return config.getTableConfiguration(tableId) != null; + return context.getTableConfiguration(tableId) != null; } public MemoryManagementActions getMemoryManagementActions(List<TabletState> tablets) { diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java index 4c68cd2..7b73ae4 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServerResourceManager.java @@ -409,7 +409,7 @@ public class TabletServerResourceManager { fileManager = new FileManager(context, context.getVolumeManager(), maxOpenFiles, fileLenCache); memoryManager = new LargestFirstMemoryManager(); - memoryManager.init(context.getServerConfFactory()); + memoryManager.init(context); memMgmt = new MemoryManagementFramework(); memMgmt.startThreads(); diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/LargestFirstMemoryManagerTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/LargestFirstMemoryManagerTest.java index b5918df..ad6b2d0 100644 --- a/server/tserver/src/test/java/org/apache/accumulo/tserver/LargestFirstMemoryManagerTest.java +++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/LargestFirstMemoryManagerTest.java @@ -18,6 +18,9 @@ */ package org.apache.accumulo.tserver; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; import static org.junit.Assert.assertEquals; import java.util.Arrays; @@ -25,22 +28,14 @@ import java.util.List; import java.util.function.Function; import org.apache.accumulo.core.conf.AccumuloConfiguration; -import org.apache.accumulo.core.conf.ConfigurationCopy; -import org.apache.accumulo.core.conf.DefaultConfiguration; import org.apache.accumulo.core.conf.Property; -import org.apache.accumulo.core.data.NamespaceId; import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.dataImpl.KeyExtent; import org.apache.accumulo.server.ServerContext; -import org.apache.accumulo.server.conf.NamespaceConfiguration; -import org.apache.accumulo.server.conf.ServerConfiguration; -import org.apache.accumulo.server.conf.ServerConfigurationFactory; -import org.apache.accumulo.server.conf.TableConfiguration; import org.apache.accumulo.server.tabletserver.LargestFirstMemoryManager; import org.apache.accumulo.server.tabletserver.MemoryManagementActions; import org.apache.accumulo.server.tabletserver.TabletState; import org.apache.hadoop.io.Text; -import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; @@ -57,34 +52,18 @@ public class LargestFirstMemoryManagerTest { @Before public void mockServerInfo() { - context = EasyMock.createMock(ServerContext.class); + context = createMock(ServerContext.class); + AccumuloConfiguration conf = createMock(AccumuloConfiguration.class); + expect(context.getConfiguration()).andReturn(conf).anyTimes(); + expect(conf.getAsBytes(Property.TSERV_MAXMEM)).andReturn(ONE_GIG).anyTimes(); + expect(conf.getCount(Property.TSERV_MINC_MAXCONCURRENT)).andReturn(4).anyTimes(); + replay(context, conf); } @Test public void test() { LargestFirstMemoryManagerUnderTest mgr = new LargestFirstMemoryManagerUnderTest(); - ServerConfiguration config = new ServerConfiguration() { - ServerConfigurationFactory delegate = context.getServerConfFactory(); - - @Override - public AccumuloConfiguration getSystemConfiguration() { - ConfigurationCopy conf = new ConfigurationCopy(DefaultConfiguration.getInstance()); - conf.set(Property.TSERV_MAXMEM, "1g"); - return conf; - } - - @Override - public TableConfiguration getTableConfiguration(TableId tableId) { - return delegate.getTableConfiguration(tableId); - } - - @Override - public NamespaceConfiguration getNamespaceConfiguration(NamespaceId namespaceId) { - return delegate.getNamespaceConfiguration(namespaceId); - } - - }; - mgr.init(config); + mgr.init(context); MemoryManagementActions result; // nothing to do result = @@ -108,7 +87,7 @@ public class LargestFirstMemoryManagerTest { assertEquals(k("y"), result.tabletsToMinorCompact.get(0)); // lots of work to do mgr = new LargestFirstMemoryManagerUnderTest(); - mgr.init(config); + mgr.init(context); result = mgr.getMemoryManagementActions(tablets(t(k("a"), ZERO, HALF_GIG, 0), t(k("b"), ZERO, HALF_GIG + 1, 0), t(k("c"), ZERO, HALF_GIG + 2, 0), t(k("d"), ZERO, HALF_GIG + 3, 0), t(k("e"), ZERO, HALF_GIG + 4, 0), @@ -119,7 +98,7 @@ public class LargestFirstMemoryManagerTest { assertEquals(k("h"), result.tabletsToMinorCompact.get(1)); // one finished, one in progress, one filled up mgr = new LargestFirstMemoryManagerUnderTest(); - mgr.init(config); + mgr.init(context); result = mgr.getMemoryManagementActions( tablets(t(k("a"), ZERO, HALF_GIG, 0), t(k("b"), ZERO, HALF_GIG + 1, 0), t(k("c"), ZERO, HALF_GIG + 2, 0), t(k("d"), ZERO, HALF_GIG + 3, 0), @@ -154,7 +133,7 @@ public class LargestFirstMemoryManagerTest { // many are running: do nothing mgr = new LargestFirstMemoryManagerUnderTest(); - mgr.init(config); + mgr.init(context); result = mgr.getMemoryManagementActions(tablets(t(k("a"), ZERO, HALF_GIG, 0), t(k("b"), ZERO, HALF_GIG + 1, 0), t(k("c"), ZERO, HALF_GIG + 2, 0), t(k("d"), ZERO, 0, HALF_GIG), t(k("e"), ZERO, 0, HALF_GIG), t(k("f"), ZERO, 0, HALF_GIG), @@ -164,7 +143,7 @@ public class LargestFirstMemoryManagerTest { // observe adjustment: mgr = new LargestFirstMemoryManagerUnderTest(); - mgr.init(config); + mgr.init(context); // compact the largest result = mgr.getMemoryManagementActions(tablets(t(k("a"), ZERO, QGIG, 0), t(k("b"), ZERO, QGIG + 1, 0), t(k("c"), ZERO, QGIG + 2, 0))); @@ -199,26 +178,8 @@ public class LargestFirstMemoryManagerTest { tableId -> !deletedTableId.contentEquals(tableId.canonical()); LargestFirstMemoryManagerWithExistenceCheck mgr = new LargestFirstMemoryManagerWithExistenceCheck(existenceCheck); - ServerConfiguration config = new ServerConfiguration() { - ServerConfigurationFactory delegate = context.getServerConfFactory(); - - @Override - public AccumuloConfiguration getSystemConfiguration() { - return DefaultConfiguration.getInstance(); - } - - @Override - public TableConfiguration getTableConfiguration(TableId tableId) { - return delegate.getTableConfiguration(tableId); - } - - @Override - public NamespaceConfiguration getNamespaceConfiguration(NamespaceId namespaceId) { - return delegate.getNamespaceConfiguration(namespaceId); - } - - }; - mgr.init(config); + + mgr.init(context); MemoryManagementActions result; // one tablet is really big and the other is for a nonexistent table KeyExtent extent = new KeyExtent(TableId.of("2"), new Text("j"), null);