This is an automated email from the ASF dual-hosted git repository.
domgarguilo pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new b2a78ddb49 Improve ActiveCompactionHelper methods (#4677)
b2a78ddb49 is described below
commit b2a78ddb496152b429b131bf960fb63a5ac04e77
Author: Dom G <[email protected]>
AuthorDate: Fri Jun 14 17:17:40 2024 -0400
Improve ActiveCompactionHelper methods (#4677)
---
.../shell/commands/ActiveCompactionHelper.java | 30 +++++++++-------------
.../shell/commands/ListCompactionsCommand.java | 2 +-
2 files changed, 13 insertions(+), 19 deletions(-)
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/ActiveCompactionHelper.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/ActiveCompactionHelper.java
index d23f242178..8f6b9259ae 100644
---
a/shell/src/main/java/org/apache/accumulo/shell/commands/ActiveCompactionHelper.java
+++
b/shell/src/main/java/org/apache/accumulo/shell/commands/ActiveCompactionHelper.java
@@ -39,6 +39,9 @@ class ActiveCompactionHelper {
private static final Logger log =
LoggerFactory.getLogger(ActiveCompactionHelper.class);
+ private static final Comparator<ActiveCompaction> COMPACTION_AGE_DESCENDING =
+ Comparator.comparingLong(ActiveCompaction::getAge).reversed();
+
private static String maxDecimal(double count) {
if (count < 9.995) {
return String.format("%.2f", count);
@@ -113,34 +116,25 @@ class ActiveCompactionHelper {
public static Stream<String> activeCompactionsForServer(String tserver,
InstanceOperations instanceOps) {
- List<String> compactions = new ArrayList<>();
try {
- List<ActiveCompaction> acl = new
ArrayList<>(instanceOps.getActiveCompactions(tserver));
- acl.sort((o1, o2) -> (int) (o2.getAge() - o1.getAge()));
- for (ActiveCompaction ac : acl) {
- compactions.add(formatActiveCompactionLine(ac));
- }
+ return
instanceOps.getActiveCompactions(tserver).stream().sorted(COMPACTION_AGE_DESCENDING)
+ .map(ActiveCompactionHelper::formatActiveCompactionLine);
} catch (Exception e) {
log.debug("Failed to list active compactions for server {}", tserver, e);
- compactions.add(tserver + " ERROR " + e.getMessage());
+ return Stream.of(tserver + " ERROR " + e.getMessage());
}
- return compactions.stream();
}
- public static Stream<String> stream(InstanceOperations instanceOps) {
- List<ActiveCompaction> activeCompactions;
+ public static Stream<String> activeCompactions(InstanceOperations
instanceOps) {
+ Comparator<ActiveCompaction> comparator =
+ Comparator.comparing((ActiveCompaction ac) ->
ac.getHost().getAddress())
+ .thenComparing(ac ->
ac.getHost().getPort()).thenComparing(COMPACTION_AGE_DESCENDING);
try {
- activeCompactions = instanceOps.getActiveCompactions();
+ return instanceOps.getActiveCompactions().stream().sorted(comparator)
+ .map(ActiveCompactionHelper::formatActiveCompactionLine);
} catch (AccumuloException | AccumuloSecurityException e) {
return Stream.of("ERROR " + e.getMessage());
}
- Comparator<ActiveCompaction> comparator = Comparator.comparing(ac ->
ac.getHost().getAddress());
- comparator = comparator.thenComparing(ac -> ac.getHost().getPort())
- .thenComparing((o1, o2) -> (int) (o2.getAge() - o1.getAge()));
-
- activeCompactions.sort(comparator);
-
- return activeCompactions.stream().map(ac ->
formatActiveCompactionLine(ac));
}
}
diff --git
a/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
b/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
index eba3c99719..7dcba79f7c 100644
---
a/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
+++
b/shell/src/main/java/org/apache/accumulo/shell/commands/ListCompactionsCommand.java
@@ -55,7 +55,7 @@ public class ListCompactionsCommand extends Command {
activeCompactionStream = ActiveCompactionHelper
.activeCompactionsForServer(cl.getOptionValue(tserverOption.getOpt()),
instanceOps);
} else {
- activeCompactionStream = ActiveCompactionHelper.stream(instanceOps);
+ activeCompactionStream =
ActiveCompactionHelper.activeCompactions(instanceOps);
}
if (cl.hasOption(filterOption.getOpt())) {