This is an automated email from the ASF dual-hosted git repository. kturner pushed a commit to branch elasticity in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/elasticity by this push: new f8258479b7 Rename TabletLocator to TabletCache (#3324) f8258479b7 is described below commit f8258479b75a7b8c7228d32e99126b668b51cf7c Author: Keith Turner <ktur...@apache.org> AuthorDate: Thu Apr 20 12:40:28 2023 -0400 Rename TabletLocator to TabletCache (#3324) In #3292 the TabletLocator was modified to cache tablets with out a location. This rename is in response to the more general purpose of the client side tablet cache. --- .../{TabletLocator.java => ClientTabletCache.java} | 98 ++++---- ...LocatorImpl.java => ClientTabletCacheImpl.java} | 171 +++++++------ .../core/clientImpl/ConditionalWriterImpl.java | 6 +- ...bletLocator.java => RootClientTabletCache.java} | 32 +-- ...tLocator.java => SyncingClientTabletCache.java} | 26 +- .../core/clientImpl/TableOperationsImpl.java | 15 +- .../TabletServerBatchReaderIterator.java | 20 +- .../core/clientImpl/TabletServerBatchWriter.java | 12 +- .../accumulo/core/clientImpl/ThriftScanner.java | 23 +- ...tLocator.java => TimeoutClientTabletCache.java} | 8 +- .../apache/accumulo/core/clientImpl/Writer.java | 12 +- .../core/clientImpl/ZookeeperLockChecker.java | 2 +- ...iner.java => MetadataCachedTabletObtainer.java} | 36 +-- ...mplTest.java => ClientTabletCacheImplTest.java} | 271 +++++++++++---------- ...torTest.java => RootClientTabletCacheTest.java} | 8 +- .../hadoopImpl/mapred/AccumuloRecordReader.java | 4 +- .../hadoopImpl/mapreduce/AccumuloRecordReader.java | 4 +- .../mapreduce/lib/InputConfigurator.java | 10 +- .../accumulo/server/client/BulkImporter.java | 62 ++--- .../accumulo/server/client/BulkImporterTest.java | 20 +- ...onStateTest.java => CachedTabletStateTest.java} | 2 +- .../org/apache/accumulo/tserver/TabletServer.java | 4 +- .../apache/accumulo/test/BatchWriterIterator.java | 4 +- .../accumulo/test/functional/BulkFailureIT.java | 6 +- .../test/functional/ManagerAssignmentIT.java | 28 +-- .../test/functional/OnDemandTabletUnloadingIT.java | 6 +- .../accumulo/test/manager/SuspendedTabletsIT.java | 8 +- 27 files changed, 450 insertions(+), 448 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCache.java similarity index 76% rename from core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocator.java rename to core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCache.java index f15d6c1984..adbe1d2b7e 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocator.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCache.java @@ -37,7 +37,7 @@ import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.dataImpl.KeyExtent; -import org.apache.accumulo.core.metadata.MetadataLocationObtainer; +import org.apache.accumulo.core.metadata.MetadataCachedTabletObtainer; import org.apache.accumulo.core.metadata.MetadataTable; import org.apache.accumulo.core.metadata.RootTable; import org.apache.accumulo.core.singletons.SingletonManager; @@ -48,11 +48,14 @@ import org.apache.hadoop.io.Text; import com.google.common.base.Preconditions; -// ELASTICITY_TODO rename to TabletCache -public abstract class TabletLocator { +/** + * Client side cache of information about Tablets. Currently, a tablet prev end row is cached and + * locations are cached if they exists. + */ +public abstract class ClientTabletCache { /** - * Flipped false on call to {@link #clearLocators}. Checked by client classes that locally cache + * Flipped false on call to {@link #clearInstances}. Checked by client classes that locally cache * Locators. */ private volatile boolean isValid = true; @@ -69,7 +72,6 @@ public abstract class TabletLocator { REQUIRED, NOT_REQUIRED } - // ELASTICITY_TODO rename to findTablet /** * Finds the tablet that contains the given row. * @@ -80,17 +82,17 @@ public abstract class TabletLocator { * @return overlapping tablet. If no overlapping tablet exists, returns null. If location is * required and the tablet currently has no location ,returns null. */ - public abstract TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, + public abstract CachedTablet findTablet(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException; - public TabletLocation locateTabletWithRetry(ClientContext context, Text row, boolean skipRow, + public CachedTablet findTabletWithRetry(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - var tl = locateTablet(context, row, skipRow, locationNeed); + var tl = findTablet(context, row, skipRow, locationNeed); while (tl == null && locationNeed == LocationNeed.REQUIRED) { UtilWaitThread.sleep(100); - tl = locateTablet(context, row, skipRow, locationNeed); + tl = findTablet(context, row, skipRow, locationNeed); } return tl; } @@ -121,22 +123,21 @@ public abstract class TabletLocator { * @return The failed ranges that did not have a location (if a location is required) or where * contiguous tablets could not be found. */ - public abstract List<Range> locateTablets(ClientContext context, List<Range> ranges, - BiConsumer<TabletLocation,Range> rangeConsumer, LocationNeed locationNeed) + public abstract List<Range> findTablets(ClientContext context, List<Range> ranges, + BiConsumer<CachedTablet,Range> rangeConsumer, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException; /** * The behavior of this method is similar to - * {@link #locateTablets(ClientContext, List, BiConsumer, LocationNeed)}, except it bins ranges to + * {@link #findTablets(ClientContext, List, BiConsumer, LocationNeed)}, except it bins ranges to * the passed in binnedRanges map instead of passing them to a consumer. This method only bins to * hosted tablets with a location. */ public List<Range> binRanges(ClientContext context, List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> binnedRanges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - return locateTablets(context, ranges, - ((cachedTablet, range) -> TabletLocatorImpl.addRange(binnedRanges, cachedTablet, range)), - LocationNeed.REQUIRED); + return findTablets(context, ranges, ((cachedTablet, range) -> ClientTabletCacheImpl + .addRange(binnedRanges, cachedTablet, range)), LocationNeed.REQUIRED); } public abstract void invalidateCache(KeyExtent failedExtent); @@ -153,11 +154,11 @@ public abstract class TabletLocator { */ public abstract void invalidateCache(ClientContext context, String server); - private static class LocatorKey { + private static class InstanceKey { InstanceId instanceId; TableId tableId; - LocatorKey(InstanceId instanceId, TableId table) { + InstanceKey(InstanceId instanceId, TableId table) { this.instanceId = instanceId; this.tableId = table; } @@ -169,26 +170,26 @@ public abstract class TabletLocator { @Override public boolean equals(Object o) { - if (o instanceof LocatorKey) { - return equals((LocatorKey) o); + if (o instanceof InstanceKey) { + return equals((InstanceKey) o); } return false; } - public boolean equals(LocatorKey lk) { + public boolean equals(InstanceKey lk) { return instanceId.equals(lk.instanceId) && tableId.equals(lk.tableId); } } - private static final HashMap<LocatorKey,TabletLocator> locators = new HashMap<>(); + private static final HashMap<InstanceKey,ClientTabletCache> instances = new HashMap<>(); private static boolean enabled = true; - public static synchronized void clearLocators() { - for (TabletLocator locator : locators.values()) { + public static synchronized void clearInstances() { + for (ClientTabletCache locator : instances.values()) { locator.isValid = false; } - locators.clear(); + instances.clear(); } static synchronized boolean isEnabled() { @@ -196,7 +197,7 @@ public abstract class TabletLocator { } static synchronized void disable() { - clearLocators(); + clearInstances(); enabled = false; } @@ -208,24 +209,24 @@ public abstract class TabletLocator { return 0L; } - public static synchronized TabletLocator getLocator(ClientContext context, TableId tableId) { + public static synchronized ClientTabletCache getInstance(ClientContext context, TableId tableId) { Preconditions.checkState(enabled, "The Accumulo singleton that that tracks tablet locations is " + "disabled. This is likely caused by all AccumuloClients being closed or garbage collected"); - LocatorKey key = new LocatorKey(context.getInstanceID(), tableId); - TabletLocator tl = locators.get(key); + InstanceKey key = new InstanceKey(context.getInstanceID(), tableId); + ClientTabletCache tl = instances.get(key); if (tl == null) { - MetadataLocationObtainer mlo = new MetadataLocationObtainer(); + MetadataCachedTabletObtainer mlo = new MetadataCachedTabletObtainer(); if (RootTable.ID.equals(tableId)) { - tl = new RootTabletLocator(new ZookeeperLockChecker(context)); + tl = new RootClientTabletCache(new ZookeeperLockChecker(context)); } else if (MetadataTable.ID.equals(tableId)) { - tl = new TabletLocatorImpl(MetadataTable.ID, getLocator(context, RootTable.ID), mlo, + tl = new ClientTabletCacheImpl(MetadataTable.ID, getInstance(context, RootTable.ID), mlo, new ZookeeperLockChecker(context)); } else { - tl = new TabletLocatorImpl(tableId, getLocator(context, MetadataTable.ID), mlo, + tl = new ClientTabletCacheImpl(tableId, getInstance(context, MetadataTable.ID), mlo, new ZookeeperLockChecker(context)); } - locators.put(key, tl); + instances.put(key, tl); } return tl; @@ -236,43 +237,42 @@ public abstract class TabletLocator { @Override public boolean isEnabled() { - return TabletLocator.isEnabled(); + return ClientTabletCache.isEnabled(); } @Override public void enable() { - TabletLocator.enable(); + ClientTabletCache.enable(); } @Override public void disable() { - TabletLocator.disable(); + ClientTabletCache.disable(); } }); } - public static class TabletLocations { + public static class CachedTablets { - private final List<TabletLocation> locations; + private final List<CachedTablet> cachedTablets; - public TabletLocations(List<TabletLocation> locations) { - this.locations = locations; + public CachedTablets(List<CachedTablet> cachedTablets) { + this.cachedTablets = cachedTablets; } - public List<TabletLocation> getLocations() { - return locations; + public List<CachedTablet> getCachedTablets() { + return cachedTablets; } } - // ELASTICITY_TODO rename to CachedTablet - public static class TabletLocation { + public static class CachedTablet { private static final Interner<String> interner = new Interner<>(); private final KeyExtent tablet_extent; private final String tserverLocation; private final String tserverSession; - public TabletLocation(KeyExtent tablet_extent, String tablet_location, String session) { + public CachedTablet(KeyExtent tablet_extent, String tablet_location, String session) { checkArgument(tablet_extent != null, "tablet_extent is null"); checkArgument(tablet_location != null, "tablet_location is null"); checkArgument(session != null, "session is null"); @@ -281,7 +281,7 @@ public abstract class TabletLocator { this.tserverSession = interner.intern(session); } - public TabletLocation(KeyExtent tablet_extent, Optional<String> tablet_location, + public CachedTablet(KeyExtent tablet_extent, Optional<String> tablet_location, Optional<String> session) { checkArgument(tablet_extent != null, "tablet_extent is null"); this.tablet_extent = tablet_extent; @@ -289,7 +289,7 @@ public abstract class TabletLocator { this.tserverSession = session.map(interner::intern).orElse(null); } - public TabletLocation(KeyExtent tablet_extent) { + public CachedTablet(KeyExtent tablet_extent) { checkArgument(tablet_extent != null, "tablet_extent is null"); this.tablet_extent = tablet_extent; this.tserverLocation = null; @@ -298,8 +298,8 @@ public abstract class TabletLocator { @Override public boolean equals(Object o) { - if (o instanceof TabletLocation) { - TabletLocation otl = (TabletLocation) o; + if (o instanceof CachedTablet) { + CachedTablet otl = (CachedTablet) o; return getExtent().equals(otl.getExtent()) && getTserverLocation().equals(otl.getTserverLocation()) && getTserverSession().equals(otl.getTserverSession()); diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java similarity index 81% rename from core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java rename to core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java index fc60a9b256..2ec7b604e4 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImpl.java @@ -74,9 +74,9 @@ import com.google.common.annotations.VisibleForTesting; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -public class TabletLocatorImpl extends TabletLocator { +public class ClientTabletCacheImpl extends ClientTabletCache { - private static final Logger log = LoggerFactory.getLogger(TabletLocatorImpl.class); + private static final Logger log = LoggerFactory.getLogger(ClientTabletCacheImpl.class); private static final AtomicBoolean HOSTING_ENABLED = new AtomicBoolean(true); // MAX_TEXT represents a TEXT object that is greater than all others. Attempted to use null for @@ -98,9 +98,9 @@ public class TabletLocatorImpl extends TabletLocator { }; protected TableId tableId; - protected TabletLocator parent; - protected TreeMap<Text,TabletLocation> metaCache = new TreeMap<>(END_ROW_COMPARATOR); - protected TabletLocationObtainer locationObtainer; + protected ClientTabletCache parent; + protected TreeMap<Text,CachedTablet> metaCache = new TreeMap<>(END_ROW_COMPARATOR); + protected CachedTabletObtainer tabletObtainer; private final TabletServerLockChecker lockChecker; protected Text lastTabletRow; @@ -113,15 +113,15 @@ public class TabletLocatorImpl extends TabletLocator { private final Cache<KeyExtent,Long> recentOndemandRequest = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(30)).build(); - public interface TabletLocationObtainer { + public interface CachedTabletObtainer { /** * @return null when unable to read information successfully */ - TabletLocations lookupTablet(ClientContext context, TabletLocation src, Text row, Text stopRow, - TabletLocator parent) throws AccumuloSecurityException, AccumuloException; + CachedTablets lookupTablet(ClientContext context, CachedTablet src, Text row, Text stopRow, + ClientTabletCache parent) throws AccumuloSecurityException, AccumuloException; - List<TabletLocation> lookupTablets(ClientContext context, String tserver, - Map<KeyExtent,List<Range>> map, TabletLocator parent) + List<CachedTablet> lookupTablets(ClientContext context, String tserver, + Map<KeyExtent,List<Range>> map, ClientTabletCache parent) throws AccumuloSecurityException, AccumuloException; } @@ -136,7 +136,7 @@ public class TabletLocatorImpl extends TabletLocator { private final HashSet<Pair<String,String>> okLocks = new HashSet<>(); private final HashSet<Pair<String,String>> invalidLocks = new HashSet<>(); - private TabletLocation checkLock(TabletLocation tl) { + private CachedTablet checkLock(CachedTablet tl) { // the goal of this class is to minimize calls out to lockChecker under that assumption that // its a resource synchronized among many threads... want to // avoid fine grained synchronization when binning lots of mutations or ranges... remember @@ -178,11 +178,11 @@ public class TabletLocatorImpl extends TabletLocator { } } - public TabletLocatorImpl(TableId tableId, TabletLocator parent, TabletLocationObtainer tlo, + public ClientTabletCacheImpl(TableId tableId, ClientTabletCache parent, CachedTabletObtainer tlo, TabletServerLockChecker tslc) { this.tableId = tableId; this.parent = parent; - this.locationObtainer = tlo; + this.tabletObtainer = tlo; this.lockChecker = tslc; this.lastTabletRow = new Text(tableId.canonical()); @@ -221,7 +221,7 @@ public class TabletLocatorImpl extends TabletLocator { for (T mutation : mutations) { row.set(mutation.getRow()); - TabletLocation tl = locateTabletInCache(row); + CachedTablet tl = findTabletInCache(row); if (!addMutation(binnedMutations, mutation, tl, lcSession)) { notInCache.add(mutation); } @@ -242,8 +242,8 @@ public class TabletLocatorImpl extends TabletLocator { row.set(mutation.getRow()); - TabletLocation tl = - _locateTablet(context, row, false, false, false, lcSession, LocationNeed.REQUIRED); + CachedTablet tl = + _findTablet(context, row, false, false, false, lcSession, LocationNeed.REQUIRED); if (!addMutation(binnedMutations, mutation, tl, lcSession)) { failures.add(mutation); @@ -269,7 +269,7 @@ public class TabletLocatorImpl extends TabletLocator { } private <T extends Mutation> boolean addMutation( - Map<String,TabletServerMutations<T>> binnedMutations, T mutation, TabletLocation tl, + Map<String,TabletServerMutations<T>> binnedMutations, T mutation, CachedTablet tl, LockCheckerSession lcSession) { if (tl == null || tl.getTserverLocation().isEmpty()) { @@ -298,9 +298,9 @@ public class TabletLocatorImpl extends TabletLocator { return false; } - static boolean isContiguous(List<TabletLocation> tabletLocations) { + static boolean isContiguous(List<CachedTablet> cachedTablets) { - Iterator<TabletLocation> iter = tabletLocations.iterator(); + Iterator<CachedTablet> iter = cachedTablets.iterator(); KeyExtent prevExtent = iter.next().getExtent(); while (iter.hasNext()) { @@ -316,17 +316,16 @@ public class TabletLocatorImpl extends TabletLocator { return true; } - private List<Range> locateTablets(ClientContext context, List<Range> ranges, - BiConsumer<TabletLocation,Range> rangeConsumer, boolean useCache, - LockCheckerSession lcSession, LocationNeed locationNeed, - Consumer<KeyExtent> locationlessConsumer) + private List<Range> findTablets(ClientContext context, List<Range> ranges, + BiConsumer<CachedTablet,Range> rangeConsumer, boolean useCache, LockCheckerSession lcSession, + LocationNeed locationNeed, Consumer<KeyExtent> locationlessConsumer) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { List<Range> failures = new ArrayList<>(); - List<TabletLocation> tabletLocations = new ArrayList<>(); + List<CachedTablet> cachedTablets = new ArrayList<>(); l1: for (Range range : ranges) { - tabletLocations.clear(); + cachedTablets.clear(); Text startRow; @@ -336,12 +335,12 @@ public class TabletLocatorImpl extends TabletLocator { startRow = new Text(); } - TabletLocation tl = null; + CachedTablet tl = null; if (useCache) { - tl = lcSession.checkLock(locateTabletInCache(startRow)); + tl = lcSession.checkLock(findTabletInCache(startRow)); } else { - tl = _locateTablet(context, startRow, false, false, false, lcSession, locationNeed); + tl = _findTablet(context, startRow, false, false, false, lcSession, locationNeed); } if (tl == null) { @@ -349,16 +348,16 @@ public class TabletLocatorImpl extends TabletLocator { continue; } - tabletLocations.add(tl); + cachedTablets.add(tl); while (tl.getExtent().endRow() != null && !range.afterEndKey(new Key(tl.getExtent().endRow()).followingKey(PartialKey.ROW))) { if (useCache) { Text row = new Text(tl.getExtent().endRow()); row.append(new byte[] {0}, 0, 1); - tl = lcSession.checkLock(locateTabletInCache(row)); + tl = lcSession.checkLock(findTabletInCache(row)); } else { - tl = _locateTablet(context, tl.getExtent().endRow(), true, false, false, lcSession, + tl = _findTablet(context, tl.getExtent().endRow(), true, false, false, lcSession, locationNeed); } @@ -366,15 +365,15 @@ public class TabletLocatorImpl extends TabletLocator { failures.add(range); continue l1; } - tabletLocations.add(tl); + cachedTablets.add(tl); } // pass all tablets without a location before failing range - tabletLocations.stream().filter(tloc -> tloc.getTserverLocation().isEmpty()) - .map(TabletLocation::getExtent).forEach(locationlessConsumer); + cachedTablets.stream().filter(tloc -> tloc.getTserverLocation().isEmpty()) + .map(CachedTablet::getExtent).forEach(locationlessConsumer); if (locationNeed == LocationNeed.REQUIRED - && !tabletLocations.stream().allMatch(tloc -> tloc.getTserverLocation().isPresent())) { + && !cachedTablets.stream().allMatch(tloc -> tloc.getTserverLocation().isPresent())) { failures.add(range); continue; } @@ -383,8 +382,8 @@ public class TabletLocatorImpl extends TabletLocator { // from the cache and other from the metadata table in the loop above we may end up with // non-contiguous extents. This can happen when a subset of exents are placed in the cache and // then after that merges and splits happen. - if (isContiguous(tabletLocations)) { - for (TabletLocation tl2 : tabletLocations) { + if (isContiguous(cachedTablets)) { + for (CachedTablet tl2 : cachedTablets) { rangeConsumer.accept(tl2, range); } } else { @@ -397,8 +396,8 @@ public class TabletLocatorImpl extends TabletLocator { } @Override - public List<Range> locateTablets(ClientContext context, List<Range> ranges, - BiConsumer<TabletLocation,Range> rangeConsumer, LocationNeed locationNeed) + public List<Range> findTablets(ClientContext context, List<Range> ranges, + BiConsumer<CachedTablet,Range> rangeConsumer, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { /* @@ -426,7 +425,7 @@ public class TabletLocatorImpl extends TabletLocator { // sort ranges... therefore try binning ranges using only the cache // and sort whatever fails and retry - failures = locateTablets(context, ranges, rangeConsumer, true, lcSession, locationNeed, + failures = findTablets(context, ranges, rangeConsumer, true, lcSession, locationNeed, keyExtent -> {}); } finally { rLock.unlock(); @@ -450,7 +449,7 @@ public class TabletLocatorImpl extends TabletLocator { wLock.lock(); try { - failures = locateTablets(context, failures, rangeConsumer, false, lcSession, locationNeed, + failures = findTablets(context, failures, rangeConsumer, false, lcSession, locationNeed, locationLessConsumer); } finally { wLock.unlock(); @@ -501,7 +500,7 @@ public class TabletLocatorImpl extends TabletLocator { wLock.lock(); try { - for (TabletLocation cacheEntry : metaCache.values()) { + for (CachedTablet cacheEntry : metaCache.values()) { var loc = cacheEntry.getTserverLocation(); if (loc.isPresent() && loc.get().equals(server)) { badExtents.add(cacheEntry.getExtent()); @@ -538,7 +537,7 @@ public class TabletLocatorImpl extends TabletLocator { } @Override - public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, + public CachedTablet findTablet(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { @@ -551,7 +550,7 @@ public class TabletLocatorImpl extends TabletLocator { } LockCheckerSession lcSession = new LockCheckerSession(); - TabletLocation tl = _locateTablet(context, row, skipRow, false, true, lcSession, locationNeed); + CachedTablet tl = _findTablet(context, row, skipRow, false, true, lcSession, locationNeed); if (timer != null) { timer.stop(); @@ -638,26 +637,26 @@ public class TabletLocatorImpl extends TabletLocator { } } - private void lookupTabletLocation(ClientContext context, Text row, boolean retry, + private void lookupTablet(ClientContext context, Text row, boolean retry, LockCheckerSession lcSession) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { Text metadataRow = new Text(tableId.canonical()); metadataRow.append(new byte[] {';'}, 0, 1); metadataRow.append(row.getBytes(), 0, row.getLength()); - TabletLocation ptl = parent.locateTablet(context, metadataRow, false, LocationNeed.REQUIRED); + CachedTablet ptl = parent.findTablet(context, metadataRow, false, LocationNeed.REQUIRED); if (ptl != null) { - TabletLocations locations = - locationObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow, parent); - while (locations != null && locations.getLocations().isEmpty()) { + CachedTablets cachedTablets = + tabletObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow, parent); + while (cachedTablets != null && cachedTablets.getCachedTablets().isEmpty()) { // try the next tablet, the current tablet does not have any tablets that overlap the row Text er = ptl.getExtent().endRow(); if (er != null && er.compareTo(lastTabletRow) < 0) { // System.out.println("er "+er+" ltr "+lastTabletRow); - ptl = parent.locateTablet(context, er, true, LocationNeed.REQUIRED); + ptl = parent.findTablet(context, er, true, LocationNeed.REQUIRED); if (ptl != null) { - locations = - locationObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow, parent); + cachedTablets = + tabletObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow, parent); } else { break; } @@ -666,7 +665,7 @@ public class TabletLocatorImpl extends TabletLocator { } } - if (locations == null) { + if (cachedTablets == null) { return; } @@ -674,18 +673,18 @@ public class TabletLocatorImpl extends TabletLocator { // best to deal with each extent individually Text lastEndRow = null; - for (TabletLocation tabletLocation : locations.getLocations()) { + for (CachedTablet cachedTablet : cachedTablets.getCachedTablets()) { - KeyExtent ke = tabletLocation.getExtent(); - TabletLocation locToCache; + KeyExtent ke = cachedTablet.getExtent(); + CachedTablet locToCache; // create new location if current prevEndRow == endRow if ((lastEndRow != null) && (ke.prevEndRow() != null) && ke.prevEndRow().equals(lastEndRow)) { - locToCache = new TabletLocation(new KeyExtent(ke.tableId(), ke.endRow(), lastEndRow), - tabletLocation.getTserverLocation(), tabletLocation.getTserverSession()); + locToCache = new CachedTablet(new KeyExtent(ke.tableId(), ke.endRow(), lastEndRow), + cachedTablet.getTserverLocation(), cachedTablet.getTserverSession()); } else { - locToCache = tabletLocation; + locToCache = cachedTablet; } // save endRow for next iteration @@ -697,46 +696,46 @@ public class TabletLocatorImpl extends TabletLocator { } - private void updateCache(TabletLocation tabletLocation, LockCheckerSession lcSession) { - if (!tabletLocation.getExtent().tableId().equals(tableId)) { + private void updateCache(CachedTablet cachedTablet, LockCheckerSession lcSession) { + if (!cachedTablet.getExtent().tableId().equals(tableId)) { // sanity check throw new IllegalStateException( - "Unexpected extent returned " + tableId + " " + tabletLocation.getExtent()); + "Unexpected extent returned " + tableId + " " + cachedTablet.getExtent()); } // clear out any overlapping extents in cache - removeOverlapping(metaCache, tabletLocation.getExtent()); + removeOverlapping(metaCache, cachedTablet.getExtent()); // do not add to cache unless lock is held - if (lcSession.checkLock(tabletLocation) == null) { + if (lcSession.checkLock(cachedTablet) == null) { return; } // add it to cache - Text er = tabletLocation.getExtent().endRow(); + Text er = cachedTablet.getExtent().endRow(); if (er == null) { er = MAX_TEXT; } - metaCache.put(er, tabletLocation); + metaCache.put(er, cachedTablet); if (!badExtents.isEmpty()) { - removeOverlapping(badExtents, tabletLocation.getExtent()); + removeOverlapping(badExtents, cachedTablet.getExtent()); } } - static void removeOverlapping(TreeMap<Text,TabletLocation> metaCache, KeyExtent nke) { - Iterator<Entry<Text,TabletLocation>> iter; + static void removeOverlapping(TreeMap<Text,CachedTablet> metaCache, KeyExtent nke) { + Iterator<Entry<Text,CachedTablet>> iter; if (nke.prevEndRow() == null) { iter = metaCache.entrySet().iterator(); } else { Text row = rowAfterPrevRow(nke); - SortedMap<Text,TabletLocation> tailMap = metaCache.tailMap(row); + SortedMap<Text,CachedTablet> tailMap = metaCache.tailMap(row); iter = tailMap.entrySet().iterator(); } while (iter.hasNext()) { - Entry<Text,TabletLocation> entry = iter.next(); + Entry<Text,CachedTablet> entry = iter.next(); KeyExtent ke = entry.getValue().getExtent(); @@ -765,9 +764,9 @@ public class TabletLocatorImpl extends TabletLocator { } } - private TabletLocation locateTabletInCache(Text row) { + private CachedTablet findTabletInCache(Text row) { - Entry<Text,TabletLocation> entry = metaCache.ceilingEntry(row); + Entry<Text,CachedTablet> entry = metaCache.ceilingEntry(row); if (entry != null) { KeyExtent ke = entry.getValue().getExtent(); @@ -778,7 +777,7 @@ public class TabletLocatorImpl extends TabletLocator { return null; } - protected TabletLocation _locateTablet(ClientContext context, Text row, boolean skipRow, + protected CachedTablet _findTablet(ClientContext context, Text row, boolean skipRow, boolean retry, boolean lock, LockCheckerSession lcSession, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { @@ -787,7 +786,7 @@ public class TabletLocatorImpl extends TabletLocator { row.append(new byte[] {0}, 0, 1); } - TabletLocation tl; + CachedTablet tl; if (lock) { rLock.lock(); @@ -818,18 +817,18 @@ public class TabletLocatorImpl extends TabletLocator { return tl; } - private TabletLocation lookupTabletLocationAndCheckLock(ClientContext context, Text row, + private CachedTablet lookupTabletLocationAndCheckLock(ClientContext context, Text row, boolean retry, LockCheckerSession lcSession) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - lookupTabletLocation(context, row, retry, lcSession); - return lcSession.checkLock(locateTabletInCache(row)); + lookupTablet(context, row, retry, lcSession); + return lcSession.checkLock(findTabletInCache(row)); } - private TabletLocation processInvalidatedAndCheckLock(ClientContext context, + private CachedTablet processInvalidatedAndCheckLock(ClientContext context, LockCheckerSession lcSession, Text row) throws AccumuloSecurityException, AccumuloException, TableNotFoundException { processInvalidated(context, lcSession); - return lcSession.checkLock(locateTabletInCache(row)); + return lcSession.checkLock(findTabletInCache(row)); } @SuppressFBWarnings(value = {"UL_UNRELEASED_LOCK", "UL_UNRELEASED_LOCK_EXCEPTION_PATH"}, @@ -862,7 +861,7 @@ public class TabletLocatorImpl extends TabletLocator { Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>(); - parent.locateTablets(context, lookups, + parent.findTablets(context, lookups, (cachedTablet, range) -> addRange(binnedRanges, cachedTablet, range), LocationNeed.REQUIRED); @@ -871,11 +870,11 @@ public class TabletLocatorImpl extends TabletLocator { Collections.shuffle(tabletServers); for (String tserver : tabletServers) { - List<TabletLocation> locations = - locationObtainer.lookupTablets(context, tserver, binnedRanges.get(tserver), parent); + List<CachedTablet> locations = + tabletObtainer.lookupTablets(context, tserver, binnedRanges.get(tserver), parent); - for (TabletLocation tabletLocation : locations) { - updateCache(tabletLocation, lcSession); + for (CachedTablet cachedTablet : locations) { + updateCache(cachedTablet, lcSession); } } } finally { @@ -886,7 +885,7 @@ public class TabletLocatorImpl extends TabletLocator { } } - static void addRange(Map<String,Map<KeyExtent,List<Range>>> binnedRanges, TabletLocation ct, + static void addRange(Map<String,Map<KeyExtent,List<Range>>> binnedRanges, CachedTablet ct, Range range) { binnedRanges.computeIfAbsent(ct.getTserverLocation().get(), k -> new HashMap<>()) .computeIfAbsent(ct.getExtent(), k -> new ArrayList<>()).add(range); diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java index 9c25135bab..4df1777d48 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java @@ -49,7 +49,7 @@ import org.apache.accumulo.core.client.ConditionalWriter; import org.apache.accumulo.core.client.ConditionalWriterConfig; import org.apache.accumulo.core.client.Durability; import org.apache.accumulo.core.client.TimedOutException; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletServerMutations; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.TabletServerMutations; import org.apache.accumulo.core.clientImpl.thrift.TInfo; import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; import org.apache.accumulo.core.data.ByteSequence; @@ -97,7 +97,7 @@ public class ConditionalWriterImpl implements ConditionalWriter { private VisibilityEvaluator ve; private Map<Text,Boolean> cache = Collections.synchronizedMap(new LRUMap<>(1000)); private final ClientContext context; - private TabletLocator locator; + private ClientTabletCache locator; private final TableId tableId; private final String tableName; private long timeout; @@ -373,7 +373,7 @@ public class ConditionalWriterImpl implements ConditionalWriter { this.ve = new VisibilityEvaluator(config.getAuthorizations()); this.threadPool = context.threadPools().createScheduledExecutorService( config.getMaxWriteThreads(), this.getClass().getSimpleName(), false); - this.locator = new SyncingTabletLocator(context, tableId); + this.locator = new SyncingClientTabletCache(context, tableId); this.serverQueues = new HashMap<>(); this.tableId = tableId; this.tableName = tableName; diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/RootTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/RootClientTabletCache.java similarity index 80% rename from core/src/main/java/org/apache/accumulo/core/clientImpl/RootTabletLocator.java rename to core/src/main/java/org/apache/accumulo/core/clientImpl/RootClientTabletCache.java index 08ec4c9aa0..048b8bb657 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/RootTabletLocator.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/RootClientTabletCache.java @@ -30,7 +30,7 @@ import java.util.Map; import java.util.function.BiConsumer; import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletServerLockChecker; +import org.apache.accumulo.core.clientImpl.ClientTabletCacheImpl.TabletServerLockChecker; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.dataImpl.KeyExtent; @@ -46,41 +46,41 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Preconditions; -public class RootTabletLocator extends TabletLocator { +public class RootClientTabletCache extends ClientTabletCache { private final TabletServerLockChecker lockChecker; - RootTabletLocator(TabletServerLockChecker lockChecker) { + RootClientTabletCache(TabletServerLockChecker lockChecker) { this.lockChecker = lockChecker; } @Override public <T extends Mutation> void binMutations(ClientContext context, List<T> mutations, Map<String,TabletServerMutations<T>> binnedMutations, List<T> failures) { - TabletLocation rootTabletLocation = getRootTabletLocation(context); - if (rootTabletLocation != null) { - var tsm = new TabletServerMutations<T>(rootTabletLocation.getTserverSession().get()); + CachedTablet rootCachedTablet = getRootTabletLocation(context); + if (rootCachedTablet != null) { + var tsm = new TabletServerMutations<T>(rootCachedTablet.getTserverSession().get()); for (T mutation : mutations) { tsm.addMutation(RootTable.EXTENT, mutation); } - binnedMutations.put(rootTabletLocation.getTserverLocation().get(), tsm); + binnedMutations.put(rootCachedTablet.getTserverLocation().get(), tsm); } else { failures.addAll(mutations); } } @Override - public List<Range> locateTablets(ClientContext context, List<Range> ranges, - BiConsumer<TabletLocation,Range> rangeConsumer, LocationNeed locationNeed) { + public List<Range> findTablets(ClientContext context, List<Range> ranges, + BiConsumer<CachedTablet,Range> rangeConsumer, LocationNeed locationNeed) { // only expect the hosted case so this code only handles that, so throw an exception is // something else is seen Preconditions.checkArgument(locationNeed == LocationNeed.REQUIRED); - TabletLocation rootTabletLocation = getRootTabletLocation(context); - if (rootTabletLocation != null) { + CachedTablet rootCachedTablet = getRootTabletLocation(context); + if (rootCachedTablet != null) { for (Range range : ranges) { - rangeConsumer.accept(rootTabletLocation, range); + rangeConsumer.accept(rootCachedTablet, range); } return Collections.emptyList(); } @@ -103,7 +103,7 @@ public class RootTabletLocator extends TabletLocator { @Override public void invalidateCache() {} - protected TabletLocation getRootTabletLocation(ClientContext context) { + protected CachedTablet getRootTabletLocation(ClientContext context) { Logger log = LoggerFactory.getLogger(this.getClass()); OpTimer timer = null; @@ -130,20 +130,20 @@ public class RootTabletLocator extends TabletLocator { String server = loc.getHostPort(); if (lockChecker.isLockHeld(server, loc.getSession())) { - return new TabletLocation(RootTable.EXTENT, server, loc.getSession()); + return new CachedTablet(RootTable.EXTENT, server, loc.getSession()); } else { return null; } } @Override - public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, + public CachedTablet findTablet(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) { // only expect the hosted case so this code only handles that, so throw an exception is // something else is seen Preconditions.checkArgument(locationNeed == LocationNeed.REQUIRED); - TabletLocation location = getRootTabletLocation(context); + CachedTablet location = getRootTabletLocation(context); // Always retry when finding the root tablet while (location == null) { sleepUninterruptibly(500, MILLISECONDS); diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/SyncingTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/SyncingClientTabletCache.java similarity index 78% rename from core/src/main/java/org/apache/accumulo/core/clientImpl/SyncingTabletLocator.java rename to core/src/main/java/org/apache/accumulo/core/clientImpl/SyncingClientTabletCache.java index 217d6d087a..20177b9f4f 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/SyncingTabletLocator.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/SyncingClientTabletCache.java @@ -38,22 +38,22 @@ import org.apache.hadoop.io.Text; * will automatically get the most up-to-date version. Caching TabletLocators locally is safe when * using SyncingTabletLocator. */ -public class SyncingTabletLocator extends TabletLocator { +public class SyncingClientTabletCache extends ClientTabletCache { - private volatile TabletLocator locator; - private final Supplier<TabletLocator> getLocatorFunction; + private volatile ClientTabletCache locator; + private final Supplier<ClientTabletCache> getLocatorFunction; - public SyncingTabletLocator(Supplier<TabletLocator> getLocatorFunction) { + public SyncingClientTabletCache(Supplier<ClientTabletCache> getLocatorFunction) { this.getLocatorFunction = getLocatorFunction; this.locator = getLocatorFunction.get(); } - public SyncingTabletLocator(final ClientContext context, final TableId tableId) { - this(() -> TabletLocator.getLocator(context, tableId)); + public SyncingClientTabletCache(final ClientContext context, final TableId tableId) { + this(() -> ClientTabletCache.getInstance(context, tableId)); } - private TabletLocator syncLocator() { - TabletLocator loc = this.locator; + private ClientTabletCache syncLocator() { + ClientTabletCache loc = this.locator; if (!loc.isValid()) { synchronized (this) { if (locator == loc) { @@ -65,10 +65,10 @@ public class SyncingTabletLocator extends TabletLocator { } @Override - public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, + public CachedTablet findTablet(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - return syncLocator().locateTablet(context, row, skipRow, locationNeed); + return syncLocator().findTablet(context, row, skipRow, locationNeed); } @Override @@ -79,10 +79,10 @@ public class SyncingTabletLocator extends TabletLocator { } @Override - public List<Range> locateTablets(ClientContext context, List<Range> ranges, - BiConsumer<TabletLocation,Range> rangeConsumer, LocationNeed locationNeed) + public List<Range> findTablets(ClientContext context, List<Range> ranges, + BiConsumer<CachedTablet,Range> rangeConsumer, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { - return syncLocator().locateTablets(context, ranges, rangeConsumer, locationNeed); + return syncLocator().findTablets(context, ranges, rangeConsumer, locationNeed); } @Override diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java index aef78b1c26..3b80dd9c3f 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java @@ -95,8 +95,8 @@ import org.apache.accumulo.core.client.admin.compaction.CompactionSelector; import org.apache.accumulo.core.client.sample.SamplerConfiguration; import org.apache.accumulo.core.client.summary.SummarizerConfiguration; import org.apache.accumulo.core.client.summary.Summary; -import org.apache.accumulo.core.clientImpl.TabletLocator.LocationNeed; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.LocationNeed; import org.apache.accumulo.core.clientImpl.bulk.BulkImport; import org.apache.accumulo.core.clientImpl.thrift.ClientService.Client; import org.apache.accumulo.core.clientImpl.thrift.TDiskUsage; @@ -547,7 +547,7 @@ public class TableOperationsImpl extends TableOperationsHelper { private void addSplits(SplitEnv env, SortedSet<Text> partitionKeys) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, AccumuloServerException { - TabletLocator tabLocator = TabletLocator.getLocator(context, env.tableId); + ClientTabletCache tabLocator = ClientTabletCache.getInstance(context, env.tableId); for (Text split : partitionKeys) { boolean successful = false; int attempt = 0; @@ -561,7 +561,7 @@ public class TableOperationsImpl extends TableOperationsHelper { attempt++; - TabletLocation tl = tabLocator.locateTablet(context, split, false, LocationNeed.REQUIRED); + CachedTablet tl = tabLocator.findTablet(context, split, false, LocationNeed.REQUIRED); if (tl == null) { context.requireTableExists(env.tableId, env.tableName); @@ -1243,7 +1243,7 @@ public class TableOperationsImpl extends TableOperationsHelper { Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>(); TableId tableId = context.getTableId(tableName); - TabletLocator tl = TabletLocator.getLocator(context, tableId); + ClientTabletCache tl = ClientTabletCache.getInstance(context, tableId); // its possible that the cache could contain complete, but old information about a tables // tablets... so clear it tl.invalidateCache(); @@ -1538,7 +1538,8 @@ public class TableOperationsImpl extends TableOperationsHelper { public void clearLocatorCache(String tableName) throws TableNotFoundException { EXISTING_TABLE_NAME.validate(tableName); - TabletLocator tabLocator = TabletLocator.getLocator(context, context.getTableId(tableName)); + ClientTabletCache tabLocator = + ClientTabletCache.getInstance(context, context.getTableId(tableName)); tabLocator.invalidateCache(); } @@ -1939,7 +1940,7 @@ public class TableOperationsImpl extends TableOperationsHelper { requireNonNull(ranges, "ranges must be non null"); TableId tableId = context.getTableId(tableName); - TabletLocator locator = TabletLocator.getLocator(context, tableId); + ClientTabletCache locator = ClientTabletCache.getInstance(context, tableId); List<Range> rangeList = null; if (ranges instanceof List) { diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java index 7996db9583..f7a713cef3 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchReaderIterator.java @@ -50,7 +50,7 @@ import org.apache.accumulo.core.client.ScannerBase.ConsistencyLevel; import org.apache.accumulo.core.client.TableDeletedException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TimedOutException; -import org.apache.accumulo.core.clientImpl.TabletLocator.LocationNeed; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.LocationNeed; import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; import org.apache.accumulo.core.data.Column; import org.apache.accumulo.core.data.Key; @@ -113,7 +113,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value private Set<String> timedoutServers; private final long retryTimeout; - private TabletLocator locator; + private ClientTabletCache locator; private ScanServerAttemptsImpl scanAttempts = new ScanServerAttemptsImpl(); @@ -134,7 +134,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value this.options = new ScannerOptions(scannerOptions); resultsQueue = new ArrayBlockingQueue<>(numThreads); - this.locator = new TimeoutTabletLocator(retryTimeout, context, tableId); + this.locator = new TimeoutClientTabletCache(retryTimeout, context, tableId); timeoutTrackers = Collections.synchronizedMap(new HashMap<>()); timedoutServers = Collections.synchronizedSet(new HashSet<>()); @@ -246,7 +246,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value doLookups(binnedRanges, receiver, columns, ssd); } - private ScanServerData binRanges(TabletLocator tabletLocator, List<Range> ranges, + private ScanServerData binRanges(ClientTabletCache clientTabletCache, List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> binnedRanges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { @@ -263,10 +263,10 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value List<Range> failures; if (options.getConsistencyLevel().equals(ConsistencyLevel.IMMEDIATE)) { - failures = tabletLocator.binRanges(context, ranges, binnedRanges); + failures = clientTabletCache.binRanges(context, ranges, binnedRanges); ssd = new ScanServerData(); } else if (options.getConsistencyLevel().equals(ConsistencyLevel.EVENTUAL)) { - ssd = binRangesForScanServers(tabletLocator, ranges, binnedRanges, startTime); + ssd = binRangesForScanServers(clientTabletCache, ranges, binnedRanges, startTime); failures = ssd.failures; } else { throw new IllegalStateException(); @@ -641,8 +641,8 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value } } - private ScanServerData binRangesForScanServers(TabletLocator tabletLocator, List<Range> ranges, - Map<String,Map<KeyExtent,List<Range>>> binnedRanges, long startTime) + private ScanServerData binRangesForScanServers(ClientTabletCache clientTabletCache, + List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> binnedRanges, long startTime) throws AccumuloException, TableNotFoundException, AccumuloSecurityException { ScanServerSelector ecsm = context.getScanServerSelector(); @@ -652,7 +652,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value Set<TabletIdImpl> tabletIds = new HashSet<>(); - List<Range> failures = tabletLocator.locateTablets(context, ranges, (cachedTablet, range) -> { + List<Range> failures = clientTabletCache.findTablets(context, ranges, (cachedTablet, range) -> { if (cachedTablet.getTserverLocation().isPresent()) { extentToTserverMap.put(cachedTablet.getExtent(), cachedTablet.getTserverLocation().get()); } @@ -734,7 +734,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value if (!failures.isEmpty()) { // if there are failures at this point its because tablets are not hosted, so lets attempt to // get them hosted - tabletLocator.locateTablets(context, ranges, (cachedTablet, range) -> {}, + clientTabletCache.findTablets(context, ranges, (cachedTablet, range) -> {}, LocationNeed.REQUIRED); return new ScanServerData(failures); } diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java index c36b0945c0..d9531171d0 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TabletServerBatchWriter.java @@ -53,7 +53,7 @@ import org.apache.accumulo.core.client.TableDeletedException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TableOfflineException; import org.apache.accumulo.core.client.TimedOutException; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletServerMutations; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.TabletServerMutations; import org.apache.accumulo.core.clientImpl.thrift.SecurityErrorCode; import org.apache.accumulo.core.clientImpl.thrift.TInfo; import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; @@ -660,7 +660,7 @@ public class TabletServerBatchWriter implements AutoCloseable { private final ThreadPoolExecutor binningThreadPool; private final Map<String,TabletServerMutations<Mutation>> serversMutations; private final Set<String> queued; - private final Map<TableId,TabletLocator> locators; + private final Map<TableId,ClientTabletCache> locators; public MutationWriter(int numSendThreads) { serversMutations = new HashMap<>(); @@ -673,10 +673,10 @@ public class TabletServerBatchWriter implements AutoCloseable { binningThreadPool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); } - private synchronized TabletLocator getLocator(TableId tableId) { - TabletLocator ret = locators.get(tableId); + private synchronized ClientTabletCache getLocator(TableId tableId) { + ClientTabletCache ret = locators.get(tableId); if (ret == null) { - ret = new TimeoutTabletLocator(timeout, context, tableId); + ret = new TimeoutClientTabletCache(timeout, context, tableId); locators.put(tableId, ret); } @@ -690,7 +690,7 @@ public class TabletServerBatchWriter implements AutoCloseable { Set<Entry<TableId,List<Mutation>>> es = mutationsToProcess.getMutations().entrySet(); for (Entry<TableId,List<Mutation>> entry : es) { tableId = entry.getKey(); - TabletLocator locator = getLocator(tableId); + ClientTabletCache locator = getLocator(tableId); List<Mutation> tableMutations = entry.getValue(); if (tableMutations != null) { diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftScanner.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftScanner.java index 78aba868fe..9d0812872a 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftScanner.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftScanner.java @@ -47,7 +47,7 @@ import org.apache.accumulo.core.client.SampleNotPresentException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TimedOutException; import org.apache.accumulo.core.client.sample.SamplerConfiguration; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; import org.apache.accumulo.core.clientImpl.thrift.TInfo; import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; import org.apache.accumulo.core.conf.Property; @@ -186,9 +186,9 @@ public class ThriftScanner { static class ScanAddress { final String serverAddress; final ServerType serverType; - final TabletLocation tabletInfo; + final CachedTablet tabletInfo; - public ScanAddress(String serverAddress, ServerType serverType, TabletLocation tabletInfo) { + public ScanAddress(String serverAddress, ServerType serverType, CachedTablet tabletInfo) { this.serverAddress = Objects.requireNonNull(serverAddress); this.serverType = Objects.requireNonNull(serverType); this.tabletInfo = Objects.requireNonNull(tabletInfo); @@ -365,7 +365,7 @@ public class ThriftScanner { } private static Optional<ScanAddress> getScanServerAddress(ClientContext context, - ScanState scanState, TabletLocation loc, long timeOut, long startTime) { + ScanState scanState, CachedTablet loc, long timeOut, long startTime) { Preconditions.checkArgument(scanState.runOnScanServer); ScanAddress addr = null; @@ -466,8 +466,8 @@ public class ThriftScanner { ScanAddress addr = null; - var hostingNeed = scanState.runOnScanServer ? TabletLocator.LocationNeed.NOT_REQUIRED - : TabletLocator.LocationNeed.REQUIRED; + var hostingNeed = scanState.runOnScanServer ? ClientTabletCache.LocationNeed.NOT_REQUIRED + : ClientTabletCache.LocationNeed.REQUIRED; while (addr == null) { long currentTime = System.currentTimeMillis(); @@ -475,12 +475,12 @@ public class ThriftScanner { throw new ScanTimedOutException("Failed to locate next server to scan before timeout"); } - TabletLocation loc = null; + CachedTablet loc = null; Span child1 = TraceUtil.startSpan(ThriftScanner.class, "scan::locateTablet"); try (Scope locateSpan = child1.makeCurrent()) { - loc = TabletLocator.getLocator(context, scanState.tableId).locateTablet(context, + loc = ClientTabletCache.getInstance(context, scanState.tableId).findTablet(context, scanState.startRow, scanState.skipStartRow, hostingNeed); if (loc == null) { @@ -540,7 +540,7 @@ public class ThriftScanner { addr = getScanServerAddress(context, scanState, loc, timeOut, startTime).orElse(null); if (addr == null && loc.getTserverLocation().isEmpty()) { // wanted to fall back to tserver but tablet was not hosted so make another loop - hostingNeed = TabletLocator.LocationNeed.REQUIRED; + hostingNeed = ClientTabletCache.LocationNeed.REQUIRED; } } else { addr = new ScanAddress(loc.getTserverLocation().get(), ServerType.TSERVER, loc); @@ -606,7 +606,8 @@ public class ThriftScanner { } lastError = error; - TabletLocator.getLocator(context, scanState.tableId).invalidateCache(addr.getExtent()); + ClientTabletCache.getInstance(context, scanState.tableId) + .invalidateCache(addr.getExtent()); // no need to try the current scan id somewhere else scanState.scanID = null; @@ -681,7 +682,7 @@ public class ThriftScanner { if (addr.serverType == ServerType.TSERVER) { // only tsever locations are in cache, invalidating a scan server would not find // anything the cache - TabletLocator.getLocator(context, scanState.tableId).invalidateCache(context, + ClientTabletCache.getInstance(context, scanState.tableId).invalidateCache(context, addr.serverAddress); } error = "Scan failed, thrift error " + e.getClass().getName() + " " + e.getMessage() diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/TimeoutTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/TimeoutClientTabletCache.java similarity index 90% rename from core/src/main/java/org/apache/accumulo/core/clientImpl/TimeoutTabletLocator.java rename to core/src/main/java/org/apache/accumulo/core/clientImpl/TimeoutClientTabletCache.java index e8497d89ad..0acd743e76 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/TimeoutTabletLocator.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/TimeoutClientTabletCache.java @@ -37,7 +37,7 @@ import org.apache.hadoop.io.Text; * <p> * This class is safe to cache locally. */ -public class TimeoutTabletLocator extends SyncingTabletLocator { +public class TimeoutClientTabletCache extends SyncingClientTabletCache { private long timeout; private Long firstFailTime = null; @@ -54,17 +54,17 @@ public class TimeoutTabletLocator extends SyncingTabletLocator { firstFailTime = null; } - public TimeoutTabletLocator(long timeout, final ClientContext context, final TableId table) { + public TimeoutClientTabletCache(long timeout, final ClientContext context, final TableId table) { super(context, table); this.timeout = timeout; } @Override - public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, + public CachedTablet findTablet(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { try { - TabletLocation ret = super.locateTablet(context, row, skipRow, locationNeed); + CachedTablet ret = super.findTablet(context, row, skipRow, locationNeed); if (ret == null) { failed(); diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/Writer.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/Writer.java index 9fa03c10b5..14a7b1797b 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/Writer.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/Writer.java @@ -26,8 +26,8 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.TableNotFoundException; -import org.apache.accumulo.core.clientImpl.TabletLocator.LocationNeed; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.LocationNeed; import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.TableId; @@ -90,7 +90,7 @@ public class Writer { } while (true) { - TabletLocation tabLoc = TabletLocator.getLocator(context, tableId).locateTablet(context, + CachedTablet tabLoc = ClientTabletCache.getInstance(context, tableId).findTablet(context, new Text(m.getRow()), false, LocationNeed.REQUIRED); if (tabLoc == null) { @@ -105,15 +105,15 @@ public class Writer { return; } catch (NotServingTabletException e) { log.trace("Not serving tablet, server = {}", parsedLocation); - TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.getExtent()); + ClientTabletCache.getInstance(context, tableId).invalidateCache(tabLoc.getExtent()); } catch (ConstraintViolationException cve) { log.error("error sending update to {}", parsedLocation, cve); // probably do not need to invalidate cache, but it does not hurt - TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.getExtent()); + ClientTabletCache.getInstance(context, tableId).invalidateCache(tabLoc.getExtent()); throw cve; } catch (TException e) { log.error("error sending update to {}", parsedLocation, e); - TabletLocator.getLocator(context, tableId).invalidateCache(tabLoc.getExtent()); + ClientTabletCache.getInstance(context, tableId).invalidateCache(tabLoc.getExtent()); } sleepUninterruptibly(500, MILLISECONDS); diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/ZookeeperLockChecker.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ZookeeperLockChecker.java index 39c7cecf53..a908e12ea6 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ZookeeperLockChecker.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ZookeeperLockChecker.java @@ -19,7 +19,7 @@ package org.apache.accumulo.core.clientImpl; import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletServerLockChecker; +import org.apache.accumulo.core.clientImpl.ClientTabletCacheImpl.TabletServerLockChecker; import org.apache.accumulo.core.fate.zookeeper.ZooCache; import org.apache.accumulo.core.lock.ServiceLock; diff --git a/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java b/core/src/main/java/org/apache/accumulo/core/metadata/MetadataCachedTabletObtainer.java similarity index 87% rename from core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java rename to core/src/main/java/org/apache/accumulo/core/metadata/MetadataCachedTabletObtainer.java index a2686d95e8..d79a5ba238 100644 --- a/core/src/main/java/org/apache/accumulo/core/metadata/MetadataLocationObtainer.java +++ b/core/src/main/java/org/apache/accumulo/core/metadata/MetadataCachedTabletObtainer.java @@ -38,11 +38,11 @@ import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.clientImpl.AccumuloServerException; import org.apache.accumulo.core.clientImpl.ClientContext; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablets; +import org.apache.accumulo.core.clientImpl.ClientTabletCacheImpl.CachedTabletObtainer; import org.apache.accumulo.core.clientImpl.ScannerOptions; -import org.apache.accumulo.core.clientImpl.TabletLocator; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocations; -import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletLocationObtainer; import org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator; import org.apache.accumulo.core.clientImpl.TabletServerBatchReaderIterator.ResultReceiver; import org.apache.accumulo.core.clientImpl.ThriftScanner; @@ -64,13 +64,13 @@ import org.apache.hadoop.io.Text; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class MetadataLocationObtainer implements TabletLocationObtainer { - private static final Logger log = LoggerFactory.getLogger(MetadataLocationObtainer.class); +public class MetadataCachedTabletObtainer implements CachedTabletObtainer { + private static final Logger log = LoggerFactory.getLogger(MetadataCachedTabletObtainer.class); private SortedSet<Column> locCols; private ArrayList<Column> columns; - public MetadataLocationObtainer() { + public MetadataCachedTabletObtainer() { locCols = new TreeSet<>(); locCols.add(new Column(TextUtil.getBytes(CurrentLocationColumnFamily.NAME), null, null)); @@ -79,8 +79,8 @@ public class MetadataLocationObtainer implements TabletLocationObtainer { } @Override - public TabletLocations lookupTablet(ClientContext context, TabletLocation src, Text row, - Text stopRow, TabletLocator parent) throws AccumuloSecurityException, AccumuloException { + public CachedTablets lookupTablet(ClientContext context, CachedTablet src, Text row, Text stopRow, + ClientTabletCache parent) throws AccumuloSecurityException, AccumuloException { try { @@ -130,7 +130,7 @@ public class MetadataLocationObtainer implements TabletLocationObtainer { // if (log.isTraceEnabled()) log.trace("results "+results); - return MetadataLocationObtainer.getMetadataLocationEntries(results); + return MetadataCachedTabletObtainer.getMetadataLocationEntries(results); } catch (AccumuloServerException ase) { if (log.isTraceEnabled()) { @@ -169,8 +169,8 @@ public class MetadataLocationObtainer implements TabletLocationObtainer { } @Override - public List<TabletLocation> lookupTablets(ClientContext context, String tserver, - Map<KeyExtent,List<Range>> tabletsRanges, TabletLocator parent) + public List<CachedTablet> lookupTablets(ClientContext context, String tserver, + Map<KeyExtent,List<Range>> tabletsRanges, ClientTabletCache parent) throws AccumuloSecurityException, AccumuloException { final TreeMap<Key,Value> results = new TreeMap<>(); @@ -210,14 +210,14 @@ public class MetadataLocationObtainer implements TabletLocationObtainer { throw e; } - return MetadataLocationObtainer.getMetadataLocationEntries(results).getLocations(); + return MetadataCachedTabletObtainer.getMetadataLocationEntries(results).getCachedTablets(); } - public static TabletLocations getMetadataLocationEntries(SortedMap<Key,Value> entries) { + public static CachedTablets getMetadataLocationEntries(SortedMap<Key,Value> entries) { Text location = null; Text session = null; - List<TabletLocation> results = new ArrayList<>(); + List<CachedTablet> results = new ArrayList<>(); Text lastRowFromKey = new Text(); @@ -249,14 +249,14 @@ public class MetadataLocationObtainer implements TabletLocationObtainer { } else if (TabletColumnFamily.PREV_ROW_COLUMN.equals(colf, colq)) { KeyExtent ke = KeyExtent.fromMetaPrevRow(entry); if (location != null) { - results.add(new TabletLocation(ke, location.toString(), session.toString())); + results.add(new CachedTablet(ke, location.toString(), session.toString())); } else { - results.add(new TabletLocation(ke)); + results.add(new CachedTablet(ke)); } location = null; } } - return new TabletLocations(results); + return new CachedTablets(results); } } diff --git a/core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java b/core/src/test/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImplTest.java similarity index 87% rename from core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java rename to core/src/test/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImplTest.java index 2ffd84ae17..b05299e382 100644 --- a/core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java +++ b/core/src/test/java/org/apache/accumulo/core/clientImpl/ClientTabletCacheImplTest.java @@ -40,12 +40,12 @@ import java.util.TreeMap; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.admin.TableOperations; -import org.apache.accumulo.core.clientImpl.TabletLocator.LocationNeed; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocations; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletServerMutations; -import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletLocationObtainer; -import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletServerLockChecker; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablets; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.LocationNeed; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.TabletServerMutations; +import org.apache.accumulo.core.clientImpl.ClientTabletCacheImpl.CachedTabletObtainer; +import org.apache.accumulo.core.clientImpl.ClientTabletCacheImpl.TabletServerLockChecker; import org.apache.accumulo.core.data.InstanceId; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Mutation; @@ -54,7 +54,7 @@ import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.TableId; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.dataImpl.KeyExtent; -import org.apache.accumulo.core.metadata.MetadataLocationObtainer; +import org.apache.accumulo.core.metadata.MetadataCachedTabletObtainer; import org.apache.accumulo.core.metadata.MetadataTable; import org.apache.accumulo.core.metadata.RootTable; import org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.CurrentLocationColumnFamily; @@ -65,7 +65,7 @@ import org.easymock.EasyMock; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class TabletLocatorImplTest { +public class ClientTabletCacheImplTest { private static final KeyExtent ROOT_TABLE_EXTENT = RootTable.EXTENT; private static final KeyExtent METADATA_TABLE_EXTENT = @@ -130,26 +130,26 @@ public class TabletLocatorImplTest { return expBinnedRanges; } - static TreeMap<KeyExtent,TabletLocation> createMetaCacheKE(Object... data) { - TreeMap<KeyExtent,TabletLocation> mcke = new TreeMap<>(); + static TreeMap<KeyExtent,CachedTablet> createMetaCacheKE(Object... data) { + TreeMap<KeyExtent,CachedTablet> mcke = new TreeMap<>(); for (int i = 0; i < data.length; i += 2) { KeyExtent ke = (KeyExtent) data[i]; String loc = (String) data[i + 1]; - mcke.put(ke, new TabletLocation(ke, loc, "1")); + mcke.put(ke, new CachedTablet(ke, loc, "1")); } return mcke; } - static TreeMap<Text,TabletLocation> createMetaCache(Object... data) { - TreeMap<KeyExtent,TabletLocation> mcke = createMetaCacheKE(data); + static TreeMap<Text,CachedTablet> createMetaCache(Object... data) { + TreeMap<KeyExtent,CachedTablet> mcke = createMetaCacheKE(data); - TreeMap<Text,TabletLocation> mc = new TreeMap<>(TabletLocatorImpl.END_ROW_COMPARATOR); + TreeMap<Text,CachedTablet> mc = new TreeMap<>(ClientTabletCacheImpl.END_ROW_COMPARATOR); - for (Entry<KeyExtent,TabletLocation> entry : mcke.entrySet()) { + for (Entry<KeyExtent,CachedTablet> entry : mcke.entrySet()) { if (entry.getKey().endRow() == null) { - mc.put(TabletLocatorImpl.MAX_TEXT, entry.getValue()); + mc.put(ClientTabletCacheImpl.MAX_TEXT, entry.getValue()); } else { mc.put(entry.getKey().endRow(), entry.getValue()); } @@ -158,24 +158,24 @@ public class TabletLocatorImplTest { return mc; } - static TabletLocatorImpl createLocators(TServers tservers, String rootTabLoc, String metaTabLoc, - String table, TabletServerLockChecker tslc, Object... data) { + static ClientTabletCacheImpl createLocators(TServers tservers, String rootTabLoc, + String metaTabLoc, String table, TabletServerLockChecker tslc, Object... data) { - TreeMap<KeyExtent,TabletLocation> mcke = createMetaCacheKE(data); + TreeMap<KeyExtent,CachedTablet> mcke = createMetaCacheKE(data); - TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers); + TestCachedTabletObtainer ttlo = new TestCachedTabletObtainer(tservers); - RootTabletLocator rtl = new TestRootTabletLocator(); - TabletLocatorImpl rootTabletCache = - new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab1TabletCache = - new TabletLocatorImpl(TableId.of(table), rootTabletCache, ttlo, tslc); + RootClientTabletCache rtl = new TestRootClientTabletCache(); + ClientTabletCacheImpl rootTabletCache = + new ClientTabletCacheImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); + ClientTabletCacheImpl tab1TabletCache = + new ClientTabletCacheImpl(TableId.of(table), rootTabletCache, ttlo, tslc); // disable hosting requests for these tests tab1TabletCache.enableTabletHostingRequests(false); setLocation(tservers, rootTabLoc, ROOT_TABLE_EXTENT, METADATA_TABLE_EXTENT, metaTabLoc); - for (Entry<KeyExtent,TabletLocation> entry : mcke.entrySet()) { + for (Entry<KeyExtent,CachedTablet> entry : mcke.entrySet()) { setLocation(tservers, metaTabLoc, METADATA_TABLE_EXTENT, entry.getKey(), entry.getValue().getTserverLocation().get()); } @@ -184,12 +184,12 @@ public class TabletLocatorImplTest { } - static TabletLocatorImpl createLocators(TServers tservers, String rootTabLoc, String metaTabLoc, - String table, Object... data) { + static ClientTabletCacheImpl createLocators(TServers tservers, String rootTabLoc, + String metaTabLoc, String table, Object... data) { return createLocators(tservers, rootTabLoc, metaTabLoc, table, new YesLockChecker(), data); } - static TabletLocatorImpl createLocators(String table, Object... data) { + static ClientTabletCacheImpl createLocators(String table, Object... data) { TServers tservers = new TServers(); return createLocators(tservers, "tserver1", "tserver2", table, data); } @@ -219,13 +219,13 @@ public class TabletLocatorImplTest { replay(context, tops); } - private void runTest(List<Range> ranges, TabletLocatorImpl tab1TabletCache, + private void runTest(List<Range> ranges, ClientTabletCacheImpl tab1TabletCache, Map<String,Map<KeyExtent,List<Range>>> expected) throws Exception { List<Range> failures = Collections.emptyList(); runTest(ranges, tab1TabletCache, expected, failures); } - private void runTest(List<Range> ranges, TabletLocatorImpl tab1TabletCache, + private void runTest(List<Range> ranges, ClientTabletCacheImpl tab1TabletCache, Map<String,Map<KeyExtent,List<Range>>> expected, List<Range> efailures) throws Exception { Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>(); @@ -246,16 +246,16 @@ public class TabletLocatorImplTest { return keyExtentSet; } - static void runTest(TreeMap<Text,TabletLocation> metaCache, KeyExtent remove, + static void runTest(TreeMap<Text,CachedTablet> metaCache, KeyExtent remove, Set<KeyExtent> expected) { // copy so same metaCache can be used for multiple test metaCache = new TreeMap<>(metaCache); - TabletLocatorImpl.removeOverlapping(metaCache, remove); + ClientTabletCacheImpl.removeOverlapping(metaCache, remove); HashSet<KeyExtent> eic = new HashSet<>(); - for (TabletLocation tl : metaCache.values()) { + for (CachedTablet tl : metaCache.values()) { eic.add(tl.getExtent()); } @@ -279,7 +279,7 @@ public class TabletLocatorImplTest { return List.of(ma); } - private void runTest(TabletLocatorImpl metaCache, List<Mutation> ml, + private void runTest(ClientTabletCacheImpl metaCache, List<Mutation> ml, Map<String,Map<KeyExtent,List<String>>> emb, String... efailures) throws Exception { Map<String,TabletServerMutations<Mutation>> binnedMutations = new HashMap<>(); List<Mutation> afailures = new ArrayList<>(); @@ -358,7 +358,7 @@ public class TabletLocatorImplTest { @Test public void testRemoveOverlapping1() { - TreeMap<Text,TabletLocation> mc = createMetaCache(createNewKeyExtent("0", null, null), "l1"); + TreeMap<Text,CachedTablet> mc = createMetaCache(createNewKeyExtent("0", null, null), "l1"); runTest(mc, createNewKeyExtent("0", "a", null), createNewKeyExtentSet()); runTest(mc, createNewKeyExtent("0", null, null), createNewKeyExtentSet()); @@ -428,7 +428,7 @@ public class TabletLocatorImplTest { public void testRemoveOverlapping2() { // test removes when cache does not contain all tablets in a table - TreeMap<Text,TabletLocation> mc = createMetaCache(createNewKeyExtent("0", "r", "g"), "l1", + TreeMap<Text,CachedTablet> mc = createMetaCache(createNewKeyExtent("0", "r", "g"), "l1", createNewKeyExtent("0", null, "r"), "l1"); runTest(mc, createNewKeyExtent("0", "a", null), createNewKeyExtentSet( @@ -493,17 +493,17 @@ public class TabletLocatorImplTest { private final Map<String,Map<KeyExtent,SortedMap<Key,Value>>> tservers = new HashMap<>(); } - static class TestTabletLocationObtainer implements TabletLocationObtainer { + static class TestCachedTabletObtainer implements CachedTabletObtainer { private final Map<String,Map<KeyExtent,SortedMap<Key,Value>>> tservers; - TestTabletLocationObtainer(TServers tservers) { + TestCachedTabletObtainer(TServers tservers) { this.tservers = tservers.tservers; } @Override - public TabletLocations lookupTablet(ClientContext context, TabletLocation src, Text row, - Text stopRow, TabletLocator parent) { + public CachedTablets lookupTablet(ClientContext context, CachedTablet src, Text row, + Text stopRow, ClientTabletCache parent) { Map<KeyExtent,SortedMap<Key,Value>> tablets = tservers.get(src.getTserverLocation().get()); @@ -527,14 +527,14 @@ public class TabletLocatorImplTest { SortedMap<Key,Value> results = tabletData.tailMap(startKey).headMap(stopKey); - return MetadataLocationObtainer.getMetadataLocationEntries(results); + return MetadataCachedTabletObtainer.getMetadataLocationEntries(results); } @Override - public List<TabletLocation> lookupTablets(ClientContext context, String tserver, - Map<KeyExtent,List<Range>> map, TabletLocator parent) { + public List<CachedTablet> lookupTablets(ClientContext context, String tserver, + Map<KeyExtent,List<Range>> map, ClientTabletCache parent) { - ArrayList<TabletLocation> list = new ArrayList<>(); + ArrayList<CachedTablet> list = new ArrayList<>(); Map<KeyExtent,SortedMap<Key,Value>> tablets = tservers.get(tserver); @@ -579,7 +579,7 @@ public class TabletLocatorImplTest { parent.invalidateCache(failures); } - return MetadataLocationObtainer.getMetadataLocationEntries(results).getLocations(); + return MetadataCachedTabletObtainer.getMetadataLocationEntries(results).getCachedTablets(); } @@ -595,15 +595,15 @@ public class TabletLocatorImplTest { public void invalidateCache(String server) {} } - static class TestRootTabletLocator extends RootTabletLocator { + static class TestRootClientTabletCache extends RootClientTabletCache { - TestRootTabletLocator() { + TestRootClientTabletCache() { super(new YesLockChecker()); } @Override - protected TabletLocation getRootTabletLocation(ClientContext context) { - return new TabletLocation(RootTable.EXTENT, context.getRootTabletLocation(), "1"); + protected CachedTablet getRootTabletLocation(ClientContext context) { + return new CachedTablet(RootTable.EXTENT, context.getRootTabletLocation(), "1"); } @Override @@ -681,9 +681,9 @@ public class TabletLocatorImplTest { } - private void locateTabletTest(TabletLocatorImpl cache, String row, boolean skipRow, + private void locateTabletTest(ClientTabletCacheImpl cache, String row, boolean skipRow, KeyExtent expected, String server, LocationNeed locationNeeded) throws Exception { - TabletLocation tl = cache.locateTablet(context, new Text(row), skipRow, locationNeeded); + CachedTablet tl = cache.findTablet(context, new Text(row), skipRow, locationNeeded); if (expected == null) { if (tl != null) { @@ -702,7 +702,7 @@ public class TabletLocatorImplTest { } } - private void locateTabletTest(TabletLocatorImpl cache, String row, KeyExtent expected, + private void locateTabletTest(ClientTabletCacheImpl cache, String row, KeyExtent expected, String server) throws Exception { locateTabletTest(cache, row, false, expected, server, LocationNeed.REQUIRED); } @@ -710,13 +710,13 @@ public class TabletLocatorImplTest { @Test public void test1() throws Exception { TServers tservers = new TServers(); - TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers); + TestCachedTabletObtainer ttlo = new TestCachedTabletObtainer(tservers); - RootTabletLocator rtl = new TestRootTabletLocator(); - TabletLocatorImpl rootTabletCache = - new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab1TabletCache = - new TabletLocatorImpl(TableId.of("tab1"), rootTabletCache, ttlo, new YesLockChecker()); + RootClientTabletCache rtl = new TestRootClientTabletCache(); + ClientTabletCacheImpl rootTabletCache = + new ClientTabletCacheImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); + ClientTabletCacheImpl tab1TabletCache = + new ClientTabletCacheImpl(TableId.of("tab1"), rootTabletCache, ttlo, new YesLockChecker()); locateTabletTest(tab1TabletCache, "r1", null, null); @@ -874,7 +874,7 @@ public class TabletLocatorImplTest { @Test public void test2() throws Exception { TServers tservers = new TServers(); - TabletLocatorImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo"); + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo"); KeyExtent ke1 = createNewKeyExtent("foo", "m", null); KeyExtent ke2 = createNewKeyExtent("foo", null, "m"); @@ -894,7 +894,7 @@ public class TabletLocatorImplTest { @Test public void testBinRanges1() throws Exception { - TabletLocatorImpl metaCache = + ClientTabletCacheImpl metaCache = createLocators("foo", createNewKeyExtent("foo", null, null), "l1"); List<Range> ranges = createNewRangeList(createNewRange(null, null)); @@ -925,8 +925,8 @@ public class TabletLocatorImplTest { public void testBinRanges2() throws Exception { List<Range> ranges = createNewRangeList(createNewRange(null, null)); - TabletLocatorImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "g", null), "l1", - createNewKeyExtent("foo", null, "g"), "l2"); + ClientTabletCacheImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "g", null), + "l1", createNewKeyExtent("foo", null, "g"), "l2"); Map<String, Map<KeyExtent,List<Range>>> expected = createExpectedBinnings( @@ -943,8 +943,9 @@ public class TabletLocatorImplTest { // test with three tablets and a range that covers the whole table List<Range> ranges = createNewRangeList(createNewRange(null, null)); - TabletLocatorImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "g", null), "l1", - createNewKeyExtent("foo", "m", "g"), "l2", createNewKeyExtent("foo", null, "m"), "l2"); + ClientTabletCacheImpl metaCache = + createLocators("foo", createNewKeyExtent("foo", "g", null), "l1", + createNewKeyExtent("foo", "m", "g"), "l2", createNewKeyExtent("foo", null, "m"), "l2"); Map<String,Map<KeyExtent,List<Range>>> expected = createExpectedBinnings( createRangeLocation("l1", createNewKeyExtent("foo", "g", null), @@ -1016,8 +1017,8 @@ public class TabletLocatorImplTest { public void testBinRanges4() throws Exception { List<Range> ranges = createNewRangeList(new Range(new Text("1"))); - TabletLocatorImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "0", null), "l1", - createNewKeyExtent("foo", "1", "0"), "l2", createNewKeyExtent("foo", "2", "1"), "l3", + ClientTabletCacheImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "0", null), + "l1", createNewKeyExtent("foo", "1", "0"), "l2", createNewKeyExtent("foo", "2", "1"), "l3", createNewKeyExtent("foo", "3", "2"), "l4", createNewKeyExtent("foo", null, "3"), "l5"); Map<String,Map<KeyExtent,List<Range>>> expected = @@ -1078,8 +1079,8 @@ public class TabletLocatorImplTest { // Test binning when there is a hole in the metadata List<Range> ranges = createNewRangeList(new Range(new Text("1"))); - TabletLocatorImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "0", null), "l1", - createNewKeyExtent("foo", "1", "0"), "l2", createNewKeyExtent("foo", "3", "2"), "l4", + ClientTabletCacheImpl metaCache = createLocators("foo", createNewKeyExtent("foo", "0", null), + "l1", createNewKeyExtent("foo", "1", "0"), "l2", createNewKeyExtent("foo", "3", "2"), "l4", createNewKeyExtent("foo", null, "3"), "l5"); Map<String,Map<KeyExtent,List<Range>>> expected1 = @@ -1135,7 +1136,7 @@ public class TabletLocatorImplTest { KeyExtent e3 = createNewKeyExtent("foo", "2", "05"); TServers tservers = new TServers(); - TabletLocatorImpl metaCache = + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo", e1, "l1", e2, "l1"); List<Range> ranges = createNewRangeList(createNewRange("01", "07")); @@ -1180,8 +1181,8 @@ public class TabletLocatorImplTest { KeyExtent e7 = createNewKeyExtent("foo", null, "s"); TServers tservers = new TServers(); - TabletLocatorImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo", e1, "l1", - e2, "l1", e4, "l1", e5, "l1", e7, "l1"); + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo", e1, + "l1", e2, "l1", e4, "l1", e5, "l1", e7, "l1"); Range r1 = createNewRange("art", "cooking"); // overlaps e1 e2 Range r2 = createNewRange("loop", "nope"); // overlaps e4 e5 @@ -1221,43 +1222,43 @@ public class TabletLocatorImplTest { @Test public void testIsContiguous() { - TabletLocation e1 = new TabletLocation(createNewKeyExtent("foo", "1", null), "l1", "1"); - TabletLocation e2 = new TabletLocation(createNewKeyExtent("foo", "2", "1"), "l1", "1"); - TabletLocation e3 = new TabletLocation(createNewKeyExtent("foo", "3", "2"), "l1", "1"); - TabletLocation e4 = new TabletLocation(createNewKeyExtent("foo", null, "3"), "l1", "1"); + CachedTablet e1 = new CachedTablet(createNewKeyExtent("foo", "1", null), "l1", "1"); + CachedTablet e2 = new CachedTablet(createNewKeyExtent("foo", "2", "1"), "l1", "1"); + CachedTablet e3 = new CachedTablet(createNewKeyExtent("foo", "3", "2"), "l1", "1"); + CachedTablet e4 = new CachedTablet(createNewKeyExtent("foo", null, "3"), "l1", "1"); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e1, e2, e3, e4))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e1, e2, e3))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e2, e3, e4))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e2, e3))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e1))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e2))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e4))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e3, e4))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e3))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e2, e3, e4))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e2, e3))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e1))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e2))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e4))); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e1, e2, e4))); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e1, e3, e4))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e4))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e1, e3, e4))); - TabletLocation e5 = new TabletLocation(createNewKeyExtent("foo", null, null), "l1", "1"); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e1, e2, e3, e4, e5))); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e5, e1, e2, e3, e4))); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e1, e2, e3, e5))); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e5, e2, e3, e4))); - assertTrue(TabletLocatorImpl.isContiguous(List.of(e5))); + CachedTablet e5 = new CachedTablet(createNewKeyExtent("foo", null, null), "l1", "1"); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e3, e4, e5))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e5, e1, e2, e3, e4))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e3, e5))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e5, e2, e3, e4))); + assertTrue(ClientTabletCacheImpl.isContiguous(List.of(e5))); - TabletLocation e6 = new TabletLocation(createNewKeyExtent("foo", null, "1"), "l1", "1"); + CachedTablet e6 = new CachedTablet(createNewKeyExtent("foo", null, "1"), "l1", "1"); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e1, e2, e3, e6))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e3, e6))); - TabletLocation e7 = new TabletLocation(createNewKeyExtent("foo", "33", "11"), "l1", "1"); + CachedTablet e7 = new CachedTablet(createNewKeyExtent("foo", "33", "11"), "l1", "1"); - assertFalse(TabletLocatorImpl.isContiguous(List.of(e1, e2, e7, e4))); + assertFalse(ClientTabletCacheImpl.isContiguous(List.of(e1, e2, e7, e4))); } @Test public void testBinMutations1() throws Exception { // one tablet table KeyExtent ke1 = createNewKeyExtent("foo", null, null); - TabletLocatorImpl metaCache = createLocators("foo", ke1, "l1"); + ClientTabletCacheImpl metaCache = createLocators("foo", ke1, "l1"); List<Mutation> ml = createNewMutationList(createNewMutation("a", "cf1:cq1=v1", "cf1:cq2=v2"), createNewMutation("c", "cf1:cq1=v3", "cf1:cq2=v4")); @@ -1280,7 +1281,7 @@ public class TabletLocatorImplTest { @Test public void testBinMutations2() throws Exception { // no tablets for table - TabletLocatorImpl metaCache = createLocators("foo"); + ClientTabletCacheImpl metaCache = createLocators("foo"); List<Mutation> ml = createNewMutationList(createNewMutation("a", "cf1:cq1=v1", "cf1:cq2=v2"), createNewMutation("c", "cf1:cq1=v3", "cf1:cq2=v4")); @@ -1295,7 +1296,7 @@ public class TabletLocatorImplTest { KeyExtent ke2 = createNewKeyExtent("foo", "t", "h"); KeyExtent ke3 = createNewKeyExtent("foo", null, "t"); - TabletLocatorImpl metaCache = createLocators("foo", ke1, "l1", ke2, "l2", ke3, "l3"); + ClientTabletCacheImpl metaCache = createLocators("foo", ke1, "l1", ke2, "l2", ke3, "l3"); List<Mutation> ml = createNewMutationList(createNewMutation("a", "cf1:cq1=v1", "cf1:cq2=v2"), createNewMutation("i", "cf1:cq1=v3", "cf1:cq2=v4")); @@ -1339,7 +1340,7 @@ public class TabletLocatorImplTest { KeyExtent ke3 = createNewKeyExtent("foo", null, "t"); - TabletLocatorImpl metaCache = createLocators("foo", ke1, "l1", ke3, "l3"); + ClientTabletCacheImpl metaCache = createLocators("foo", ke1, "l1", ke3, "l3"); List<Mutation> ml = createNewMutationList(createNewMutation("a", "cf1:cq1=v1", "cf1:cq2=v2"), createNewMutation("i", "cf1:cq1=v3", "cf1:cq2=v4")); @@ -1388,7 +1389,7 @@ public class TabletLocatorImplTest { KeyExtent ke1 = createNewKeyExtent("foo", null, null); TServers tservers = new TServers(); - TabletLocatorImpl metaCache = + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo", ke1, "l1"); List<Mutation> ml = createNewMutationList(createNewMutation("a", "cf1:cq1=v1", "cf1:cq2=v2"), @@ -1460,13 +1461,13 @@ public class TabletLocatorImplTest { KeyExtent mte2 = new KeyExtent(MetadataTable.ID, null, new Text("0;0bc")); TServers tservers = new TServers(); - TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers); + TestCachedTabletObtainer ttlo = new TestCachedTabletObtainer(tservers); - RootTabletLocator rtl = new TestRootTabletLocator(); - TabletLocatorImpl rootTabletCache = - new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab0TabletCache = - new TabletLocatorImpl(TableId.of("0"), rootTabletCache, ttlo, new YesLockChecker()); + RootClientTabletCache rtl = new TestRootClientTabletCache(); + ClientTabletCacheImpl rootTabletCache = + new ClientTabletCacheImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); + ClientTabletCacheImpl tab0TabletCache = + new ClientTabletCacheImpl(TableId.of("0"), rootTabletCache, ttlo, new YesLockChecker()); setLocation(tservers, "tserver1", ROOT_TABLE_EXTENT, mte1, "tserver2"); setLocation(tservers, "tserver1", ROOT_TABLE_EXTENT, mte2, "tserver3"); @@ -1489,13 +1490,13 @@ public class TabletLocatorImplTest { KeyExtent mte2 = new KeyExtent(MetadataTable.ID, null, new Text("~")); TServers tservers = new TServers(); - TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers); + TestCachedTabletObtainer ttlo = new TestCachedTabletObtainer(tservers); - RootTabletLocator rtl = new TestRootTabletLocator(); - TabletLocatorImpl rootTabletCache = - new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab0TabletCache = - new TabletLocatorImpl(TableId.of("0"), rootTabletCache, ttlo, new YesLockChecker()); + RootClientTabletCache rtl = new TestRootClientTabletCache(); + ClientTabletCacheImpl rootTabletCache = + new ClientTabletCacheImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); + ClientTabletCacheImpl tab0TabletCache = + new ClientTabletCacheImpl(TableId.of("0"), rootTabletCache, ttlo, new YesLockChecker()); setLocation(tservers, "tserver1", ROOT_TABLE_EXTENT, mte1, "tserver2"); setLocation(tservers, "tserver1", ROOT_TABLE_EXTENT, mte2, "tserver3"); @@ -1505,7 +1506,7 @@ public class TabletLocatorImplTest { ts3.put(mte2, new TreeMap<>()); tservers.tservers.put("tserver3", ts3); - assertNull(tab0TabletCache.locateTablet(context, new Text("row_0000000000"), false, + assertNull(tab0TabletCache.findTablet(context, new Text("row_0000000000"), false, LocationNeed.REQUIRED)); } @@ -1523,14 +1524,14 @@ public class TabletLocatorImplTest { KeyExtent ke1 = new KeyExtent(TableId.of("1"), null, null); TServers tservers = new TServers(); - TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers); + TestCachedTabletObtainer ttlo = new TestCachedTabletObtainer(tservers); - RootTabletLocator rtl = new TestRootTabletLocator(); + RootClientTabletCache rtl = new TestRootClientTabletCache(); - TabletLocatorImpl rootTabletCache = - new TabletLocatorImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); - TabletLocatorImpl tab0TabletCache = - new TabletLocatorImpl(TableId.of("1"), rootTabletCache, ttlo, new YesLockChecker()); + ClientTabletCacheImpl rootTabletCache = + new ClientTabletCacheImpl(MetadataTable.ID, rtl, ttlo, new YesLockChecker()); + ClientTabletCacheImpl tab0TabletCache = + new ClientTabletCacheImpl(TableId.of("1"), rootTabletCache, ttlo, new YesLockChecker()); setLocation(tservers, "tserver1", ROOT_TABLE_EXTENT, mte1, "tserver2"); setLocation(tservers, "tserver1", ROOT_TABLE_EXTENT, mte2, "tserver3"); @@ -1551,7 +1552,7 @@ public class TabletLocatorImplTest { @Test public void testAccumulo1248() { TServers tservers = new TServers(); - TabletLocatorImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo"); + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo"); KeyExtent ke1 = createNewKeyExtent("foo", null, null); @@ -1562,7 +1563,7 @@ public class TabletLocatorImplTest { setLocation(tservers, "tserver2", METADATA_TABLE_EXTENT, ke1, "L2", "I2"); var e = assertThrows(IllegalStateException.class, - () -> metaCache.locateTablet(context, new Text("a"), false, LocationNeed.REQUIRED)); + () -> metaCache.findTablet(context, new Text("a"), false, LocationNeed.REQUIRED)); assertTrue(e.getMessage().startsWith("Tablet has multiple locations : ")); } @@ -1573,7 +1574,7 @@ public class TabletLocatorImplTest { final HashSet<String> activeLocks = new HashSet<>(); TServers tservers = new TServers(); - TabletLocatorImpl metaCache = + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo", new TabletServerLockChecker() { @Override public boolean isLockHeld(String tserver, String session) { @@ -1715,7 +1716,7 @@ public class TabletLocatorImplTest { // this test caching tablets without a location TServers tservers = new TServers(); - TabletLocatorImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo"); + ClientTabletCacheImpl metaCache = createLocators(tservers, "tserver1", "tserver2", "foo"); var ke1 = createNewKeyExtent("foo", "g", null); var ke2 = createNewKeyExtent("foo", "m", "g"); @@ -1737,19 +1738,19 @@ public class TabletLocatorImplTest { var r2 = new Range("d", "o"); List<Range> ranges = List.of(r1, r2); - Set<Pair<TabletLocation,Range>> actual = new HashSet<>(); - var failures = metaCache.locateTablets(context, ranges, - (tl, r) -> actual.add(new Pair<>(tl, r)), LocationNeed.NOT_REQUIRED); + Set<Pair<CachedTablet,Range>> actual = new HashSet<>(); + var failures = metaCache.findTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), + LocationNeed.NOT_REQUIRED); assertEquals(List.of(), failures); - var tl1 = new TabletLocation(ke1); - var tl2 = new TabletLocation(ke2); - var tl3 = new TabletLocation(ke3, "L2", "I2"); + var tl1 = new CachedTablet(ke1); + var tl2 = new CachedTablet(ke2); + var tl3 = new CachedTablet(ke3, "L2", "I2"); var expected = Set.of(new Pair<>(tl1, r1), new Pair<>(tl1, r2), new Pair<>(tl2, r2), new Pair<>(tl3, r2)); assertEquals(expected, actual); actual.clear(); - failures = metaCache.locateTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), + failures = metaCache.findTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), LocationNeed.REQUIRED); assertEquals(new HashSet<>(ranges), new HashSet<>(failures)); assertEquals(Set.of(), actual); @@ -1767,25 +1768,25 @@ public class TabletLocatorImplTest { // even though the location is set for ke2 the cache should have ke2 w/o a location and that // should be seeen actual.clear(); - failures = metaCache.locateTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), + failures = metaCache.findTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), LocationNeed.NOT_REQUIRED); assertEquals(List.of(), failures); - tl1 = new TabletLocation(ke1, "L3", "I3"); + tl1 = new CachedTablet(ke1, "L3", "I3"); expected = Set.of(new Pair<>(tl1, r1), new Pair<>(tl1, r2), new Pair<>(tl2, r2), new Pair<>(tl3, r2)); assertEquals(expected, actual); // this should cause the location for ke2 to be pulled into the cache actual.clear(); - failures = metaCache.locateTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), + failures = metaCache.findTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), LocationNeed.REQUIRED); assertEquals(List.of(), failures); - tl2 = new TabletLocation(ke2, "L4", "I4"); + tl2 = new CachedTablet(ke2, "L4", "I4"); expected = Set.of(new Pair<>(tl1, r1), new Pair<>(tl1, r2), new Pair<>(tl2, r2), new Pair<>(tl3, r2)); assertEquals(expected, actual); // should still see locations in cache actual.clear(); - failures = metaCache.locateTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), + failures = metaCache.findTablets(context, ranges, (tl, r) -> actual.add(new Pair<>(tl, r)), LocationNeed.NOT_REQUIRED); assertEquals(List.of(), failures); assertEquals(expected, actual); diff --git a/core/src/test/java/org/apache/accumulo/core/clientImpl/RootTabletLocatorTest.java b/core/src/test/java/org/apache/accumulo/core/clientImpl/RootClientTabletCacheTest.java similarity index 89% rename from core/src/test/java/org/apache/accumulo/core/clientImpl/RootTabletLocatorTest.java rename to core/src/test/java/org/apache/accumulo/core/clientImpl/RootClientTabletCacheTest.java index 64f497d030..a50a314bd5 100644 --- a/core/src/test/java/org/apache/accumulo/core/clientImpl/RootTabletLocatorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/clientImpl/RootClientTabletCacheTest.java @@ -24,16 +24,16 @@ import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.clientImpl.TabletLocatorImpl.TabletServerLockChecker; +import org.apache.accumulo.core.clientImpl.ClientTabletCacheImpl.TabletServerLockChecker; import org.apache.accumulo.core.fate.zookeeper.ZooCache; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class RootTabletLocatorTest { +public class RootClientTabletCacheTest { private ClientContext context; private TabletServerLockChecker lockChecker; private ZooCache zc; - private RootTabletLocator rtl; + private RootClientTabletCache rtl; @BeforeEach public void setUp() { @@ -43,7 +43,7 @@ public class RootTabletLocatorTest { expect(context.getZooCache()).andReturn(zc).anyTimes(); replay(context); lockChecker = createMock(TabletServerLockChecker.class); - rtl = new RootTabletLocator(lockChecker); + rtl = new RootClientTabletCache(lockChecker); } @Test diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordReader.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordReader.java index b7d72a4a9d..948865cb6d 100644 --- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordReader.java +++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapred/AccumuloRecordReader.java @@ -46,9 +46,9 @@ import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TableOfflineException; import org.apache.accumulo.core.client.sample.SamplerConfiguration; import org.apache.accumulo.core.clientImpl.ClientContext; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.clientImpl.OfflineScanner; import org.apache.accumulo.core.clientImpl.ScannerImpl; -import org.apache.accumulo.core.clientImpl.TabletLocator; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.TableId; @@ -330,7 +330,7 @@ public abstract class AccumuloRecordReader<K,V> implements RecordReader<K,V> { // get the metadata information for these ranges Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>(); - TabletLocator tl; + ClientTabletCache tl; try { if (tableConfig.isOfflineScan()) { binnedRanges = binOfflineTable(job, tableId, ranges, callingClass); diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordReader.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordReader.java index 90956ccdf1..5d6b3bfa89 100644 --- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordReader.java +++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/AccumuloRecordReader.java @@ -46,9 +46,9 @@ import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TableOfflineException; import org.apache.accumulo.core.client.sample.SamplerConfiguration; import org.apache.accumulo.core.clientImpl.ClientContext; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.clientImpl.OfflineScanner; import org.apache.accumulo.core.clientImpl.ScannerImpl; -import org.apache.accumulo.core.clientImpl.TabletLocator; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.TableId; @@ -362,7 +362,7 @@ public abstract class AccumuloRecordReader<K,V> extends RecordReader<K,V> { // get the metadata information for these ranges Map<String,Map<KeyExtent,List<Range>>> binnedRanges = new HashMap<>(); - TabletLocator tl; + ClientTabletCache tl; try { if (tableConfig.isOfflineScan()) { binnedRanges = binOfflineTable(context, tableId, ranges, callingClass); diff --git a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java index b013aa7565..da89099147 100644 --- a/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java +++ b/hadoop-mapreduce/src/main/java/org/apache/accumulo/hadoopImpl/mapreduce/lib/InputConfigurator.java @@ -53,7 +53,7 @@ import org.apache.accumulo.core.client.ScannerBase.ConsistencyLevel; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.sample.SamplerConfiguration; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.conf.ClientProperty; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.PartialKey; @@ -705,19 +705,19 @@ public class InputConfigurator extends ConfiguratorBase { } /** - * Initializes an Accumulo {@link TabletLocator} based on the configuration. + * Initializes an Accumulo {@link ClientTabletCache} based on the configuration. * * @param implementingClass the class whose name will be used as a prefix for the property * configuration key * @param conf the Hadoop configuration object to configure - * @param tableId The table id for which to initialize the {@link TabletLocator} + * @param tableId The table id for which to initialize the {@link ClientTabletCache} * @return an Accumulo tablet locator * @since 1.6.0 */ - public static TabletLocator getTabletLocator(Class<?> implementingClass, Configuration conf, + public static ClientTabletCache getTabletLocator(Class<?> implementingClass, Configuration conf, TableId tableId) { try (AccumuloClient client = createClient(implementingClass, conf)) { - return TabletLocator.getLocator((ClientContext) client, tableId); + return ClientTabletCache.getInstance((ClientContext) client, tableId); } } 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 53a72341eb..1777c6f71e 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 @@ -40,8 +40,8 @@ import java.util.stream.Collectors; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; import org.apache.accumulo.core.clientImpl.bulk.BulkImport; import org.apache.accumulo.core.clientImpl.thrift.ClientService; import org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException; @@ -128,10 +128,10 @@ public class BulkImporter { Collections.synchronizedSortedMap(new TreeMap<>()); ClientService.Client client = null; - final TabletLocator locator = TabletLocator.getLocator(context, tableId); + final ClientTabletCache locator = ClientTabletCache.getInstance(context, tableId); try { - final Map<Path,List<TabletLocation>> assignments = + final Map<Path,List<CachedTablet>> assignments = Collections.synchronizedSortedMap(new TreeMap<>()); timer.start(Timers.EXAMINE_MAP_FILES); @@ -141,7 +141,7 @@ public class BulkImporter { for (Path path : paths) { final Path mapFile = path; Runnable getAssignments = () -> { - List<TabletLocation> tabletsToAssignMapFileTo = Collections.emptyList(); + List<CachedTablet> tabletsToAssignMapFileTo = Collections.emptyList(); try { tabletsToAssignMapFileTo = findOverlappingTablets(context, fs, locator, mapFile, tableConf.getCryptoService()); @@ -204,7 +204,7 @@ public class BulkImporter { for (Entry<Path,List<KeyExtent>> entry : assignmentFailures.entrySet()) { Iterator<KeyExtent> keListIter = entry.getValue().iterator(); - List<TabletLocation> tabletsToAssignMapFileTo = new ArrayList<>(); + List<CachedTablet> tabletsToAssignMapFileTo = new ArrayList<>(); while (keListIter.hasNext()) { KeyExtent ke = keListIter.next(); @@ -337,16 +337,16 @@ public class BulkImporter { long estSize; } - private static List<KeyExtent> extentsOf(List<TabletLocation> locations) { + private static List<KeyExtent> extentsOf(List<CachedTablet> locations) { List<KeyExtent> result = new ArrayList<>(locations.size()); - for (TabletLocation tl : locations) { + for (CachedTablet tl : locations) { result.add(tl.getExtent()); } return result; } private Map<Path,List<AssignmentInfo>> estimateSizes(final VolumeManager vm, - Map<Path,List<TabletLocation>> assignments, Collection<Path> paths, int numThreads) { + Map<Path,List<CachedTablet>> assignments, Collection<Path> paths, int numThreads) { long t1 = System.currentTimeMillis(); final Map<Path,Long> mapFileSizes = new TreeMap<>(); @@ -366,15 +366,15 @@ public class BulkImporter { ExecutorService threadPool = ThreadPools.getServerThreadPools() .createFixedThreadPool(numThreads, "estimateSizes", false); - for (final Entry<Path,List<TabletLocation>> entry : assignments.entrySet()) { + for (final Entry<Path,List<CachedTablet>> entry : assignments.entrySet()) { if (entry.getValue().size() == 1) { - TabletLocation tabletLocation = entry.getValue().get(0); + CachedTablet cachedTablet = entry.getValue().get(0); // if the tablet completely contains the map file, there is no // need to estimate its // size ais.put(entry.getKey(), Collections.singletonList( - new AssignmentInfo(tabletLocation.getExtent(), mapFileSizes.get(entry.getKey())))); + new AssignmentInfo(cachedTablet.getExtent(), mapFileSizes.get(entry.getKey())))); continue; } @@ -397,7 +397,7 @@ public class BulkImporter { estimatedSizes = new TreeMap<>(); long estSize = (long) (mapFileSizes.get(entry.getKey()) / (double) entry.getValue().size()); - for (TabletLocation tl : entry.getValue()) { + for (CachedTablet tl : entry.getValue()) { estimatedSizes.put(tl.getExtent(), estSize); } } @@ -433,10 +433,10 @@ public class BulkImporter { return ais; } - private static Map<KeyExtent,String> locationsOf(Map<Path,List<TabletLocation>> assignments) { + private static Map<KeyExtent,String> locationsOf(Map<Path,List<CachedTablet>> assignments) { Map<KeyExtent,String> result = new HashMap<>(); - for (List<TabletLocation> entry : assignments.values()) { - for (TabletLocation tl : entry) { + for (List<CachedTablet> entry : assignments.values()) { + for (CachedTablet tl : entry) { result.put(tl.getExtent(), tl.getTserverLocation().get()); } } @@ -444,7 +444,7 @@ public class BulkImporter { } private Map<Path,List<KeyExtent>> assignMapFiles(VolumeManager fs, - Map<Path,List<TabletLocation>> assignments, Collection<Path> paths, int numThreads, + Map<Path,List<CachedTablet>> assignments, Collection<Path> paths, int numThreads, int numMapThreads) { timer.start(Timers.EXAMINE_MAP_FILES); Map<Path,List<AssignmentInfo>> assignInfo = @@ -618,13 +618,13 @@ public class BulkImporter { } } - public static List<TabletLocation> findOverlappingTablets(ServerContext context, VolumeManager fs, - TabletLocator locator, Path file, CryptoService cs) throws Exception { + public static List<CachedTablet> findOverlappingTablets(ServerContext context, VolumeManager fs, + ClientTabletCache locator, Path file, CryptoService cs) throws Exception { return findOverlappingTablets(context, fs, locator, file, null, null, cs); } - public static List<TabletLocation> findOverlappingTablets(ServerContext context, VolumeManager fs, - TabletLocator locator, Path file, KeyExtent failed, CryptoService cs) throws Exception { + public static List<CachedTablet> findOverlappingTablets(ServerContext context, VolumeManager fs, + ClientTabletCache locator, Path file, KeyExtent failed, CryptoService cs) throws Exception { locator.invalidateCache(failed); Text start = getStartRowForExtent(failed); return findOverlappingTablets(context, fs, locator, file, start, failed.endRow(), cs); @@ -643,10 +643,10 @@ public class BulkImporter { static final byte[] byte0 = {0}; - public static List<TabletLocation> findOverlappingTablets(ServerContext context, VolumeManager vm, - TabletLocator locator, Path file, Text startRow, Text endRow, CryptoService cs) + public static List<CachedTablet> findOverlappingTablets(ServerContext context, VolumeManager vm, + ClientTabletCache locator, Path file, Text startRow, Text endRow, CryptoService cs) throws Exception { - List<TabletLocation> result = new ArrayList<>(); + List<CachedTablet> result = new ArrayList<>(); Collection<ByteSequence> columnFamilies = Collections.emptyList(); String filename = file.toString(); // log.debug(filename + " finding overlapping tablets " + startRow + " -> " + endRow); @@ -666,11 +666,11 @@ public class BulkImporter { break; } row = reader.getTopKey().getRow(); - TabletLocation tabletLocation = - locator.locateTabletWithRetry(context, row, false, TabletLocator.LocationNeed.REQUIRED); + CachedTablet cachedTablet = locator.findTabletWithRetry(context, row, false, + ClientTabletCache.LocationNeed.REQUIRED); // log.debug(filename + " found row " + row + " at location " + tabletLocation); - result.add(tabletLocation); - row = tabletLocation.getExtent().endRow(); + result.add(cachedTablet); + row = cachedTablet.getExtent().endRow(); if (row != null && (endRow == null || row.compareTo(endRow) < 0)) { row = new Text(row); row.append(byte0, 0, byte0.length); @@ -694,9 +694,9 @@ public class BulkImporter { numUniqueMapFiles = fileCount; } - void attemptingAssignments(Map<Path,List<TabletLocation>> assignments) { - for (Entry<Path,List<TabletLocation>> entry : assignments.entrySet()) { - for (TabletLocation tl : entry.getValue()) { + void attemptingAssignments(Map<Path,List<CachedTablet>> assignments) { + for (Entry<Path,List<CachedTablet>> entry : assignments.entrySet()) { + for (CachedTablet tl : entry.getValue()) { Integer count = getCount(tl.getExtent()); diff --git a/server/base/src/test/java/org/apache/accumulo/server/client/BulkImporterTest.java b/server/base/src/test/java/org/apache/accumulo/server/client/BulkImporterTest.java index 576a97c435..e9f9c072e0 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/client/BulkImporterTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/client/BulkImporterTest.java @@ -31,8 +31,8 @@ import java.util.TreeSet; import java.util.function.BiConsumer; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; -import org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; +import org.apache.accumulo.core.clientImpl.ClientTabletCache.CachedTablet; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Range; @@ -67,13 +67,13 @@ public class BulkImporterTest { fakeMetaData.add(new KeyExtent(tableId, null, fakeMetaData.last().endRow())); } - class MockTabletLocator extends TabletLocator { + class MockClientTabletCache extends ClientTabletCache { int invalidated = 0; @Override - public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, + public CachedTablet findTablet(ClientContext context, Text row, boolean skipRow, LocationNeed locationNeed) { - return new TabletLocation(fakeMetaData.tailSet(new KeyExtent(tableId, row, null)).first(), + return new CachedTablet(fakeMetaData.tailSet(new KeyExtent(tableId, row, null)).first(), "localhost", "1"); } @@ -84,8 +84,8 @@ public class BulkImporterTest { } @Override - public List<Range> locateTablets(ClientContext context, List<Range> ranges, - BiConsumer<TabletLocation,Range> rangeConsumer, LocationNeed locationNeed) { + public List<Range> findTablets(ClientContext context, List<Range> ranges, + BiConsumer<CachedTablet,Range> rangeConsumer, LocationNeed locationNeed) { throw new UnsupportedOperationException(); } @@ -112,7 +112,7 @@ public class BulkImporterTest { @Test public void testFindOverlappingTablets() throws Exception { - MockTabletLocator locator = new MockTabletLocator(); + MockClientTabletCache locator = new MockClientTabletCache(); FileSystem fs = FileSystem.getLocal(new Configuration()); ServerContext context = MockServerContext.get(); CryptoService cs = NoCryptoServiceFactory.NONE; @@ -146,7 +146,7 @@ public class BulkImporterTest { writer.append(new Key("xyzzy", "cf", "cq"), empty); writer.close(); try (var vm = VolumeManagerImpl.getLocalForTesting("file:///")) { - List<TabletLocation> overlaps = + List<CachedTablet> overlaps = BulkImporter.findOverlappingTablets(context, vm, locator, new Path(file), null, null, cs); assertEquals(5, overlaps.size()); Collections.sort(overlaps, Comparator.comparing(tl -> tl.getExtent())); @@ -159,7 +159,7 @@ public class BulkImporterTest { overlaps.get(3).getExtent()); assertEquals(new KeyExtent(tableId, null, new Text("l")), overlaps.get(4).getExtent()); - List<TabletLocation> overlaps2 = BulkImporter.findOverlappingTablets(context, vm, locator, + List<CachedTablet> overlaps2 = BulkImporter.findOverlappingTablets(context, vm, locator, new Path(file), new KeyExtent(tableId, new Text("h"), new Text("b")), cs); assertEquals(3, overlaps2.size()); assertEquals(new KeyExtent(tableId, new Text("d"), new Text("cm")), diff --git a/server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletLocationStateTest.java b/server/base/src/test/java/org/apache/accumulo/server/manager/state/CachedTabletStateTest.java similarity index 99% rename from server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletLocationStateTest.java rename to server/base/src/test/java/org/apache/accumulo/server/manager/state/CachedTabletStateTest.java index b7cbd748d2..1282274179 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/manager/state/TabletLocationStateTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/manager/state/CachedTabletStateTest.java @@ -42,7 +42,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class TabletLocationStateTest { +public class CachedTabletStateTest { private static final Collection<String> innerWalogs = new java.util.HashSet<>(); private static final Collection<Collection<String>> walogs = new java.util.HashSet<>(); diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java index eccd0e1630..51104fb954 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java @@ -68,8 +68,8 @@ import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.classloader.ClassLoaderUtil; import org.apache.accumulo.core.cli.ConfigOpts; import org.apache.accumulo.core.client.Durability; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.clientImpl.DurabilityImpl; -import org.apache.accumulo.core.clientImpl.TabletLocator; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.InstanceId; @@ -355,7 +355,7 @@ public class TabletServer extends AbstractServer implements TabletHostingServer this.security = context.getSecurityOperation(); watchCriticalScheduledTask(context.getScheduledExecutor().scheduleWithFixedDelay( - TabletLocator::clearLocators, jitter(), jitter(), TimeUnit.MILLISECONDS)); + ClientTabletCache::clearInstances, jitter(), jitter(), TimeUnit.MILLISECONDS)); walMarker = new WalStateManager(context); if (aconf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) { diff --git a/test/src/main/java/org/apache/accumulo/test/BatchWriterIterator.java b/test/src/main/java/org/apache/accumulo/test/BatchWriterIterator.java index 2b009f909e..fecb79fb37 100644 --- a/test/src/main/java/org/apache/accumulo/test/BatchWriterIterator.java +++ b/test/src/main/java/org/apache/accumulo/test/BatchWriterIterator.java @@ -34,7 +34,7 @@ import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.core.clientImpl.ClientInfo; -import org.apache.accumulo.core.clientImpl.TabletLocator; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.data.ByteSequence; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Mutation; @@ -217,7 +217,7 @@ public class BatchWriterIterator extends WrappingIterator { if (firstWrite) { batchWriter.flush(); if (clearCacheAfterFirstWrite) { - TabletLocator.clearLocators(); + ClientTabletCache.clearInstances(); } if (splitAfterFirstWrite) { SortedSet<Text> splits = new TreeSet<>(); diff --git a/test/src/main/java/org/apache/accumulo/test/functional/BulkFailureIT.java b/test/src/main/java/org/apache/accumulo/test/functional/BulkFailureIT.java index 7a9565caaa..9e1c9863af 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/BulkFailureIT.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/BulkFailureIT.java @@ -46,7 +46,7 @@ import org.apache.accumulo.core.client.admin.CompactionConfig; import org.apache.accumulo.core.client.rfile.RFile; import org.apache.accumulo.core.client.rfile.RFileWriter; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.TableId; @@ -302,12 +302,12 @@ public class BulkFailureIT extends AccumuloClusterHarness { protected static TabletIngestClientService.Iface getClient(ClientContext context, KeyExtent extent) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TTransportException { - TabletLocator locator = TabletLocator.getLocator(context, extent.tableId()); + ClientTabletCache locator = ClientTabletCache.getInstance(context, extent.tableId()); locator.invalidateCache(extent); HostAndPort location = HostAndPort.fromString(locator - .locateTabletWithRetry(context, new Text(""), false, TabletLocator.LocationNeed.REQUIRED) + .findTabletWithRetry(context, new Text(""), false, ClientTabletCache.LocationNeed.REQUIRED) .getTserverLocation().get()); long timeInMillis = context.getConfiguration().getTimeInMillis(Property.TSERV_BULK_TIMEOUT); diff --git a/test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java b/test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java index cdec540a91..b0974edab5 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/ManagerAssignmentIT.java @@ -43,7 +43,7 @@ import org.apache.accumulo.core.client.admin.Locations; import org.apache.accumulo.core.client.admin.NewTableConfiguration; import org.apache.accumulo.core.client.admin.TabletHostingGoal; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Range; @@ -201,13 +201,13 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { Thread.sleep(50); stats = getTabletStats(c, tableId); } - assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertEquals(0, ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount()); // loading data will force the tablets to be hosted loadDataForScan(c, tableName); - assertTrue(TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertTrue(ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount() > 0); stats = getTabletStats(c, tableId); @@ -229,7 +229,7 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { Thread.sleep(50); stats = getTabletStats(c, tableId); } - assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertEquals(0, ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount()); return tableId; @@ -252,7 +252,7 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { List<TabletStats> stats = getTabletStats(c, tableId); // There should be one tablet online assertEquals(1, stats.size()); - assertTrue(TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertTrue(ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount() > 0); } @@ -272,8 +272,8 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { List<TabletStats> stats = getTabletStats(c, tableId); assertEquals(3, stats.size()); - long hostingRequestCount = TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) - .getTabletHostingRequestCount(); + long hostingRequestCount = ClientTabletCache + .getInstance((ClientContext) c, TableId.of(tableId)).getTabletHostingRequestCount(); assertTrue(hostingRequestCount > 0); // Run another scan, all tablets should be loaded @@ -285,8 +285,8 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { stats = getTabletStats(c, tableId); assertEquals(3, stats.size()); // No more tablets should have been brought online - assertEquals(hostingRequestCount, TabletLocator - .getLocator((ClientContext) c, TableId.of(tableId)).getTabletHostingRequestCount()); + assertEquals(hostingRequestCount, ClientTabletCache + .getInstance((ClientContext) c, TableId.of(tableId)).getTabletHostingRequestCount()); } } @@ -307,7 +307,7 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { List<TabletStats> stats = getTabletStats(c, tableId); // There should be one tablet online assertEquals(1, stats.size()); - assertTrue(TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertTrue(ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount() > 0); } @@ -327,8 +327,8 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { List<TabletStats> stats = getTabletStats(c, tableId); assertEquals(3, stats.size()); - long hostingRequestCount = TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) - .getTabletHostingRequestCount(); + long hostingRequestCount = ClientTabletCache + .getInstance((ClientContext) c, TableId.of(tableId)).getTabletHostingRequestCount(); assertTrue(hostingRequestCount > 0); // Run another scan, all tablets should be loaded @@ -340,8 +340,8 @@ public class ManagerAssignmentIT extends SharedMiniClusterBase { stats = getTabletStats(c, tableId); assertEquals(3, stats.size()); // No more tablets should have been brought online - assertEquals(hostingRequestCount, TabletLocator - .getLocator((ClientContext) c, TableId.of(tableId)).getTabletHostingRequestCount()); + assertEquals(hostingRequestCount, ClientTabletCache + .getInstance((ClientContext) c, TableId.of(tableId)).getTabletHostingRequestCount()); } } diff --git a/test/src/main/java/org/apache/accumulo/test/functional/OnDemandTabletUnloadingIT.java b/test/src/main/java/org/apache/accumulo/test/functional/OnDemandTabletUnloadingIT.java index e29ae08456..b9db6731a5 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/OnDemandTabletUnloadingIT.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/OnDemandTabletUnloadingIT.java @@ -41,7 +41,7 @@ import org.apache.accumulo.core.client.ScannerBase; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.admin.NewTableConfiguration; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.core.data.Range; @@ -145,7 +145,7 @@ public class OnDemandTabletUnloadingIT extends SharedMiniClusterBase { // There should be no tablets online List<TabletStats> stats = ManagerAssignmentIT.getTabletStats(c, tableId); assertEquals(0, stats.size()); - assertEquals(0, TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertEquals(0, ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount()); assertEquals(0, ONDEMAND_ONLINE_COUNT); @@ -156,7 +156,7 @@ public class OnDemandTabletUnloadingIT extends SharedMiniClusterBase { // There should be four tablets online stats = ManagerAssignmentIT.getTabletStats(c, tableId); assertEquals(4, stats.size()); - assertTrue(TabletLocator.getLocator((ClientContext) c, TableId.of(tableId)) + assertTrue(ClientTabletCache.getInstance((ClientContext) c, TableId.of(tableId)) .getTabletHostingRequestCount() > 0); while (ONDEMAND_ONLINE_COUNT != 4) { diff --git a/test/src/main/java/org/apache/accumulo/test/manager/SuspendedTabletsIT.java b/test/src/main/java/org/apache/accumulo/test/manager/SuspendedTabletsIT.java index 681cec4672..d82648d176 100644 --- a/test/src/main/java/org/apache/accumulo/test/manager/SuspendedTabletsIT.java +++ b/test/src/main/java/org/apache/accumulo/test/manager/SuspendedTabletsIT.java @@ -48,7 +48,7 @@ import org.apache.accumulo.core.client.AccumuloClient; import org.apache.accumulo.core.client.admin.InstanceOperations; import org.apache.accumulo.core.client.admin.NewTableConfiguration; import org.apache.accumulo.core.clientImpl.ClientContext; -import org.apache.accumulo.core.clientImpl.TabletLocator; +import org.apache.accumulo.core.clientImpl.ClientTabletCache; import org.apache.accumulo.core.conf.ClientProperty; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.data.Range; @@ -179,15 +179,15 @@ public class SuspendedTabletsIT extends ConfigurableMacBase { Set<TServerInstance> tserverSet = new HashSet<>(); Set<TServerInstance> metadataServerSet = new HashSet<>(); - TabletLocator tl = TabletLocator.getLocator(ctx, MetadataTable.ID); + ClientTabletCache tl = ClientTabletCache.getInstance(ctx, MetadataTable.ID); for (TabletLocationState tls : locs.locationStates.values()) { if (tls.current != null) { // add to set of all servers tserverSet.add(tls.current.getServerInstance()); // get server that the current tablets metadata is on - TabletLocator.TabletLocation tab = tl.locateTablet(ctx, tls.extent.toMetaRow(), false, - TabletLocator.LocationNeed.REQUIRED); + ClientTabletCache.CachedTablet tab = tl.findTablet(ctx, tls.extent.toMetaRow(), false, + ClientTabletCache.LocationNeed.REQUIRED); // add it to the set of servers with metadata metadataServerSet.add(new TServerInstance(tab.getTserverLocation().get(), Long.valueOf(tab.getTserverSession().get(), 16)));