ACCUMULO-4681 Created Table & Namespace WeakReference cache
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/cc1cf734 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/cc1cf734 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/cc1cf734 Branch: refs/heads/master Commit: cc1cf734bd616d72533db41fa0a3a0a721f53ed3 Parents: 4014116 Author: Mike Miller <[email protected]> Authored: Thu Aug 17 09:57:10 2017 -0400 Committer: Mike Miller <[email protected]> Committed: Thu Aug 17 09:57:10 2017 -0400 ---------------------------------------------------------------------- .../core/client/MutationsRejectedException.java | 2 +- .../core/client/TableOfflineException.java | 2 +- .../core/client/impl/ActiveScanImpl.java | 2 +- .../accumulo/core/client/impl/Namespace.java | 37 ++++++-- .../accumulo/core/client/impl/Namespaces.java | 6 +- .../core/client/impl/OfflineIterator.java | 2 +- .../client/impl/ReplicationOperationsImpl.java | 2 +- .../apache/accumulo/core/client/impl/Table.java | 33 ++++++- .../accumulo/core/client/impl/Tables.java | 10 +-- .../core/client/mapred/AbstractInputFormat.java | 4 +- .../client/mapreduce/AbstractInputFormat.java | 4 +- .../client/mock/impl/MockTabletLocator.java | 2 +- .../accumulo/core/data/impl/KeyExtent.java | 42 +++------ .../core/metadata/MetadataServicer.java | 2 +- .../core/metadata/schema/MetadataSchema.java | 2 +- .../core/replication/ReplicationSchema.java | 2 +- .../core/replication/ReplicationTable.java | 2 +- .../core/replication/ReplicationTarget.java | 2 +- .../apache/accumulo/core/summary/Gatherer.java | 2 +- .../accumulo/core/util/ByteBufferUtil.java | 2 +- .../core/client/impl/NamespaceTest.java | 87 +++++++++++++++++++ .../core/client/impl/ScannerImplTest.java | 8 +- .../client/impl/TableOperationsImplTest.java | 2 +- .../accumulo/core/client/impl/TableTest.java | 91 ++++++++++++++++++++ .../core/client/impl/TabletLocatorImplTest.java | 18 ++-- .../impl/TabletServerBatchReaderTest.java | 4 +- .../mapreduce/impl/BatchInputSplitTest.java | 4 +- .../accumulo/core/data/KeyExtentTest.java | 2 +- .../apache/accumulo/core/data/RangeTest.java | 20 ++--- .../core/iterators/IteratorUtilTest.java | 10 +-- .../iterators/system/MultiIteratorTest.java | 2 +- .../core/metadata/MetadataServicerTest.java | 2 +- .../ReplicationConfigurationUtilTest.java | 4 +- .../core/replication/ReplicationSchemaTest.java | 4 +- .../core/replication/ReplicationTargetTest.java | 20 ++--- .../apache/accumulo/core/util/MergeTest.java | 2 +- .../accumulo/server/client/BulkImporter.java | 2 +- .../server/conf/NamespaceConfWatcher.java | 2 +- .../accumulo/server/conf/TableConfWatcher.java | 2 +- .../accumulo/server/fs/VolumeManagerImpl.java | 2 +- .../master/balancer/ChaoticLoadBalancer.java | 2 +- .../master/balancer/DefaultLoadBalancer.java | 4 +- .../server/master/balancer/GroupBalancer.java | 2 +- .../balancer/HostRegexTableLoadBalancer.java | 6 +- .../master/balancer/RegexGroupBalancer.java | 4 +- .../master/balancer/TableLoadBalancer.java | 2 +- .../accumulo/server/problems/ProblemReport.java | 4 +- .../DistributedWorkQueueWorkAssignerHelper.java | 2 +- .../accumulo/server/tables/TableManager.java | 4 +- .../accumulo/server/util/MetadataTableUtil.java | 8 +- .../accumulo/server/util/RandomizeVolumes.java | 4 +- .../accumulo/server/util/TableDiskUsage.java | 2 +- .../server/client/BulkImporterTest.java | 10 +-- .../server/conf/NamespaceConfigurationTest.java | 2 +- .../conf/ServerConfigurationFactoryTest.java | 2 +- .../server/conf/TableConfigurationTest.java | 2 +- .../server/fs/VolumeManagerImplTest.java | 2 +- .../BaseHostRegexTableLoadBalancerTest.java | 6 +- .../balancer/ChaoticLoadBalancerTest.java | 2 +- .../balancer/DefaultLoadBalancerTest.java | 2 +- .../master/balancer/GroupBalancerTest.java | 2 +- .../master/balancer/TableLoadBalancerTest.java | 6 +- .../server/master/state/MergeInfoTest.java | 24 +++--- .../server/problems/ProblemReportTest.java | 2 +- .../problems/ProblemReportingIteratorTest.java | 2 +- .../server/util/ReplicationTableUtilTest.java | 4 +- .../accumulo/gc/GarbageCollectionAlgorithm.java | 2 +- .../accumulo/gc/SimpleGarbageCollector.java | 2 +- .../accumulo/gc/GarbageCollectionTest.java | 10 +-- .../master/MasterClientServiceHandler.java | 4 +- .../RemoveCompleteReplicationRecords.java | 2 +- .../accumulo/master/tableOps/CloneTable.java | 2 +- .../master/tableOps/CreateNamespace.java | 2 +- .../accumulo/master/tableOps/CreateTable.java | 2 +- .../accumulo/master/tableOps/ImportTable.java | 2 +- .../apache/accumulo/master/tableOps/Utils.java | 24 ++---- ...tributedWorkQueueWorkAssignerHelperTest.java | 4 +- .../replication/SequentialWorkAssignerTest.java | 10 +-- .../replication/UnorderedWorkAssignerTest.java | 2 +- .../master/state/RootTabletStateStoreTest.java | 2 +- .../master/tableOps/ImportTableTest.java | 2 +- .../monitor/rest/problems/ProblemsResource.java | 4 +- .../monitor/rest/tables/TablesResource.java | 4 +- .../apache/accumulo/monitor/view/WebViews.java | 2 +- .../apache/accumulo/tserver/TabletServer.java | 22 ++--- .../accumulo/tserver/logger/LogReader.java | 2 +- .../replication/ReplicationServicerHandler.java | 2 +- .../accumulo/tserver/AssignmentWatcherTest.java | 2 +- .../tserver/CheckTabletMetadataTest.java | 6 +- .../tserver/LargestFirstMemoryManagerTest.java | 4 +- .../DefaultCompactionStrategyTest.java | 2 +- .../SizeLimitCompactionStrategyTest.java | 2 +- .../TwoTierCompactionStrategyTest.java | 6 +- .../ConfigurableCompactionStrategyTest.java | 2 +- .../accumulo/tserver/log/LogEntryTest.java | 2 +- .../tserver/log/SortedLogRecoveryTest.java | 2 +- .../accumulo/tserver/logger/LogFileTest.java | 2 +- .../replication/AccumuloReplicaSystemTest.java | 36 ++++---- .../replication/ReplicationProcessorTest.java | 2 +- .../java/org/apache/accumulo/test/CloneIT.java | 52 +++++------ .../org/apache/accumulo/test/FileArchiveIT.java | 6 +- .../apache/accumulo/test/ImportExportIT.java | 2 +- .../org/apache/accumulo/test/LocatorIT.java | 2 +- .../accumulo/test/MetaConstraintRetryIT.java | 2 +- .../MissingWalHeaderCompletesRecoveryIT.java | 4 +- .../test/RewriteTabletDirectoriesIT.java | 2 +- .../java/org/apache/accumulo/test/SampleIT.java | 2 +- .../apache/accumulo/test/SplitRecoveryIT.java | 2 +- .../test/TableConfigurationUpdateIT.java | 2 +- .../apache/accumulo/test/VolumeChooserIT.java | 18 ++-- .../java/org/apache/accumulo/test/VolumeIT.java | 4 +- .../apache/accumulo/test/WrongTabletTest.java | 4 +- .../test/functional/FunctionalTestUtils.java | 2 +- .../test/functional/MasterAssignmentIT.java | 2 +- .../accumulo/test/functional/MergeIT.java | 6 +- .../test/functional/RegexGroupBalanceIT.java | 4 +- .../accumulo/test/functional/SplitIT.java | 2 +- .../test/functional/SplitRecoveryIT.java | 2 +- .../accumulo/test/functional/TableIT.java | 2 +- .../functional/TabletStateChangeIteratorIT.java | 8 +- .../CloseWriteAheadLogReferencesIT.java | 2 +- .../accumulo/test/master/MergeStateIT.java | 4 +- .../metadata/MetadataBatchScanTest.java | 2 +- .../test/replication/FinishedWorkUpdaterIT.java | 14 +-- ...bageCollectorCommunicatesWithTServersIT.java | 2 +- .../RemoveCompleteReplicationRecordsIT.java | 26 +++--- .../test/replication/ReplicationIT.java | 8 +- .../ReplicationOperationsImplIT.java | 12 +-- .../replication/SequentialWorkAssignerIT.java | 12 +-- .../test/replication/StatusCombinerMacIT.java | 4 +- .../replication/UnorderedWorkAssignerIT.java | 10 +-- ...UnusedWalDoesntCloseReplicationStatusIT.java | 4 +- .../accumulo/test/replication/WorkMakerIT.java | 4 +- 133 files changed, 586 insertions(+), 386 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java index 2bb348d..3d26e2d 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java +++ b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java @@ -70,7 +70,7 @@ public class MutationsRejectedException extends AccumuloException { for (Entry<TabletId,Set<SecurityErrorCode>> entry : hashMap.entrySet()) { TabletId tabletId = entry.getKey(); - String tableInfo = Tables.getPrintableTableInfoFromId(instance, new Table.ID(tabletId.getTableId().toString())); + String tableInfo = Tables.getPrintableTableInfoFromId(instance, Table.ID.of(tabletId.getTableId().toString())); if (!result.containsKey(tableInfo)) { result.put(tableInfo, new HashSet<SecurityErrorCode>()); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/TableOfflineException.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/TableOfflineException.java b/core/src/main/java/org/apache/accumulo/core/client/TableOfflineException.java index 2afb69d..2677a56 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/TableOfflineException.java +++ b/core/src/main/java/org/apache/accumulo/core/client/TableOfflineException.java @@ -27,7 +27,7 @@ public class TableOfflineException extends RuntimeException { if (tableId == null) return " <unknown table> "; try { - String tableName = Tables.getTableName(instance, new Table.ID(tableId)); + String tableName = Tables.getTableName(instance, Table.ID.of(tableId)); return tableName + " (" + tableId + ")"; } catch (TableNotFoundException e) { return " <unknown table> (" + tableId + ")"; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java index d962143..2e6a9c1 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java @@ -60,7 +60,7 @@ public class ActiveScanImpl extends ActiveScan { this.user = activeScan.user; this.age = activeScan.age; this.idle = activeScan.idleTime; - this.tableName = Tables.getTableName(instance, new Table.ID(activeScan.tableId)); + this.tableName = Tables.getTableName(instance, Table.ID.of(activeScan.tableId)); this.type = ScanType.valueOf(activeScan.getType().name()); this.state = ScanState.valueOf(activeScan.state.name()); this.extent = new KeyExtent(activeScan.extent); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java index 41f8b05..83edeee 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java @@ -16,27 +16,50 @@ */ package org.apache.accumulo.core.client.impl; +import java.util.concurrent.ExecutionException; + import org.apache.accumulo.core.client.Instance; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + public class Namespace { + public static final String ACCUMULO = "accumulo"; + public static final String DEFAULT = ""; + public static final String SEPARATOR = "."; /** * Object representing an internal Namespace ID. This class was created to help with type safety. For help obtaining the value of a namespace ID from * Zookeeper, see {@link Namespaces#getNamespaceId(Instance, String)} + * + * Uses an internal cache and private constructor for storing a WeakReference of every Namespace.ID. Therefore, a Namespace.ID can't be instantiated outside + * this class and is accessed by calling Namespace.ID.{@link #of(String)}. */ public static class ID extends AbstractId { private static final long serialVersionUID = 8931104141709170293L; + static final Cache<String,ID> cache = CacheBuilder.newBuilder().weakValues().build(); - public static final ID ACCUMULO = new ID("+accumulo"); - public static final ID DEFAULT = new ID("+default"); + public static final ID ACCUMULO = of("+accumulo"); + public static final ID DEFAULT = of("+default"); - public ID(String canonical) { + private ID(String canonical) { super(canonical); } - } - public static final String ACCUMULO = "accumulo"; - public static final String DEFAULT = ""; - public static final String SEPARATOR = "."; + /** + * Get a Namespace.ID object for the provided canonical string. + * + * @param canonical + * Namespace ID string + * @return Namespace.ID object + */ + public static Namespace.ID of(final String canonical) { + try { + return cache.get(canonical, () -> new Namespace.ID(canonical)); + } catch (ExecutionException e) { + throw new AssertionError("This should never happen: ID constructor should never return null."); + } + } + } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java index 17f5c18..2416c5a 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespaces.java @@ -125,7 +125,7 @@ public class Namespaces { */ public static SortedMap<Namespace.ID,String> getIdToNameMap(Instance instance) { SortedMap<Namespace.ID,String> idMap = new TreeMap<>(); - getAllNamespaces(instance, (id, name) -> idMap.put(new Namespace.ID(id), name)); + getAllNamespaces(instance, (id, name) -> idMap.put(Namespace.ID.of(id), name)); return idMap; } @@ -134,7 +134,7 @@ public class Namespaces { */ public static SortedMap<String,Namespace.ID> getNameToIdMap(Instance instance) { SortedMap<String,Namespace.ID> nameMap = new TreeMap<>(); - getAllNamespaces(instance, (id, name) -> nameMap.put(name, new Namespace.ID(id))); + getAllNamespaces(instance, (id, name) -> nameMap.put(name, Namespace.ID.of(id))); return nameMap; } @@ -145,7 +145,7 @@ public class Namespaces { final ArrayList<Namespace.ID> singleId = new ArrayList<>(1); getAllNamespaces(instance, (id, name) -> { if (name.equals(namespaceName)) - singleId.add(new Namespace.ID(id)); + singleId.add(Namespace.ID.of(id)); }); if (singleId.isEmpty()) throw new NamespaceNotFoundException(null, namespaceName, "getNamespaceId() failed to find namespace"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineIterator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineIterator.java b/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineIterator.java index 4d8470b..40095c1 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineIterator.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineIterator.java @@ -162,7 +162,7 @@ class OfflineIterator implements Iterator<Entry<Key,Value>> { this.range = range.bound(this.options.fetchedColumns.first(), this.options.fetchedColumns.last()); } - this.tableId = new Table.ID(table.toString()); + this.tableId = Table.ID.of(table.toString()); this.authorizations = authorizations; this.readers = new ArrayList<>(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/ReplicationOperationsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ReplicationOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ReplicationOperationsImpl.java index 79a2dad..f691f19 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/ReplicationOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ReplicationOperationsImpl.java @@ -132,7 +132,7 @@ public class ReplicationOperationsImpl implements ReplicationOperations { } } - return new Table.ID(tableId); + return Table.ID.of(tableId); } @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java index e20ef01..74d783d 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java @@ -16,24 +16,49 @@ */ package org.apache.accumulo.core.client.impl; +import java.util.concurrent.ExecutionException; + import org.apache.accumulo.core.client.Instance; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + public class Table { /** * Object representing an internal table ID. This class was created to help with type safety. For help obtaining the value of a table ID from Zookeeper, see * {@link Tables#getTableId(Instance, String)} + * + * Uses an internal cache and private constructor for storing a WeakReference of every Table.ID. Therefore, a Table.ID can't be instantiated outside this + * class and is accessed by calling Table.ID.{@link #of(String)}. */ public static class ID extends AbstractId { private static final long serialVersionUID = 7399913185860577809L; + static final Cache<String,ID> cache = CacheBuilder.newBuilder().weakValues().build(); - public static final ID METADATA = new ID("!0"); - public static final ID REPLICATION = new ID("+rep"); - public static final ID ROOT = new ID("+r"); + public static final ID METADATA = of("!0"); + public static final ID REPLICATION = of("+rep"); + public static final ID ROOT = of("+r"); - public ID(final String canonical) { + private ID(final String canonical) { super(canonical); } + + /** + * Get a Table.ID object for the provided canonical string. + * + * @param canonical + * table ID string + * @return Table.ID object + */ + public static ID of(final String canonical) { + try { + return cache.get(canonical, () -> new Table.ID(canonical)); + } catch (ExecutionException e) { + throw new AssertionError("This should never happen: ID constructor should never return null."); + } + } + } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java index 8cf1233..dfdc170 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java @@ -228,7 +228,7 @@ public class Tables { throw new TableNotFoundException(tableId.canonicalID(), null, null); } - return new Namespace.ID(new String(n, UTF_8)); + return Namespace.ID.of(new String(n, UTF_8)); } /** @@ -247,7 +247,7 @@ public class Tables { if (nId == null) { namespaceName = null; } else { - Namespace.ID namespaceId = new Namespace.ID(new String(nId, UTF_8)); + Namespace.ID namespaceId = Namespace.ID.of(new String(nId, UTF_8)); if (!namespaceId.equals(Namespace.ID.DEFAULT)) { try { namespaceName = namespaceIdToNameMap.get(namespaceId); @@ -270,13 +270,13 @@ public class Tables { public static SortedMap<Table.ID,String> getIdToNameMap(Instance instance) { SortedMap<Table.ID,String> map = new TreeMap<>(); - getAllTables(instance, (id, name) -> map.put(new Table.ID(id), name)); + getAllTables(instance, (id, name) -> map.put(Table.ID.of(id), name)); return map; } public static SortedMap<String,Table.ID> getNameToIdMap(Instance instance) { SortedMap<String,Table.ID> map = new TreeMap<>(); - getAllTables(instance, (id, name) -> map.put(name, new Table.ID(id))); + getAllTables(instance, (id, name) -> map.put(name, Table.ID.of(id))); return map; } @@ -287,7 +287,7 @@ public class Tables { ArrayList<Table.ID> singleId = new ArrayList<>(1); getAllTables(instance, (id, name) -> { if (name.equals(tableName)) - singleId.add(new Table.ID(id)); + singleId.add(Table.ID.of(id)); }); if (singleId.isEmpty()) return null; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java index 54aceeb..1b8ac2a 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java @@ -544,13 +544,13 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> { try { if (isOffline) { - scanner = new OfflineScanner(instance, new Credentials(principal, token), new Table.ID(baseSplit.getTableId()), authorizations); + scanner = new OfflineScanner(instance, new Credentials(principal, token), Table.ID.of(baseSplit.getTableId()), authorizations); } else if (DeprecationUtil.isMockInstance(instance)) { scanner = instance.getConnector(principal, token).createScanner(baseSplit.getTableName(), authorizations); } else { ClientConfiguration clientConf = getClientConfiguration(job); ClientContext context = new ClientContext(instance, new Credentials(principal, token), clientConf); - scanner = new ScannerImpl(context, new Table.ID(baseSplit.getTableId()), authorizations); + scanner = new ScannerImpl(context, Table.ID.of(baseSplit.getTableId()), authorizations); } if (isIsolated) { log.info("Creating isolated scanner"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java index 78c94d3..0d89c7a 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java @@ -572,13 +572,13 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> { try { if (isOffline) { - scanner = new OfflineScanner(instance, new Credentials(principal, token), new Table.ID(split.getTableId()), authorizations); + scanner = new OfflineScanner(instance, new Credentials(principal, token), Table.ID.of(split.getTableId()), authorizations); } else if (DeprecationUtil.isMockInstance(instance)) { scanner = instance.getConnector(principal, token).createScanner(split.getTableName(), authorizations); } else { ClientConfiguration clientConf = getClientConfiguration(attempt); ClientContext context = new ClientContext(instance, new Credentials(principal, token), clientConf); - scanner = new ScannerImpl(context, new Table.ID(split.getTableId()), authorizations); + scanner = new ScannerImpl(context, Table.ID.of(split.getTableId()), authorizations); } if (isIsolated) { log.info("Creating isolated scanner"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java index 78f604d..3837f2a 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java @@ -57,7 +57,7 @@ public class MockTabletLocator extends TabletLocator { @Override public List<Range> binRanges(ClientContext context, List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> binnedRanges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - binnedRanges.put("", Collections.singletonMap(new KeyExtent(null, null, null), ranges)); + binnedRanges.put("", Collections.singletonMap(new KeyExtent(), ranges)); return Collections.emptyList(); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java b/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java index e6bc9fd..a8471de 100644 --- a/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java +++ b/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java @@ -23,19 +23,18 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; -import java.lang.ref.WeakReference; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeSet; import java.util.UUID; -import java.util.WeakHashMap; import org.apache.accumulo.core.client.impl.Table; import org.apache.accumulo.core.data.ByteSequence; @@ -60,28 +59,11 @@ import org.apache.hadoop.io.WritableComparable; public class KeyExtent implements WritableComparable<KeyExtent> { - private static final WeakHashMap<Table.ID,WeakReference<Table.ID>> tableIds = new WeakHashMap<>(); - - private static Table.ID dedupeTableId(Table.ID tableId) { - synchronized (tableIds) { - WeakReference<Table.ID> etir = tableIds.get(tableId); - if (etir != null) { - Table.ID eti = etir.get(); - if (eti != null) { - return eti; - } - } - - tableIds.put(tableId, new WeakReference<>(tableId)); - return tableId; - } - } - private Table.ID tableId; private Text textEndRow; private Text textPrevEndRow; - private final Table.ID EMPTY_ID = new Table.ID(""); + private static final Table.ID EMPTY_ID = Table.ID.of(""); private void check() { @@ -124,7 +106,7 @@ public class KeyExtent implements WritableComparable<KeyExtent> { } public KeyExtent(TKeyExtent tke) { - this.setTableId(dedupeTableId(new Table.ID(new String(ByteBufferUtil.toBytes(tke.table), UTF_8)))); + this.setTableId(Table.ID.of(new String(ByteBufferUtil.toBytes(tke.table), UTF_8))); this.setEndRow(tke.endRow == null ? null : new Text(ByteBufferUtil.toBytes(tke.endRow)), false, false); this.setPrevEndRow(tke.prevEndRow == null ? null : new Text(ByteBufferUtil.toBytes(tke.prevEndRow)), false, false); @@ -171,11 +153,9 @@ public class KeyExtent implements WritableComparable<KeyExtent> { * */ public void setTableId(Table.ID tId) { + Objects.requireNonNull(tId, "null table id not allowed"); - if (tId == null) - throw new IllegalArgumentException("null table name not allowed"); - - this.tableId = dedupeTableId(tId); + this.tableId = tId; hashCode = 0; } @@ -252,7 +232,7 @@ public class KeyExtent implements WritableComparable<KeyExtent> { public void readFields(DataInput in) throws IOException { Text tid = new Text(); tid.readFields(in); - setTableId(new Table.ID(tid.toString())); + setTableId(Table.ID.of(tid.toString())); boolean hasRow = in.readBoolean(); if (hasRow) { Text er = new Text(); @@ -267,7 +247,7 @@ public class KeyExtent implements WritableComparable<KeyExtent> { per.readFields(in); setPrevEndRow(per, false, true); } else { - setPrevEndRow((Text) null); + setPrevEndRow(null); } hashCode = 0; @@ -533,12 +513,12 @@ public class KeyExtent implements WritableComparable<KeyExtent> { } String decodedString = new String(Arrays.copyOfRange(flattenedExtent.getBytes(), 0, flattenedExtent.getLength() - 1), UTF_8); - Table.ID tableId = new Table.ID(decodedString); + Table.ID tableId = Table.ID.of(decodedString); this.setTableId(tableId); this.setEndRow(null, false, false); } else { - Table.ID tableId = new Table.ID(new String(Arrays.copyOfRange(flattenedExtent.getBytes(), 0, semiPos), UTF_8)); + Table.ID tableId = Table.ID.of(new String(Arrays.copyOfRange(flattenedExtent.getBytes(), 0, semiPos), UTF_8)); Text endRow = new Text(); endRow.set(flattenedExtent.getBytes(), semiPos + 1, flattenedExtent.getLength() - (semiPos + 1)); @@ -635,7 +615,7 @@ public class KeyExtent implements WritableComparable<KeyExtent> { public static KeyExtent findContainingExtent(KeyExtent extent, SortedSet<KeyExtent> extents) { KeyExtent lookupExtent = new KeyExtent(extent); - lookupExtent.setPrevEndRow((Text) null); + lookupExtent.setPrevEndRow(null); SortedSet<KeyExtent> tailSet = extents.tailSet(lookupExtent); @@ -752,7 +732,7 @@ public class KeyExtent implements WritableComparable<KeyExtent> { return getPrevEndRow() == null; if (!prevExtent.getTableId().equals(getTableId())) - throw new IllegalArgumentException("Cannot compare accross tables " + prevExtent + " " + this); + throw new IllegalArgumentException("Cannot compare across tables " + prevExtent + " " + this); if (prevExtent.getEndRow() == null) return false; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/metadata/MetadataServicer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/metadata/MetadataServicer.java b/core/src/main/java/org/apache/accumulo/core/metadata/MetadataServicer.java index 7eae639..a315d59 100644 --- a/core/src/main/java/org/apache/accumulo/core/metadata/MetadataServicer.java +++ b/core/src/main/java/org/apache/accumulo/core/metadata/MetadataServicer.java @@ -34,7 +34,7 @@ public abstract class MetadataServicer { public static MetadataServicer forTableName(ClientContext context, String tableName) throws AccumuloException, AccumuloSecurityException { checkArgument(tableName != null, "tableName is null"); - return forTableId(context, new Table.ID(context.getConnector().tableOperations().tableIdMap().get(tableName))); + return forTableId(context, Table.ID.of(context.getConnector().tableOperations().tableIdMap().get(tableName))); } public static MetadataServicer forTableId(ClientContext context, Table.ID tableId) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java b/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java index cf00164..8c76e52 100644 --- a/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java +++ b/core/src/main/java/org/apache/accumulo/core/metadata/schema/MetadataSchema.java @@ -262,7 +262,7 @@ public class MetadataSchema { */ public static Table.ID getTableId(Key k) { requireNonNull(k); - return new Table.ID(k.getColumnQualifier().toString()); + return Table.ID.of(k.getColumnQualifier().toString()); } /** http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/replication/ReplicationSchema.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationSchema.java b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationSchema.java index 5c6a83d..28d089d 100644 --- a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationSchema.java +++ b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationSchema.java @@ -99,7 +99,7 @@ public class ReplicationSchema { */ public static Table.ID getTableId(Key k) { requireNonNull(k); - return new Table.ID(k.getColumnQualifier().toString()); + return Table.ID.of(k.getColumnQualifier().toString()); } /** http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java index b5ad84b..c1a87c7 100644 --- a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java +++ b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java @@ -46,7 +46,7 @@ import com.google.common.collect.ImmutableMap; public class ReplicationTable { private static final Logger log = LoggerFactory.getLogger(ReplicationTable.class); - public static final Table.ID ID = new Table.ID("+rep"); + public static final Table.ID ID = Table.ID.of("+rep"); public static final String NAME = Namespace.ACCUMULO + ".replication"; public static final String COMBINER_NAME = "statuscombiner"; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTarget.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTarget.java b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTarget.java index 95659a2..e39fb97 100644 --- a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTarget.java +++ b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTarget.java @@ -103,7 +103,7 @@ public class ReplicationTarget implements Writable { this.remoteIdentifier = WritableUtils.readString(in); } if (in.readBoolean()) { - this.sourceTableId = new Table.ID(WritableUtils.readString(in)); + this.sourceTableId = Table.ID.of(WritableUtils.readString(in)); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java b/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java index a4cc96d..45edd1a 100644 --- a/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java +++ b/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java @@ -115,7 +115,7 @@ public class Gatherer { public Gatherer(ClientContext context, TSummaryRequest request, AccumuloConfiguration tableConfig) { this.ctx = context; - this.tableId = new Table.ID(request.tableId); + this.tableId = Table.ID.of(request.tableId); this.startRow = ByteBufferUtil.toText(request.bounds.startRow); this.endRow = ByteBufferUtil.toText(request.bounds.endRow); this.clipRange = new Range(startRow, false, endRow, true); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java index c94c853..9c878fe 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java @@ -88,7 +88,7 @@ public class ByteBufferUtil { } public static Table.ID toTableId(ByteBuffer bytes) { - return new Table.ID(toString(bytes)); + return Table.ID.of(toString(bytes)); } public static ByteBuffer toByteBuffers(ByteSequence bs) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/impl/NamespaceTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/NamespaceTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/NamespaceTest.java new file mode 100644 index 0000000..2921e58 --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/NamespaceTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.core.client.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +/** + * Tests the Namespace ID class, mainly the internal cache. + */ +public class NamespaceTest { + @Rule + public TestName name = new TestName(); + + @Test + public void testCacheIncreases() { + String namespaceString = "namespace-" + name.getMethodName(); + Long initialSize = Namespace.ID.cache.asMap().entrySet().stream().count(); + Namespace.ID nsId = Namespace.ID.of(namespaceString); + assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count()); + assertEquals(namespaceString, nsId.canonicalID()); + } + + @Test + public void testCacheNoDuplicates() { + String namespaceString = "namespace-" + name.getMethodName(); + Long initialSize = Namespace.ID.cache.asMap().entrySet().stream().count(); + Namespace.ID nsId = Namespace.ID.of(namespaceString); + assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count()); + assertEquals(namespaceString, nsId.canonicalID()); + + // ensure duplicates are not created + Namespace.ID builtInNamespaceId = Namespace.ID.of("+accumulo"); + assertSame(Namespace.ID.ACCUMULO, builtInNamespaceId); + builtInNamespaceId = Namespace.ID.of("+default"); + assertSame(Namespace.ID.DEFAULT, builtInNamespaceId); + nsId = Namespace.ID.of(namespaceString); + assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count()); + assertEquals(namespaceString, nsId.canonicalID()); + Namespace.ID nsId2 = Namespace.ID.of(namespaceString); + assertEquals(initialSize + 1, Namespace.ID.cache.asMap().entrySet().stream().count()); + assertSame(nsId, nsId2); + } + + @Test(timeout = 60_000) + public void testCacheDecreasesAfterGC() { + Long initialSize = Namespace.ID.cache.asMap().entrySet().stream().count(); + generateJunkCacheEntries(); + Long postGCSize; + do { + System.gc(); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + fail("Thread interrupted while waiting for GC"); + } + postGCSize = Namespace.ID.cache.asMap().entrySet().stream().count(); + } while (postGCSize > initialSize); + + assertTrue("Cache did not decrease with GC.", Namespace.ID.cache.asMap().entrySet().stream().count() < initialSize); + } + + private void generateJunkCacheEntries() { + for (int i = 0; i < 1000; i++) + Namespace.ID.of(new String("namespace" + i)); + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerImplTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerImplTest.java index c6b4082..7bbff8f 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerImplTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/ScannerImplTest.java @@ -39,7 +39,7 @@ public class ScannerImplTest { @Test public void testValidReadaheadValues() { - Scanner s = new ScannerImpl(context, new Table.ID("foo"), Authorizations.EMPTY); + Scanner s = new ScannerImpl(context, Table.ID.of("foo"), Authorizations.EMPTY); s.setReadaheadThreshold(0); s.setReadaheadThreshold(10); s.setReadaheadThreshold(Long.MAX_VALUE); @@ -50,7 +50,7 @@ public class ScannerImplTest { @Test(expected = IllegalArgumentException.class) public void testInValidReadaheadValues() { - Scanner s = new ScannerImpl(context, new Table.ID("foo"), Authorizations.EMPTY); + Scanner s = new ScannerImpl(context, Table.ID.of("foo"), Authorizations.EMPTY); s.setReadaheadThreshold(-1); s.close(); } @@ -58,7 +58,7 @@ public class ScannerImplTest { @Test public void testGetAuthorizations() { Authorizations expected = new Authorizations("a,b"); - Scanner s = new ScannerImpl(context, new Table.ID("foo"), expected); + Scanner s = new ScannerImpl(context, Table.ID.of("foo"), expected); assertEquals(expected, s.getAuthorizations()); s.close(); } @@ -66,7 +66,7 @@ public class ScannerImplTest { @SuppressWarnings("resource") @Test(expected = IllegalArgumentException.class) public void testNullAuthorizationsFails() { - new ScannerImpl(context, new Table.ID("foo"), null); + new ScannerImpl(context, Table.ID.of("foo"), null); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsImplTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsImplTest.java index 8f59e17..4ef8628 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsImplTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsImplTest.java @@ -44,7 +44,7 @@ public class TableOperationsImplTest { Connector connector = EasyMock.createMock(Connector.class); Scanner scanner = EasyMock.createMock(Scanner.class); - Range range = new KeyExtent(new Table.ID("1"), null, null).toMetadataRange(); + Range range = new KeyExtent(Table.ID.of("1"), null, null).toMetadataRange(); String user = "root"; PasswordToken token = new PasswordToken("password"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/impl/TableTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TableTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TableTest.java new file mode 100644 index 0000000..b9f2e47 --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TableTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.core.client.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +/** + * Tests the Table ID class, mainly the internal cache. + */ +public class TableTest { + @Rule + public TestName name = new TestName(); + + @Test + public void testCacheIncreases() { + Long initialSize = Table.ID.cache.asMap().entrySet().stream().count(); + String tableString = "table-" + name.getMethodName(); + Table.ID table1 = Table.ID.of(tableString); + assertEquals(initialSize + 1, Table.ID.cache.asMap().entrySet().stream().count()); + assertEquals(tableString, table1.canonicalID()); + } + + @Test + public void testCacheNoDuplicates() { + String tableString = "table-" + name.getMethodName(); + Long initialSize = Table.ID.cache.asMap().entrySet().stream().count(); + Table.ID table1 = Table.ID.of(tableString); + assertEquals(initialSize + 1, Table.ID.cache.asMap().entrySet().stream().count()); + assertEquals(tableString, table1.canonicalID()); + + // ensure duplicates are not created + Table.ID builtInTableId = Table.ID.of("!0"); + assertSame(Table.ID.METADATA, builtInTableId); + builtInTableId = Table.ID.of("+r"); + assertSame(Table.ID.ROOT, builtInTableId); + builtInTableId = Table.ID.of("+rep"); + assertSame(Table.ID.REPLICATION, builtInTableId); + table1 = Table.ID.of(tableString); + assertEquals(initialSize + 1, Table.ID.cache.asMap().entrySet().stream().count()); + assertEquals(tableString, table1.canonicalID()); + Table.ID table2 = Table.ID.of(tableString); + assertEquals(initialSize + 1, Table.ID.cache.asMap().entrySet().stream().count()); + assertEquals(tableString, table2.canonicalID()); + assertSame(table1, table2); + } + + @Test(timeout = 60_000) + public void testCacheDecreasesAfterGC() { + Long initialSize = Table.ID.cache.asMap().entrySet().stream().count(); + generateJunkCacheEntries(); + Long postGCSize; + do { + System.gc(); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + fail("Thread interrupted while waiting for GC"); + } + postGCSize = Table.ID.cache.asMap().entrySet().stream().count(); + } while (postGCSize > initialSize); + + assertTrue("Cache did not decrease with GC.", Table.ID.cache.asMap().entrySet().stream().count() < initialSize); + } + + private void generateJunkCacheEntries() { + for (int i = 0; i < 1000; i++) + Table.ID.of(new String("table" + i)); + } + +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java index 079becd..ea3c8f7 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java @@ -65,7 +65,7 @@ public class TabletLocatorImplTest { private static final KeyExtent MTE = new KeyExtent(MetadataTable.ID, null, RTE.getEndRow()); static KeyExtent nke(String t, String er, String per) { - return new KeyExtent(new Table.ID(t), er == null ? null : new Text(er), per == null ? null : new Text(per)); + return new KeyExtent(Table.ID.of(t), er == null ? null : new Text(er), per == null ? null : new Text(per)); } static Range nr(String k1, boolean si, String k2, boolean ei) { @@ -143,7 +143,7 @@ public class TabletLocatorImplTest { RootTabletLocator rtl = new TestRootTabletLocator(); TabletLocatorImpl rootTabletCache = new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab1TabletCache = new TabletLocatorImpl(new Table.ID(table), rootTabletCache, ttlo, tslc); + TabletLocatorImpl tab1TabletCache = new TabletLocatorImpl(Table.ID.of(table), rootTabletCache, ttlo, tslc); setLocation(tservers, rootTabLoc, RTE, MTE, metaTabLoc); @@ -680,7 +680,7 @@ public class TabletLocatorImplTest { RootTabletLocator rtl = new TestRootTabletLocator(); TabletLocatorImpl rootTabletCache = new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab1TabletCache = new TabletLocatorImpl(new Table.ID("tab1"), rootTabletCache, ttlo, new YesLockChecker()); + TabletLocatorImpl tab1TabletCache = new TabletLocatorImpl(Table.ID.of("tab1"), rootTabletCache, ttlo, new YesLockChecker()); locateTabletTest(tab1TabletCache, "r1", null, null); @@ -1223,14 +1223,14 @@ public class TabletLocatorImplTest { RootTabletLocator rtl = new TestRootTabletLocator(); TabletLocatorImpl rootTabletCache = new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab0TabletCache = new TabletLocatorImpl(new Table.ID("0"), rootTabletCache, ttlo, new YesLockChecker()); + TabletLocatorImpl tab0TabletCache = new TabletLocatorImpl(Table.ID.of("0"), rootTabletCache, ttlo, new YesLockChecker()); setLocation(tservers, "tserver1", RTE, mte1, "tserver2"); setLocation(tservers, "tserver1", RTE, mte2, "tserver3"); // create two tablets that straddle a metadata split point - KeyExtent ke1 = new KeyExtent(new Table.ID("0"), new Text("0bbf20e"), null); - KeyExtent ke2 = new KeyExtent(new Table.ID("0"), new Text("0bc0756"), new Text("0bbf20e")); + KeyExtent ke1 = new KeyExtent(Table.ID.of("0"), new Text("0bbf20e"), null); + KeyExtent ke2 = new KeyExtent(Table.ID.of("0"), new Text("0bc0756"), new Text("0bbf20e")); setLocation(tservers, "tserver2", mte1, ke1, "tserver4"); setLocation(tservers, "tserver3", mte2, ke2, "tserver5"); @@ -1250,7 +1250,7 @@ public class TabletLocatorImplTest { RootTabletLocator rtl = new TestRootTabletLocator(); TabletLocatorImpl rootTabletCache = new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab0TabletCache = new TabletLocatorImpl(new Table.ID("0"), rootTabletCache, ttlo, new YesLockChecker()); + TabletLocatorImpl tab0TabletCache = new TabletLocatorImpl(Table.ID.of("0"), rootTabletCache, ttlo, new YesLockChecker()); setLocation(tservers, "tserver1", RTE, mte1, "tserver2"); setLocation(tservers, "tserver1", RTE, mte2, "tserver3"); @@ -1273,7 +1273,7 @@ public class TabletLocatorImplTest { KeyExtent mte4 = new KeyExtent(MetadataTable.ID, new Text("1;r"), new Text("1;j")); KeyExtent mte5 = new KeyExtent(MetadataTable.ID, null, new Text("1;r")); - KeyExtent ke1 = new KeyExtent(new Table.ID("1"), null, null); + KeyExtent ke1 = new KeyExtent(Table.ID.of("1"), null, null); TServers tservers = new TServers(); TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers); @@ -1281,7 +1281,7 @@ public class TabletLocatorImplTest { RootTabletLocator rtl = new TestRootTabletLocator(); TabletLocatorImpl rootTabletCache = new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab0TabletCache = new TabletLocatorImpl(new Table.ID("1"), rootTabletCache, ttlo, new YesLockChecker()); + TabletLocatorImpl tab0TabletCache = new TabletLocatorImpl(Table.ID.of("1"), rootTabletCache, ttlo, new YesLockChecker()); setLocation(tservers, "tserver1", RTE, mte1, "tserver2"); setLocation(tservers, "tserver1", RTE, mte2, "tserver3"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderTest.java index 7f2780e..3c43558 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderTest.java @@ -36,7 +36,7 @@ public class TabletServerBatchReaderTest { @Test public void testGetAuthorizations() { Authorizations expected = new Authorizations("a,b"); - try (BatchScanner s = new TabletServerBatchReader(context, new Table.ID("foo"), expected, 1)) { + try (BatchScanner s = new TabletServerBatchReader(context, Table.ID.of("foo"), expected, 1)) { assertEquals(expected, s.getAuthorizations()); } } @@ -44,6 +44,6 @@ public class TabletServerBatchReaderTest { @SuppressWarnings("resource") @Test(expected = IllegalArgumentException.class) public void testNullAuthorizationsFails() { - new TabletServerBatchReader(context, new Table.ID("foo"), null, 1); + new TabletServerBatchReader(context, Table.ID.of("foo"), null, 1); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java index 40f92e1..c9d0864 100644 --- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java +++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java @@ -46,7 +46,7 @@ public class BatchInputSplitTest { @Test public void testSimpleWritable() throws IOException { Range[] ranges = new Range[] {new Range(new Key("a"), new Key("b"))}; - BatchInputSplit split = new BatchInputSplit("table", new Table.ID("1"), Arrays.asList(ranges), new String[] {"localhost"}); + BatchInputSplit split = new BatchInputSplit("table", Table.ID.of("1"), Arrays.asList(ranges), new String[] {"localhost"}); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); @@ -67,7 +67,7 @@ public class BatchInputSplitTest { @Test public void testAllFieldsWritable() throws IOException { Range[] ranges = new Range[] {new Range(new Key("a"), new Key("b"))}; - BatchInputSplit split = new BatchInputSplit("table", new Table.ID("1"), Arrays.asList(ranges), new String[] {"localhost"}); + BatchInputSplit split = new BatchInputSplit("table", Table.ID.of("1"), Arrays.asList(ranges), new String[] {"localhost"}); Set<Pair<Text,Text>> fetchedColumns = new HashSet<>(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java b/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java index 73035d6..5920364 100644 --- a/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java +++ b/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java @@ -45,7 +45,7 @@ import org.junit.Test; public class KeyExtentTest { KeyExtent nke(String t, String er, String per) { - return new KeyExtent(new Table.ID(t), er == null ? null : new Text(er), per == null ? null : new Text(per)); + return new KeyExtent(Table.ID.of(t), er == null ? null : new Text(er), per == null ? null : new Text(per)); } KeyExtent ke; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java b/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java index 57b92cc..eac2954 100644 --- a/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java +++ b/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java @@ -192,31 +192,31 @@ public class RangeTest extends TestCase { public void testMergeOverlapping22() { - Range ke1 = new KeyExtent(new Table.ID("tab1"), new Text("Bank"), null).toMetadataRange(); - Range ke2 = new KeyExtent(new Table.ID("tab1"), new Text("Fails"), new Text("Bank")).toMetadataRange(); - Range ke3 = new KeyExtent(new Table.ID("tab1"), new Text("Sam"), new Text("Fails")).toMetadataRange(); - Range ke4 = new KeyExtent(new Table.ID("tab1"), new Text("bails"), new Text("Sam")).toMetadataRange(); - Range ke5 = new KeyExtent(new Table.ID("tab1"), null, new Text("bails")).toMetadataRange(); + Range ke1 = new KeyExtent(Table.ID.of("tab1"), new Text("Bank"), null).toMetadataRange(); + Range ke2 = new KeyExtent(Table.ID.of("tab1"), new Text("Fails"), new Text("Bank")).toMetadataRange(); + Range ke3 = new KeyExtent(Table.ID.of("tab1"), new Text("Sam"), new Text("Fails")).toMetadataRange(); + Range ke4 = new KeyExtent(Table.ID.of("tab1"), new Text("bails"), new Text("Sam")).toMetadataRange(); + Range ke5 = new KeyExtent(Table.ID.of("tab1"), null, new Text("bails")).toMetadataRange(); List<Range> rl = newRangeList(ke1, ke2, ke3, ke4, ke5); - List<Range> expected = newRangeList(new KeyExtent(new Table.ID("tab1"), null, null).toMetadataRange()); + List<Range> expected = newRangeList(new KeyExtent(Table.ID.of("tab1"), null, null).toMetadataRange()); check(Range.mergeOverlapping(rl), expected); rl = newRangeList(ke1, ke2, ke4, ke5); - expected = newRangeList(new KeyExtent(new Table.ID("tab1"), new Text("Fails"), null).toMetadataRange(), new KeyExtent(new Table.ID("tab1"), null, new Text( + expected = newRangeList(new KeyExtent(Table.ID.of("tab1"), new Text("Fails"), null).toMetadataRange(), new KeyExtent(Table.ID.of("tab1"), null, new Text( "Sam")).toMetadataRange()); check(Range.mergeOverlapping(rl), expected); rl = newRangeList(ke2, ke3, ke4, ke5); - expected = newRangeList(new KeyExtent(new Table.ID("tab1"), null, new Text("Bank")).toMetadataRange()); + expected = newRangeList(new KeyExtent(Table.ID.of("tab1"), null, new Text("Bank")).toMetadataRange()); check(Range.mergeOverlapping(rl), expected); rl = newRangeList(ke1, ke2, ke3, ke4); - expected = newRangeList(new KeyExtent(new Table.ID("tab1"), new Text("bails"), null).toMetadataRange()); + expected = newRangeList(new KeyExtent(Table.ID.of("tab1"), new Text("bails"), null).toMetadataRange()); check(Range.mergeOverlapping(rl), expected); rl = newRangeList(ke2, ke3, ke4); - expected = newRangeList(new KeyExtent(new Table.ID("tab1"), new Text("bails"), new Text("Bank")).toMetadataRange()); + expected = newRangeList(new KeyExtent(Table.ID.of("tab1"), new Text("bails"), new Text("Bank")).toMetadataRange()); check(Range.mergeOverlapping(rl), expected); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java index 03c2208..64201bd 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java @@ -139,7 +139,7 @@ public class IteratorUtilTest { SortedMapIterator source = new SortedMapIterator(tm); - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Table.ID("tab"), null, null), conf, + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(Table.ID.of("tab"), null, null), conf, new DefaultIteratorEnvironment(conf)); iter.seek(new Range(), EMPTY_COL_FAMS, false); @@ -171,7 +171,7 @@ public class IteratorUtilTest { SortedMapIterator source = new SortedMapIterator(tm); - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.majc, source, new KeyExtent(new Table.ID("tab"), null, null), conf, + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.majc, source, new KeyExtent(Table.ID.of("tab"), null, null), conf, new DefaultIteratorEnvironment(conf)); iter.seek(new Range(), EMPTY_COL_FAMS, false); @@ -207,7 +207,7 @@ public class IteratorUtilTest { conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "2," + AddingIter.class.getName()); conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "1," + SquaringIter.class.getName()); - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Table.ID("tab"), null, null), conf, + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(Table.ID.of("tab"), null, null), conf, new DefaultIteratorEnvironment(conf)); iter.seek(new Range(), EMPTY_COL_FAMS, false); @@ -243,7 +243,7 @@ public class IteratorUtilTest { SortedMapIterator source = new SortedMapIterator(tm); - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Table.ID("tab"), null, null), conf, + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(Table.ID.of("tab"), null, null), conf, new DefaultIteratorEnvironment(conf)); iter.seek(new Range(), EMPTY_COL_FAMS, false); @@ -279,7 +279,7 @@ public class IteratorUtilTest { SortedMapIterator source = new SortedMapIterator(tm); - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Table.ID("tab"), null, null), conf, + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(Table.ID.of("tab"), null, null), conf, new DefaultIteratorEnvironment(conf)); iter.seek(new Range(), EMPTY_COL_FAMS, false); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java index d38ea27..b26f012 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java @@ -345,7 +345,7 @@ public class MultiIteratorTest extends TestCase { List<SortedKeyValueIterator<Key,Value>> skvil = new ArrayList<>(1); skvil.add(new SortedMapIterator(tm1)); - KeyExtent extent = new KeyExtent(new Table.ID("tablename"), newRow(1), newRow(0)); + KeyExtent extent = new KeyExtent(Table.ID.of("tablename"), newRow(1), newRow(0)); MultiIterator mi = new MultiIterator(skvil, extent); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/metadata/MetadataServicerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/metadata/MetadataServicerTest.java b/core/src/test/java/org/apache/accumulo/core/metadata/MetadataServicerTest.java index 6f3316f..063dda1 100644 --- a/core/src/test/java/org/apache/accumulo/core/metadata/MetadataServicerTest.java +++ b/core/src/test/java/org/apache/accumulo/core/metadata/MetadataServicerTest.java @@ -40,7 +40,7 @@ import org.junit.Test; public class MetadataServicerTest { private static final String userTableName = "tableName"; - private static final Table.ID userTableId = new Table.ID("tableId"); + private static final Table.ID userTableId = Table.ID.of("tableId"); private static ClientContext context; @BeforeClass http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/replication/ReplicationConfigurationUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/replication/ReplicationConfigurationUtilTest.java b/core/src/test/java/org/apache/accumulo/core/replication/ReplicationConfigurationUtilTest.java index ee92f5d..1d72b7b 100644 --- a/core/src/test/java/org/apache/accumulo/core/replication/ReplicationConfigurationUtilTest.java +++ b/core/src/test/java/org/apache/accumulo/core/replication/ReplicationConfigurationUtilTest.java @@ -73,13 +73,13 @@ public class ReplicationConfigurationUtilTest { @Test public void regularTable() { - KeyExtent extent = new KeyExtent(new Table.ID("1"), new Text("b"), new Text("a")); + KeyExtent extent = new KeyExtent(Table.ID.of("1"), new Text("b"), new Text("a")); Assert.assertTrue("Table should be replicated", ReplicationConfigurationUtil.isEnabled(extent, conf)); } @Test public void regularNonEnabledTable() { - KeyExtent extent = new KeyExtent(new Table.ID("1"), new Text("b"), new Text("a")); + KeyExtent extent = new KeyExtent(Table.ID.of("1"), new Text("b"), new Text("a")); Assert.assertFalse("Table should not be replicated", ReplicationConfigurationUtil.isEnabled(extent, new ConfigurationCopy(new HashMap<String,String>()))); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/replication/ReplicationSchemaTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/replication/ReplicationSchemaTest.java b/core/src/test/java/org/apache/accumulo/core/replication/ReplicationSchemaTest.java index 08274ef..b665a5d 100644 --- a/core/src/test/java/org/apache/accumulo/core/replication/ReplicationSchemaTest.java +++ b/core/src/test/java/org/apache/accumulo/core/replication/ReplicationSchemaTest.java @@ -62,14 +62,14 @@ public class ReplicationSchemaTest { @Test public void extractTableId() { - Table.ID tableId = new Table.ID("1"); + Table.ID tableId = Table.ID.of("1"); Key k = new Key(new Text("foo"), StatusSection.NAME, new Text(tableId.getUtf8())); Assert.assertEquals(tableId, StatusSection.getTableId(k)); } @Test public void extractTableIdUsingText() { - Table.ID tableId = new Table.ID("1"); + Table.ID tableId = Table.ID.of("1"); Key k = new Key(new Text("foo"), StatusSection.NAME, new Text(tableId.getUtf8())); Assert.assertEquals(tableId, StatusSection.getTableId(k)); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/replication/ReplicationTargetTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/replication/ReplicationTargetTest.java b/core/src/test/java/org/apache/accumulo/core/replication/ReplicationTargetTest.java index c2c8b84..a28c04e 100644 --- a/core/src/test/java/org/apache/accumulo/core/replication/ReplicationTargetTest.java +++ b/core/src/test/java/org/apache/accumulo/core/replication/ReplicationTargetTest.java @@ -30,18 +30,18 @@ public class ReplicationTargetTest { @Test public void properEquality() { - ReplicationTarget expected1 = new ReplicationTarget("foo", "bar", new Table.ID("1")); + ReplicationTarget expected1 = new ReplicationTarget("foo", "bar", Table.ID.of("1")); - Assert.assertEquals(expected1, new ReplicationTarget("foo", "bar", new Table.ID("1"))); - Assert.assertNotEquals(expected1, new ReplicationTarget("foo", "foo", new Table.ID("1"))); - Assert.assertNotEquals(expected1, new ReplicationTarget("bar", "bar", new Table.ID("1"))); - Assert.assertNotEquals(expected1, new ReplicationTarget(null, "bar", new Table.ID("1"))); - Assert.assertNotEquals(expected1, new ReplicationTarget("foo", null, new Table.ID("1"))); + Assert.assertEquals(expected1, new ReplicationTarget("foo", "bar", Table.ID.of("1"))); + Assert.assertNotEquals(expected1, new ReplicationTarget("foo", "foo", Table.ID.of("1"))); + Assert.assertNotEquals(expected1, new ReplicationTarget("bar", "bar", Table.ID.of("1"))); + Assert.assertNotEquals(expected1, new ReplicationTarget(null, "bar", Table.ID.of("1"))); + Assert.assertNotEquals(expected1, new ReplicationTarget("foo", null, Table.ID.of("1"))); } @Test public void writableOut() throws Exception { - ReplicationTarget expected = new ReplicationTarget("foo", "bar", new Table.ID("1")); + ReplicationTarget expected = new ReplicationTarget("foo", "bar", Table.ID.of("1")); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer); @@ -65,7 +65,7 @@ public class ReplicationTargetTest { @Test public void staticFromTextHelper() throws Exception { - ReplicationTarget expected = new ReplicationTarget("foo", "bar", new Table.ID("1")); + ReplicationTarget expected = new ReplicationTarget("foo", "bar", Table.ID.of("1")); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer); Text t = new Text(); @@ -76,7 +76,7 @@ public class ReplicationTargetTest { @Test public void staticToTextHelper() throws Exception { - ReplicationTarget expected = new ReplicationTarget("foo", "bar", new Table.ID("1")); + ReplicationTarget expected = new ReplicationTarget("foo", "bar", Table.ID.of("1")); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer); Text t = new Text(); @@ -87,7 +87,7 @@ public class ReplicationTargetTest { @Test public void staticFromStringHelper() throws Exception { - ReplicationTarget expected = new ReplicationTarget("foo", "bar", new Table.ID("1")); + ReplicationTarget expected = new ReplicationTarget("foo", "bar", Table.ID.of("1")); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer); Text t = new Text(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/core/src/test/java/org/apache/accumulo/core/util/MergeTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/util/MergeTest.java b/core/src/test/java/org/apache/accumulo/core/util/MergeTest.java index 7a0773e..aa8a0d0 100644 --- a/core/src/test/java/org/apache/accumulo/core/util/MergeTest.java +++ b/core/src/test/java/org/apache/accumulo/core/util/MergeTest.java @@ -44,7 +44,7 @@ public class MergeTest { end = null; else end = new Text(String.format("%05d", tablets.size())); - KeyExtent extent = new KeyExtent(new Table.ID("table"), end, start); + KeyExtent extent = new KeyExtent(Table.ID.of("table"), end, start); start = end; tablets.add(new Size(extent, size)); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java b/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java index e5ed823..16ca6aa 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java +++ b/server/base/src/main/java/org/apache/accumulo/server/client/BulkImporter.java @@ -130,7 +130,7 @@ public class BulkImporter { final Map<Path,List<KeyExtent>> completeFailures = Collections.synchronizedSortedMap(new TreeMap<Path,List<KeyExtent>>()); ClientService.Client client = null; - final TabletLocator locator = TabletLocator.getLocator(context, new Table.ID(tableId)); + final TabletLocator locator = TabletLocator.getLocator(context, Table.ID.of(tableId)); try { final Map<Path,List<TabletLocation>> assignments = Collections.synchronizedSortedMap(new TreeMap<Path,List<TabletLocation>>()); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfWatcher.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfWatcher.java b/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfWatcher.java index 22969e5..ee27431 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfWatcher.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfWatcher.java @@ -73,7 +73,7 @@ class NamespaceConfWatcher implements Watcher { return; } } - Namespace.ID namespaceId = new Namespace.ID(namespaceIdStr); + Namespace.ID namespaceId = Namespace.ID.of(namespaceIdStr); switch (event.getType()) { case NodeDataChanged: http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java b/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java index f7ffe62..0f7812b 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java @@ -71,7 +71,7 @@ class TableConfWatcher implements Watcher { return; } } - Table.ID tableId = new Table.ID(tableIdString); + Table.ID tableId = Table.ID.of(tableIdString); switch (event.getType()) { case NodeDataChanged: http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java index e19cd36..83d4b78 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java @@ -374,7 +374,7 @@ public class VolumeManagerImpl implements VolumeManager { // TODO sanity check col fam String relPath = key.getColumnQualifierData().toString(); byte[] tableId = KeyExtent.tableOfMetadataRow(key.getRow()); - return getFullPath(new Table.ID(new String(tableId)), relPath); + return getFullPath(Table.ID.of(new String(tableId)), relPath); } @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancer.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancer.java index bd16d9b..702478d 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/ChaoticLoadBalancer.java @@ -130,7 +130,7 @@ public class ChaoticLoadBalancer extends TabletBalancer { for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { for (String tableId : e.getValue().getTableMap().keySet()) { - Table.ID id = new Table.ID(tableId); + Table.ID id = Table.ID.of(tableId); if (!moveMetadata && MetadataTable.ID.equals(id)) continue; try { http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java index 4c85521..2dd63f9 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/DefaultLoadBalancer.java @@ -276,7 +276,7 @@ public class DefaultLoadBalancer extends TabletBalancer { if (status != null && status.tableMap != null) { Map<String,TableInfo> tableMap = status.tableMap; for (Entry<String,TableInfo> entry : tableMap.entrySet()) { - result.put(new Table.ID(entry.getKey()), entry.getValue().onlineTablets); + result.put(Table.ID.of(entry.getKey()), entry.getValue().onlineTablets); } } return result; @@ -304,7 +304,7 @@ public class DefaultLoadBalancer extends TabletBalancer { double busy = info.ingestRate + info.queryRate; if (busy > busiest) { busiest = busy; - result = new Table.ID(entry.getKey()); + result = Table.ID.of(entry.getKey()); } } return result; http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/master/balancer/GroupBalancer.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/GroupBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/GroupBalancer.java index fd15ddd..9a49b7d 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/GroupBalancer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/GroupBalancer.java @@ -774,7 +774,7 @@ public abstract class GroupBalancer extends TabletBalancer { Scanner scanner = new IsolatedScanner(context.getConnector().createScanner(MetadataTable.NAME, Authorizations.EMPTY)); scanner.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME); MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner); - scanner.setRange(MetadataSchema.TabletsSection.getRange(new org.apache.accumulo.core.client.impl.Table.ID(tableId))); + scanner.setRange(MetadataSchema.TabletsSection.getRange(org.apache.accumulo.core.client.impl.Table.ID.of(tableId))); RowIterator rowIter = new RowIterator(scanner); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java index 0d4d3a8..288742d 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/HostRegexTableLoadBalancer.java @@ -197,7 +197,7 @@ public class HostRegexTableLoadBalancer extends TableLoadBalancer implements Con tableIdToTableName = new HashMap<>(); poolNameToRegexPattern = new HashMap<>(); for (Entry<String,String> table : t.tableIdMap().entrySet()) { - Table.ID tableId = new Table.ID(table.getValue()); + Table.ID tableId = Table.ID.of(table.getValue()); tableIdToTableName.put(tableId, table.getKey()); conf.getTableConfiguration(tableId).addObserver(this); Map<String,String> customProps = conf.getTableConfiguration(tableId).getAllPropertiesWithPrefix(Property.TABLE_ARBITRARY_PROP_PREFIX); @@ -344,7 +344,7 @@ public class HostRegexTableLoadBalancer extends TableLoadBalancer implements Con continue; } try { - List<TabletStats> outOfBoundsTablets = getOnlineTabletsForTable(e.getKey(), new Table.ID(tid)); + List<TabletStats> outOfBoundsTablets = getOnlineTabletsForTable(e.getKey(), Table.ID.of(tid)); if (null == outOfBoundsTablets) { continue; } @@ -422,7 +422,7 @@ public class HostRegexTableLoadBalancer extends TableLoadBalancer implements Con } for (String s : tableIdMap.values()) { - Table.ID tableId = new Table.ID(s); + Table.ID tableId = Table.ID.of(s); String tableName = tableIdToTableName.get(tableId); String regexTableName = getPoolNameForTable(tableName); SortedMap<TServerInstance,TabletServerStatus> currentView = currentGrouped.get(regexTableName); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/master/balancer/RegexGroupBalancer.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/RegexGroupBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/RegexGroupBalancer.java index 54c76aa..e11557a 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/RegexGroupBalancer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/RegexGroupBalancer.java @@ -58,7 +58,7 @@ public class RegexGroupBalancer extends GroupBalancer { @Override protected long getWaitTime() { - Map<String,String> customProps = context.getServerConfigurationFactory().getTableConfiguration(new Table.ID(tableId)) + Map<String,String> customProps = context.getServerConfigurationFactory().getTableConfiguration(Table.ID.of(tableId)) .getAllPropertiesWithPrefix(Property.TABLE_ARBITRARY_PROP_PREFIX); if (customProps.containsKey(WAIT_TIME_PROPERTY)) { return ConfigurationTypeHelper.getTimeInMillis(customProps.get(WAIT_TIME_PROPERTY)); @@ -70,7 +70,7 @@ public class RegexGroupBalancer extends GroupBalancer { @Override protected Function<KeyExtent,String> getPartitioner() { - Map<String,String> customProps = context.getServerConfigurationFactory().getTableConfiguration(new Table.ID(tableId)) + Map<String,String> customProps = context.getServerConfigurationFactory().getTableConfiguration(Table.ID.of(tableId)) .getAllPropertiesWithPrefix(Property.TABLE_ARBITRARY_PROP_PREFIX); String regex = customProps.get(REGEX_PROPERTY); final String defaultGroup = customProps.get(DEFAUT_GROUP_PROPERTY); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java index 2b4b552..bbf2b80 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/balancer/TableLoadBalancer.java @@ -153,7 +153,7 @@ public class TableLoadBalancer extends TabletBalancer { return minBalanceTime; for (String s : t.tableIdMap().values()) { ArrayList<TabletMigration> newMigrations = new ArrayList<>(); - long tableBalanceTime = getBalancerForTable(new Table.ID(s)).balance(current, migrations, newMigrations); + long tableBalanceTime = getBalancerForTable(Table.ID.of(s)).balance(current, migrations, newMigrations); if (tableBalanceTime < minBalanceTime) minBalanceTime = tableBalanceTime; migrationsOut.addAll(newMigrations); http://git-wip-us.apache.org/repos/asf/accumulo/blob/cc1cf734/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReport.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReport.java b/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReport.java index 532c791..ea8fab7 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReport.java +++ b/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReport.java @@ -189,7 +189,7 @@ public class ProblemReport { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); DataInputStream dis = new DataInputStream(bais); - Table.ID tableId = new Table.ID(dis.readUTF()); + Table.ID tableId = Table.ID.of(dis.readUTF()); String problemType = dis.readUTF(); String resource = dis.readUTF(); @@ -201,7 +201,7 @@ public class ProblemReport { } public static ProblemReport decodeMetadataEntry(Entry<Key,Value> entry) throws IOException { - Table.ID tableId = new Table.ID(entry.getKey().getRow().toString().substring("~err_".length())); + Table.ID tableId = Table.ID.of(entry.getKey().getRow().toString().substring("~err_".length())); String problemType = entry.getKey().getColumnFamily().toString(); String resource = entry.getKey().getColumnQualifier().toString();
