Skip to content

Commit 305101f

Browse files
committed
Merge remote-tracking branch 'dlmarion/4973-new-monitor-metrics' into newServerOldMonitor
2 parents 065aabd + 1691c9c commit 305101f

37 files changed

+612
-786
lines changed

assemble/bin/accumulo-cluster

+290-492
Large diffs are not rendered by default.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ public enum CompactionReason {
134134
public abstract List<IteratorSetting> getIterators();
135135

136136
/**
137-
* Return the host where the compaction is running.
137+
* Return the server where the compaction is running.
138138
*
139-
* @since 2.1.0
139+
* @since 4.0.0
140140
*/
141-
public abstract ServerId getHost();
141+
public abstract ServerId getServerId();
142142
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
import org.apache.accumulo.core.client.admin.servers.ServerId;
2425
import org.apache.accumulo.core.data.Column;
2526
import org.apache.accumulo.core.data.TabletId;
2627
import org.apache.accumulo.core.security.Authorizations;
@@ -96,4 +97,11 @@ public abstract class ActiveScan {
9697
* @since 1.5.0
9798
*/
9899
public abstract long getIdleTime();
100+
101+
/**
102+
* Return the server where the scan is running.
103+
*
104+
* @since 4.0.0
105+
*/
106+
public abstract ServerId getServerId();
99107
}

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

+8-20
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,22 @@ Set<ServerId> getServers(ServerId.Type type, Predicate<String> resourceGroupPred
259259
* @param tserver The tablet server address. This should be of the form
260260
* {@code <ip address>:<port>}
261261
* @return A list of active scans on tablet server.
262-
* @deprecated see {@link #getActiveScans(ServerId)}
262+
* @deprecated see {@link #getActiveScans(Collection)}
263263
*/
264264
@Deprecated(since = "4.0.0")
265265
List<ActiveScan> getActiveScans(String tserver)
266266
throws AccumuloException, AccumuloSecurityException;
267267

268268
/**
269-
* List the active scans on a server.
269+
* List the active scans on a collection of servers.
270270
*
271-
* @param server server type and address
272-
* @return A stream of active scans on server.
271+
* @param servers Collection of server types and addresses
272+
* @return A list of active scans on the given servers.
273273
* @throws IllegalArgumentException when the type of the server is not TABLET_SERVER or
274274
* SCAN_SERVER
275275
* @since 4.0.0
276276
*/
277-
List<ActiveScan> getActiveScans(ServerId server)
277+
List<ActiveScan> getActiveScans(Collection<ServerId> servers)
278278
throws AccumuloException, AccumuloSecurityException;
279279

280280
/**
@@ -286,32 +286,20 @@ List<ActiveScan> getActiveScans(ServerId server)
286286
* @param tserver The server address. This should be of the form {@code <ip address>:<port>}
287287
* @return the list of active compactions
288288
* @since 1.5.0
289-
* @deprecated see {@link #getActiveCompactions(ServerId server)}
289+
* @deprecated see {@link #getActiveCompactions(Collection)}
290290
*/
291291
@Deprecated(since = "4.0.0")
292292
List<ActiveCompaction> getActiveCompactions(String tserver)
293293
throws AccumuloException, AccumuloSecurityException;
294294

295-
/**
296-
* List the active compaction running on a TabletServer or Compactor. The server address can be
297-
* retrieved using {@link #getCompactors()} or {@link #getTabletServers()}. Use
298-
* {@link #getActiveCompactions()} to get a list of all compactions running on tservers and
299-
* compactors.
300-
*
301-
* @param server The ServerId object
302-
* @return the list of active compactions
303-
* @throws IllegalArgumentException when the type of the server is not TABLET_SERVER or COMPACTOR
304-
* @since 4.0.0
305-
*/
306-
List<ActiveCompaction> getActiveCompactions(ServerId server)
307-
throws AccumuloException, AccumuloSecurityException;
308-
309295
/**
310296
* List all internal and external compactions running in Accumulo.
311297
*
312298
* @return the list of active compactions
313299
* @since 2.1.0
300+
* @deprecated see {@link #getActiveCompactions(Collection)}
314301
*/
302+
@Deprecated(since = "4.0.0")
315303
List<ActiveCompaction> getActiveCompactions() throws AccumuloException, AccumuloSecurityException;
316304

317305
/**

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public List<IteratorSetting> getIterators() {
119119
}
120120

121121
@Override
122-
public ServerId getHost() {
122+
public ServerId getServerId() {
123123
return server;
124124
}
125125
}

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

+18-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import java.util.ArrayList;
2222
import java.util.List;
2323
import java.util.Map;
24+
import java.util.Objects;
2425

2526
import org.apache.accumulo.core.client.TableNotFoundException;
2627
import org.apache.accumulo.core.client.admin.ActiveScan;
2728
import org.apache.accumulo.core.client.admin.ScanState;
2829
import org.apache.accumulo.core.client.admin.ScanType;
30+
import org.apache.accumulo.core.client.admin.servers.ServerId;
2931
import org.apache.accumulo.core.data.Column;
3032
import org.apache.accumulo.core.data.TableId;
3133
import org.apache.accumulo.core.data.TabletId;
@@ -44,20 +46,21 @@ public class ActiveScanImpl extends ActiveScan {
4446

4547
private final long scanId;
4648
private final String client;
47-
private String tableName;
49+
private final String tableName;
4850
private final long age;
4951
private final long idle;
50-
private ScanType type;
51-
private ScanState state;
52-
private KeyExtent extent;
53-
private List<Column> columns;
54-
private List<String> ssiList;
55-
private Map<String,Map<String,String>> ssio;
52+
private final ScanType type;
53+
private final ScanState state;
54+
private final KeyExtent extent;
55+
private final List<Column> columns;
56+
private final List<String> ssiList;
57+
private final Map<String,Map<String,String>> ssio;
5658
private final String user;
57-
private Authorizations authorizations;
59+
private final Authorizations authorizations;
60+
private final ServerId server;
5861

5962
ActiveScanImpl(ClientContext context,
60-
org.apache.accumulo.core.tabletscan.thrift.ActiveScan activeScan)
63+
org.apache.accumulo.core.tabletscan.thrift.ActiveScan activeScan, ServerId server)
6164
throws TableNotFoundException {
6265
this.scanId = activeScan.scanId;
6366
this.client = activeScan.client;
@@ -81,6 +84,7 @@ public class ActiveScanImpl extends ActiveScan {
8184
this.ssiList.add(ii.iterName + "=" + ii.priority + "," + ii.className);
8285
}
8386
this.ssio = activeScan.ssio;
87+
this.server = Objects.requireNonNull(server);
8488
}
8589

8690
@Override
@@ -152,4 +156,9 @@ public Authorizations getAuthorizations() {
152156
public long getIdleTime() {
153157
return idle;
154158
}
159+
160+
@Override
161+
public ServerId getServerId() {
162+
return server;
163+
}
155164
}

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

+52-46
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.apache.accumulo.core.rpc.ThriftUtil.getClient;
2626
import static org.apache.accumulo.core.rpc.ThriftUtil.returnClient;
2727
import static org.apache.accumulo.core.util.threads.ThreadPoolNames.INSTANCE_OPS_COMPACTIONS_FINDER_POOL;
28+
import static org.apache.accumulo.core.util.threads.ThreadPoolNames.INSTANCE_OPS_SCANS_FINDER_POOL;
2829

2930
import java.time.Duration;
3031
import java.util.ArrayList;
@@ -38,6 +39,7 @@
3839
import java.util.Optional;
3940
import java.util.Set;
4041
import java.util.concurrent.ExecutionException;
42+
import java.util.concurrent.ExecutorService;
4143
import java.util.concurrent.Future;
4244
import java.util.function.BiPredicate;
4345
import java.util.function.Consumer;
@@ -51,6 +53,7 @@
5153
import org.apache.accumulo.core.client.admin.ActiveScan;
5254
import org.apache.accumulo.core.client.admin.InstanceOperations;
5355
import org.apache.accumulo.core.client.admin.servers.ServerId;
56+
import org.apache.accumulo.core.client.admin.servers.ServerId.Type;
5457
import org.apache.accumulo.core.clientImpl.thrift.ClientService;
5558
import org.apache.accumulo.core.clientImpl.thrift.ConfigurationType;
5659
import org.apache.accumulo.core.clientImpl.thrift.TVersionedProperties;
@@ -72,12 +75,14 @@
7275
import org.apache.accumulo.core.util.LocalityGroupUtil.LocalityGroupConfigurationError;
7376
import org.apache.accumulo.core.util.Retry;
7477
import org.apache.accumulo.core.util.compaction.ExternalCompactionUtil;
78+
import org.apache.accumulo.core.util.threads.ThreadPoolNames;
7579
import org.apache.thrift.TException;
7680
import org.apache.thrift.transport.TTransport;
7781
import org.slf4j.LoggerFactory;
7882

7983
import com.google.common.base.Preconditions;
8084
import com.google.common.net.HostAndPort;
85+
import com.google.common.util.concurrent.MoreExecutors;
8186

8287
/**
8388
* Provides a class for administering the accumulo instance
@@ -265,33 +270,18 @@ public List<String> getTabletServers() {
265270
@Deprecated(since = "4.0.0")
266271
public List<ActiveScan> getActiveScans(String tserver)
267272
throws AccumuloException, AccumuloSecurityException {
268-
final var parsedTserver = HostAndPort.fromString(tserver);
269-
TabletScanClientService.Client client = null;
270-
try {
271-
client = getClient(ThriftClientTypes.TABLET_SCAN, parsedTserver, context);
272-
273-
List<ActiveScan> as = new ArrayList<>();
274-
for (var activeScan : client.getActiveScans(TraceUtil.traceInfo(), context.rpcCreds())) {
275-
try {
276-
as.add(new ActiveScanImpl(context, activeScan));
277-
} catch (TableNotFoundException e) {
278-
throw new AccumuloException(e);
279-
}
280-
}
281-
return as;
282-
} catch (ThriftSecurityException e) {
283-
throw new AccumuloSecurityException(e.user, e.code, e);
284-
} catch (TException e) {
285-
throw new AccumuloException(e);
286-
} finally {
287-
if (client != null) {
288-
returnClient(client, context);
289-
}
290-
}
273+
var si = getServerId(tserver, List.of(Type.TABLET_SERVER, Type.SCAN_SERVER));
274+
// getActiveScans throws exceptions so we can't use Optional.map() here
275+
return si.isPresent() ? getActiveScans(si.orElseThrow()) : List.of();
291276
}
292277

293278
@Override
294-
public List<ActiveScan> getActiveScans(ServerId server)
279+
public List<ActiveScan> getActiveScans(Collection<ServerId> servers)
280+
throws AccumuloException, AccumuloSecurityException {
281+
return queryServers(servers, this::getActiveScans, INSTANCE_OPS_SCANS_FINDER_POOL);
282+
}
283+
284+
private List<ActiveScan> getActiveScans(ServerId server)
295285
throws AccumuloException, AccumuloSecurityException {
296286

297287
Objects.requireNonNull(server);
@@ -309,7 +299,7 @@ public List<ActiveScan> getActiveScans(ServerId server)
309299
List<ActiveScan> as = new ArrayList<>();
310300
for (var activeScan : rpcClient.getActiveScans(TraceUtil.traceInfo(), context.rpcCreds())) {
311301
try {
312-
as.add(new ActiveScanImpl(context, activeScan));
302+
as.add(new ActiveScanImpl(context, activeScan, server));
313303
} catch (TableNotFoundException e) {
314304
throw new AccumuloException(e);
315305
}
@@ -337,21 +327,12 @@ public boolean testClassLoad(final String className, final String asTypeName)
337327
@Deprecated
338328
public List<ActiveCompaction> getActiveCompactions(String server)
339329
throws AccumuloException, AccumuloSecurityException {
340-
341-
HostAndPort hp = HostAndPort.fromString(server);
342-
343-
ServerId si = getServer(ServerId.Type.COMPACTOR, null, hp.getHost(), hp.getPort());
344-
if (si == null) {
345-
si = getServer(ServerId.Type.TABLET_SERVER, null, hp.getHost(), hp.getPort());
346-
}
347-
if (si == null) {
348-
return List.of();
349-
}
350-
return getActiveCompactions(si);
330+
var si = getServerId(server, List.of(Type.COMPACTOR, Type.TABLET_SERVER));
331+
// getActiveCompactions throws exceptions so we can't use Optional.map() here
332+
return si.isPresent() ? getActiveCompactions(si.orElseThrow()) : List.of();
351333
}
352334

353-
@Override
354-
public List<ActiveCompaction> getActiveCompactions(ServerId server)
335+
private List<ActiveCompaction> getActiveCompactions(ServerId server)
355336
throws AccumuloException, AccumuloSecurityException {
356337

357338
Objects.requireNonNull(server);
@@ -391,6 +372,7 @@ public List<ActiveCompaction> getActiveCompactions(ServerId server)
391372
}
392373

393374
@Override
375+
@Deprecated
394376
public List<ActiveCompaction> getActiveCompactions()
395377
throws AccumuloException, AccumuloSecurityException {
396378

@@ -404,19 +386,34 @@ public List<ActiveCompaction> getActiveCompactions()
404386
@Override
405387
public List<ActiveCompaction> getActiveCompactions(Collection<ServerId> compactionServers)
406388
throws AccumuloException, AccumuloSecurityException {
389+
return queryServers(compactionServers, this::getActiveCompactions,
390+
INSTANCE_OPS_COMPACTIONS_FINDER_POOL);
391+
}
392+
393+
private <T> List<T> queryServers(Collection<ServerId> servers, ServerQuery<List<T>> serverQuery,
394+
ThreadPoolNames pool) throws AccumuloException, AccumuloSecurityException {
395+
396+
final ExecutorService executorService;
397+
// If size 0 or 1 there's no need to create a thread pool
398+
if (servers.isEmpty()) {
399+
return List.of();
400+
} else if (servers.size() == 1) {
401+
executorService = MoreExecutors.newDirectExecutorService();
402+
} else {
403+
int numThreads = Math.max(4, Math.min((servers.size()) / 10, 256));
404+
executorService =
405+
context.threadPools().getPoolBuilder(pool).numCoreThreads(numThreads).build();
406+
}
407407

408-
int numThreads = Math.max(4, Math.min((compactionServers.size()) / 10, 256));
409-
var executorService = context.threadPools().getPoolBuilder(INSTANCE_OPS_COMPACTIONS_FINDER_POOL)
410-
.numCoreThreads(numThreads).build();
411408
try {
412-
List<Future<List<ActiveCompaction>>> futures = new ArrayList<>();
409+
List<Future<List<T>>> futures = new ArrayList<>();
413410

414-
for (ServerId server : compactionServers) {
415-
futures.add(executorService.submit(() -> getActiveCompactions(server)));
411+
for (ServerId server : servers) {
412+
futures.add(executorService.submit(() -> serverQuery.execute(server)));
416413
}
417414

418-
List<ActiveCompaction> ret = new ArrayList<>();
419-
for (Future<List<ActiveCompaction>> future : futures) {
415+
List<T> ret = new ArrayList<>();
416+
for (Future<List<T>> future : futures) {
420417
try {
421418
ret.addAll(future.get());
422419
} catch (InterruptedException | ExecutionException e) {
@@ -635,4 +632,13 @@ private ServerId createServerId(ServerId.Type type, ServiceLockPath slp) {
635632
return new ServerId(type, resourceGroup, host, port);
636633
}
637634

635+
private Optional<ServerId> getServerId(String server, List<Type> types) {
636+
HostAndPort hp = HostAndPort.fromString(server);
637+
return types.stream().map(type -> getServer(type, null, hp.getHost(), hp.getPort()))
638+
.findFirst();
639+
}
640+
641+
interface ServerQuery<T> {
642+
T execute(ServerId server) throws AccumuloException, AccumuloSecurityException;
643+
}
638644
}

0 commit comments

Comments
 (0)