Skip to content

Commit 6de07db

Browse files
committed
Merge branch 'main' into accumulo-5160-2
2 parents 77919bc + cc9aff0 commit 6de07db

File tree

186 files changed

+3129
-2449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+3129
-2449
lines changed

core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.accumulo.core.client.admin;
2020

21+
import java.time.Duration;
2122
import java.util.Collection;
2223
import java.util.List;
2324
import java.util.Map;
@@ -357,4 +358,14 @@ boolean testClassLoad(final String className, final String asTypeName)
357358
* @since 2.1.0
358359
*/
359360
InstanceId getInstanceId();
361+
362+
/**
363+
* Return the current manager time. This duration represents the amount of time an accumulo
364+
* manager process has been running. The duration is persisted and should only increase over the
365+
* lifetime of an Accumulo instance.
366+
*
367+
* @return current time
368+
* @since 4.0.0
369+
*/
370+
Duration getManagerTime() throws AccumuloException, AccumuloSecurityException;
360371
}

core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java

+24-38
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@
9595
import org.apache.accumulo.core.rpc.SslConnectionParams;
9696
import org.apache.accumulo.core.security.Authorizations;
9797
import org.apache.accumulo.core.securityImpl.thrift.TCredentials;
98-
import org.apache.accumulo.core.singletons.SingletonManager;
99-
import org.apache.accumulo.core.singletons.SingletonReservation;
10098
import org.apache.accumulo.core.spi.common.ServiceEnvironment;
10199
import org.apache.accumulo.core.spi.scan.ScanServerInfo;
102100
import org.apache.accumulo.core.spi.scan.ScanServerSelector;
@@ -137,6 +135,7 @@ public class ClientContext implements AccumuloClient {
137135
private ConditionalWriterConfig conditionalWriterConfig;
138136
private final AccumuloConfiguration accumuloConf;
139137
private final Configuration hadoopConf;
138+
private final HashMap<TableId,ClientTabletCache> tabletCaches = new HashMap<>();
140139

141140
// These fields are very frequently accessed (each time a connection is created) and expensive to
142141
// compute, so cache them.
@@ -156,7 +155,6 @@ public class ClientContext implements AccumuloClient {
156155
private final TableOperationsImpl tableops;
157156
private final NamespaceOperations namespaceops;
158157
private InstanceOperations instanceops = null;
159-
private final SingletonReservation singletonReservation;
160158
private final ThreadPools clientThreadPools;
161159
private ThreadPoolExecutor cleanupThreadPool;
162160
private ThreadPoolExecutor scannerReadaheadPool;
@@ -223,27 +221,24 @@ public String getGroup() {
223221
}
224222

225223
/**
226-
* Create a client context with the provided configuration. Legacy client code must provide a
227-
* no-op SingletonReservation to preserve behavior prior to 2.x. Clients since 2.x should call
228-
* Accumulo.newClient() builder, which will create a client reservation in
229-
* {@link ClientBuilderImpl#buildClient}
224+
* Create a client context with the provided configuration. Clients should call
225+
* Accumulo.newClient() builder
230226
*/
231-
public ClientContext(SingletonReservation reservation, ClientInfo info,
232-
AccumuloConfiguration serverConf, UncaughtExceptionHandler ueh) {
227+
public ClientContext(ClientInfo info, AccumuloConfiguration serverConf,
228+
UncaughtExceptionHandler ueh) {
233229
this.info = info;
234230
this.hadoopConf = info.getHadoopConf();
235231

236232
this.zooSession = memoize(() -> {
237-
var zk = info
238-
.getZooKeeperSupplier(getClass().getSimpleName() + "(" + info.getPrincipal() + ")", "")
239-
.get();
233+
var zk =
234+
info.getZooKeeperSupplier(getClass().getSimpleName() + "(" + info.getPrincipal() + ")",
235+
ZooUtil.getRoot(getInstanceID())).get();
240236
zooKeeperOpened.set(true);
241237
return zk;
242238
});
243239

244240
this.zooCache = memoize(() -> {
245-
var zc = new ZooCache(getZooSession(),
246-
createPersistentWatcherPaths(ZooUtil.getRoot(getInstanceID())));
241+
var zc = new ZooCache(getZooSession(), createPersistentWatcherPaths());
247242
zooCacheCreated.set(true);
248243
return zc;
249244
});
@@ -255,11 +250,9 @@ public ClientContext(SingletonReservation reservation, ClientInfo info,
255250
() -> SaslConnectionParams.from(getConfiguration(), getCredentials().getToken()), 100,
256251
MILLISECONDS);
257252
scanServerSelectorSupplier = memoize(this::createScanServerSelector);
258-
this.singletonReservation = Objects.requireNonNull(reservation);
259253
this.tableops = new TableOperationsImpl(this);
260254
this.namespaceops = new NamespaceOperationsImpl(this, tableops);
261-
this.serverPaths =
262-
Suppliers.memoize(() -> new ServiceLockPaths(this.getZooKeeperRoot(), this.getZooCache()));
255+
this.serverPaths = Suppliers.memoize(() -> new ServiceLockPaths(this.getZooCache()));
263256
if (ueh == Threads.UEH) {
264257
clientThreadPools = ThreadPools.getServerThreadPools();
265258
} else {
@@ -504,10 +497,6 @@ public InstanceId getInstanceID() {
504497
return info.getInstanceId();
505498
}
506499

507-
public String getZooKeeperRoot() {
508-
return ZooUtil.getRoot(getInstanceID());
509-
}
510-
511500
/**
512501
* Returns the instance name given at system initialization time.
513502
*
@@ -813,7 +802,6 @@ public synchronized void close() {
813802
if (cleanupThreadPool != null) {
814803
cleanupThreadPool.shutdown(); // wait for shutdown tasks to execute
815804
}
816-
singletonReservation.close();
817805
}
818806
}
819807

@@ -846,16 +834,10 @@ public T build() {
846834
}
847835

848836
public static AccumuloClient buildClient(ClientBuilderImpl<AccumuloClient> cbi) {
849-
SingletonReservation reservation = SingletonManager.getClientReservation();
850-
try {
851-
// ClientContext closes reservation unless a RuntimeException is thrown
852-
ClientInfo info = cbi.getClientInfo();
853-
var config = ClientConfConverter.toAccumuloConf(info.getClientProperties());
854-
return new ClientContext(reservation, info, config, cbi.getUncaughtExceptionHandler());
855-
} catch (RuntimeException e) {
856-
reservation.close();
857-
throw e;
858-
}
837+
// ClientContext closes reservation unless a RuntimeException is thrown
838+
ClientInfo info = cbi.getClientInfo();
839+
var config = ClientConfConverter.toAccumuloConf(info.getClientProperties());
840+
return new ClientContext(info, config, cbi.getUncaughtExceptionHandler());
859841
}
860842

861843
public static Properties buildProps(ClientBuilderImpl<Properties> cbi) {
@@ -1090,10 +1072,9 @@ public synchronized ZookeeperLockChecker getTServerLockChecker() {
10901072
// so, it can't rely on being able to continue to use the same client's ZooCache,
10911073
// because that client could be closed, and its ZooSession also closed
10921074
// this needs to be fixed; TODO https://github.com/apache/accumulo/issues/2301
1093-
var zk = info.getZooKeeperSupplier(ZookeeperLockChecker.class.getSimpleName(), "").get();
1094-
String zkRoot = getZooKeeperRoot();
1095-
this.zkLockChecker =
1096-
new ZookeeperLockChecker(new ZooCache(zk, Set.of(zkRoot + Constants.ZTSERVERS)), zkRoot);
1075+
var zk = info.getZooKeeperSupplier(ZookeeperLockChecker.class.getSimpleName(),
1076+
ZooUtil.getRoot(getInstanceID())).get();
1077+
this.zkLockChecker = new ZookeeperLockChecker(new ZooCache(zk, Set.of(Constants.ZTSERVERS)));
10971078
}
10981079
return this.zkLockChecker;
10991080
}
@@ -1107,13 +1088,18 @@ public NamespaceMapping getNamespaces() {
11071088
return namespaces;
11081089
}
11091090

1110-
private static Set<String> createPersistentWatcherPaths(String zkRoot) {
1091+
public HashMap<TableId,ClientTabletCache> tabletCaches() {
1092+
ensureOpen();
1093+
return tabletCaches;
1094+
}
1095+
1096+
private static Set<String> createPersistentWatcherPaths() {
11111097
Set<String> pathsToWatch = new HashSet<>();
11121098
for (String path : Set.of(Constants.ZCOMPACTORS, Constants.ZDEADTSERVERS, Constants.ZGC_LOCK,
11131099
Constants.ZMANAGER_LOCK, Constants.ZMINI_LOCK, Constants.ZMONITOR_LOCK,
11141100
Constants.ZNAMESPACES, Constants.ZRECOVERY, Constants.ZSSERVERS, Constants.ZTABLES,
11151101
Constants.ZTSERVERS, Constants.ZUSERS, RootTable.ZROOT_TABLET, Constants.ZTEST_LOCK)) {
1116-
pathsToWatch.add(zkRoot + path);
1102+
pathsToWatch.add(path);
11171103
}
11181104
return pathsToWatch;
11191105
}

core/src/main/java/org/apache/accumulo/core/clientImpl/ClientTabletCache.java

+5-75
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,17 @@
3434
import org.apache.accumulo.core.client.InvalidTabletHostingRequestException;
3535
import org.apache.accumulo.core.client.TableNotFoundException;
3636
import org.apache.accumulo.core.client.admin.TabletAvailability;
37-
import org.apache.accumulo.core.data.InstanceId;
3837
import org.apache.accumulo.core.data.Mutation;
3938
import org.apache.accumulo.core.data.Range;
4039
import org.apache.accumulo.core.data.TableId;
4140
import org.apache.accumulo.core.dataImpl.KeyExtent;
4241
import org.apache.accumulo.core.metadata.AccumuloTable;
4342
import org.apache.accumulo.core.metadata.MetadataCachedTabletObtainer;
44-
import org.apache.accumulo.core.singletons.SingletonManager;
45-
import org.apache.accumulo.core.singletons.SingletonService;
4643
import org.apache.accumulo.core.util.Interner;
4744
import org.apache.accumulo.core.util.Timer;
4845
import org.apache.accumulo.core.util.UtilWaitThread;
4946
import org.apache.hadoop.io.Text;
5047

51-
import com.google.common.base.Preconditions;
52-
5348
/**
5449
* Client side cache of information about Tablets. Currently, a tablet prev end row is cached and
5550
* locations are cached if they exist.
@@ -189,66 +184,21 @@ public List<Range> binRanges(ClientContext context, List<Range> ranges,
189184
*/
190185
public abstract void invalidateCache(ClientContext context, String server);
191186

192-
private static class InstanceKey {
193-
final InstanceId instanceId;
194-
final TableId tableId;
195-
196-
InstanceKey(InstanceId instanceId, TableId table) {
197-
this.instanceId = instanceId;
198-
this.tableId = table;
199-
}
200-
201-
@Override
202-
public int hashCode() {
203-
return instanceId.hashCode() + tableId.hashCode();
204-
}
205-
206-
@Override
207-
public boolean equals(Object o) {
208-
if (o instanceof InstanceKey) {
209-
return equals((InstanceKey) o);
210-
}
211-
return false;
212-
}
213-
214-
public boolean equals(InstanceKey lk) {
215-
return instanceId.equals(lk.instanceId) && tableId.equals(lk.tableId);
216-
}
217-
218-
}
219-
220-
private static final HashMap<InstanceKey,ClientTabletCache> instances = new HashMap<>();
221-
private static boolean enabled = true;
222-
223-
public static synchronized void clearInstances() {
187+
public static synchronized void clearInstances(ClientContext context) {
188+
final var instances = context.tabletCaches();
224189
for (ClientTabletCache locator : instances.values()) {
225190
locator.isValid = false;
226191
}
227192
instances.clear();
228193
}
229194

230-
static synchronized boolean isEnabled() {
231-
return enabled;
232-
}
233-
234-
static synchronized void disable() {
235-
clearInstances();
236-
enabled = false;
237-
}
238-
239-
static synchronized void enable() {
240-
enabled = true;
241-
}
242-
243195
public long getTabletHostingRequestCount() {
244196
return 0L;
245197
}
246198

247199
public static synchronized ClientTabletCache getInstance(ClientContext context, TableId tableId) {
248-
Preconditions.checkState(enabled, "The Accumulo singleton that that tracks tablet locations is "
249-
+ "disabled. This is likely caused by all AccumuloClients being closed or garbage collected");
250-
InstanceKey key = new InstanceKey(context.getInstanceID(), tableId);
251-
ClientTabletCache tl = instances.get(key);
200+
final var caches = context.tabletCaches();
201+
ClientTabletCache tl = caches.get(tableId);
252202
if (tl == null) {
253203
MetadataCachedTabletObtainer mlo = new MetadataCachedTabletObtainer();
254204

@@ -263,32 +213,12 @@ public static synchronized ClientTabletCache getInstance(ClientContext context,
263213
getInstance(context, AccumuloTable.METADATA.tableId()), mlo,
264214
context.getTServerLockChecker());
265215
}
266-
instances.put(key, tl);
216+
caches.put(tableId, tl);
267217
}
268218

269219
return tl;
270220
}
271221

272-
static {
273-
SingletonManager.register(new SingletonService() {
274-
275-
@Override
276-
public boolean isEnabled() {
277-
return ClientTabletCache.isEnabled();
278-
}
279-
280-
@Override
281-
public void enable() {
282-
ClientTabletCache.enable();
283-
}
284-
285-
@Override
286-
public void disable() {
287-
ClientTabletCache.disable();
288-
}
289-
});
290-
}
291-
292222
public static class CachedTablets {
293223

294224
private final List<CachedTablet> cachedTablets;

core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
import org.apache.accumulo.access.AccessEvaluator;
4747
import org.apache.accumulo.access.InvalidAccessExpressionException;
48-
import org.apache.accumulo.core.Constants;
4948
import org.apache.accumulo.core.client.AccumuloException;
5049
import org.apache.accumulo.core.client.AccumuloSecurityException;
5150
import org.apache.accumulo.core.client.ConditionalWriter;
@@ -683,7 +682,7 @@ private void invalidateSession(SessionID sessionId, HostAndPort location)
683682

684683
long startTime = System.currentTimeMillis();
685684

686-
LockID lid = new LockID(context.getZooKeeperRoot() + Constants.ZTSERVERS, sessionId.lockId);
685+
LockID lid = LockID.deserialize(sessionId.lockId);
687686

688687
while (true) {
689688
if (!ServiceLock.isLockHeld(context.getZooCache(), lid)) {

core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java

+6
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ public InstanceId getInstanceId() {
470470
return context.getInstanceID();
471471
}
472472

473+
@Override
474+
public Duration getManagerTime() throws AccumuloException, AccumuloSecurityException {
475+
return Duration.ofNanos(ThriftClientTypes.MANAGER.execute(context,
476+
client -> client.getManagerTimeNanos(TraceUtil.traceInfo(), context.rpcCreds())));
477+
}
478+
473479
@Override
474480
public ServerId getServer(ServerId.Type type, String resourceGroup, String host, int port) {
475481
Objects.requireNonNull(type, "type parameter cannot be null");

core/src/main/java/org/apache/accumulo/core/clientImpl/NamespaceMapping.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,17 @@ public NamespaceMapping(ClientContext context) {
5353
this.context = context;
5454
}
5555

56-
public static void put(final ZooReaderWriter zoo, final String zPath,
57-
final NamespaceId namespaceId, final String namespaceName)
56+
public static void put(final ZooReaderWriter zoo, final NamespaceId namespaceId,
57+
final String namespaceName)
5858
throws InterruptedException, KeeperException, AcceptableThriftTableOperationException {
5959
requireNonNull(zoo);
60-
requireNonNull(zPath);
6160
requireNonNull(namespaceId);
6261
requireNonNull(namespaceName);
6362
if (Namespace.DEFAULT.id().equals(namespaceId) || Namespace.ACCUMULO.id().equals(namespaceId)) {
6463
throw new AssertionError(
6564
"Putting built-in namespaces in map should not be possible after init");
6665
}
67-
zoo.mutateExisting(zPath, data -> {
66+
zoo.mutateExisting(Constants.ZNAMESPACES, data -> {
6867
var namespaces = deserialize(data);
6968
final String currentName = namespaces.get(namespaceId.canonical());
7069
if (namespaceName.equals(currentName)) {
@@ -106,18 +105,17 @@ public static void remove(final ZooReaderWriter zoo, final String zPath,
106105
});
107106
}
108107

109-
public static void rename(final ZooReaderWriter zoo, final String zPath,
110-
final NamespaceId namespaceId, final String oldName, final String newName)
108+
public static void rename(final ZooReaderWriter zoo, final NamespaceId namespaceId,
109+
final String oldName, final String newName)
111110
throws InterruptedException, KeeperException, AcceptableThriftTableOperationException {
112111
requireNonNull(zoo);
113-
requireNonNull(zPath);
114112
requireNonNull(namespaceId);
115113
requireNonNull(oldName);
116114
requireNonNull(newName);
117115
if (Namespace.DEFAULT.id().equals(namespaceId) || Namespace.ACCUMULO.id().equals(namespaceId)) {
118116
throw new AssertionError("Renaming built-in namespaces in map should not be possible");
119117
}
120-
zoo.mutateExisting(zPath, current -> {
118+
zoo.mutateExisting(Constants.ZNAMESPACES, current -> {
121119
var namespaces = deserialize(current);
122120
final String currentName = namespaces.get(namespaceId.canonical());
123121
if (newName.equals(currentName)) {
@@ -147,10 +145,9 @@ public static Map<String,String> deserialize(byte[] data) {
147145

148146
private synchronized void update() {
149147
final ZooCache zc = context.getZooCache();
150-
final String zPath = context.getZooKeeperRoot() + Constants.ZNAMESPACES;
151148
final ZcStat stat = new ZcStat();
152149

153-
byte[] data = zc.get(zPath, stat);
150+
byte[] data = zc.get(Constants.ZNAMESPACES, stat);
154151
if (stat.getMzxid() > lastMzxid) {
155152
if (data == null) {
156153
throw new IllegalStateException("namespaces node should not be null");

core/src/main/java/org/apache/accumulo/core/clientImpl/RootClientTabletCache.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ protected CachedTablet getRootTabletLocation(ClientContext context) {
128128
timer = Timer.startNew();
129129
}
130130

131-
var zpath = RootTabletMetadata.zooPath(context);
132131
var zooCache = context.getZooCache();
133-
Location loc = new RootTabletMetadata(new String(zooCache.get(zpath), UTF_8)).toTabletMetadata()
134-
.getLocation();
132+
Location loc = new RootTabletMetadata(new String(zooCache.get(RootTable.ZROOT_TABLET), UTF_8))
133+
.toTabletMetadata().getLocation();
135134

136135
if (timer != null) {
137136
log.trace("tid={} Found root tablet at {} in {}", Thread.currentThread().getId(), loc,

0 commit comments

Comments
 (0)