Skip to content

Commit 7f0ba70

Browse files
committed
Improves GC logging
Adds batch counter to log messages. Adds in-progress counters to long-running methods.
1 parent 5847052 commit 7f0ba70

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

server/gc/src/main/java/org/apache/accumulo/gc/GCRun.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.FileNotFoundException;
2727
import java.io.IOException;
28+
import java.time.Duration;
2829
import java.util.ArrayList;
2930
import java.util.Collection;
3031
import java.util.Collections;
@@ -38,6 +39,7 @@
3839
import java.util.SortedMap;
3940
import java.util.concurrent.ExecutorService;
4041
import java.util.concurrent.TimeUnit;
42+
import java.util.concurrent.atomic.AtomicInteger;
4143
import java.util.stream.Stream;
4244

4345
import org.apache.accumulo.core.Constants;
@@ -65,6 +67,7 @@
6567
import org.apache.accumulo.core.metadata.schema.TabletsMetadata;
6668
import org.apache.accumulo.core.security.Authorizations;
6769
import org.apache.accumulo.core.util.Pair;
70+
import org.apache.accumulo.core.util.Timer;
6871
import org.apache.accumulo.core.util.UtilWaitThread;
6972
import org.apache.accumulo.core.util.threads.ThreadPools;
7073
import org.apache.accumulo.core.volume.Volume;
@@ -99,12 +102,14 @@ public class GCRun implements GarbageCollectionEnvironment {
99102
private long inUse = 0;
100103
private long deleted = 0;
101104
private long errors = 0;
105+
private AtomicInteger batchCount;
102106

103107
public GCRun(Ample.DataLevel level, ServerContext context) {
104108
this.log = LoggerFactory.getLogger(GCRun.class.getName() + "." + level.name());
105109
this.level = level;
106110
this.context = context;
107111
this.config = context.getConfiguration();
112+
this.batchCount = new AtomicInteger(0);
108113
}
109114

110115
@Override
@@ -132,7 +137,8 @@ public void deleteGcCandidates(Collection<GcCandidate> gcCandidates, GcCandidate
132137
return;
133138
}
134139

135-
log.info("Attempting to delete gcCandidates of type {} from metadata", type);
140+
log.info("Batch {} attempting to delete {} gcCandidates of type {} from metadata",
141+
batchCount.get(), gcCandidates.size(), type);
136142
context.getAmple().deleteGcCandidates(level, gcCandidates, type);
137143
}
138144

@@ -143,6 +149,7 @@ public List<GcCandidate> readCandidatesThatFitInMemory(Iterator<GcCandidate> can
143149
long candidateBatchSize = getCandidateBatchSize() / 2;
144150

145151
List<GcCandidate> candidatesBatch = new ArrayList<>();
152+
batchCount.incrementAndGet();
146153

147154
while (candidates.hasNext()) {
148155
GcCandidate candidate = candidates.next();
@@ -295,8 +302,12 @@ public void deleteConfirmedCandidates(SortedMap<String,GcCandidate> confirmedDel
295302

296303
final List<Pair<Path,Path>> replacements = context.getVolumeReplacements();
297304

305+
log.debug("Batch {} attempting to delete {} gcCandidate files", batchCount.get(),
306+
confirmedDeletes.size());
307+
int deleteCounter = 0;
308+
Timer timer = Timer.startNew();
298309
for (final GcCandidate delete : confirmedDeletes.values()) {
299-
310+
deleteCounter++;
300311
Runnable deleteTask = () -> {
301312
boolean removeFlag = false;
302313

@@ -320,7 +331,7 @@ public void deleteConfirmedCandidates(SortedMap<String,GcCandidate> confirmedDel
320331
}
321332

322333
for (Path pathToDel : GcVolumeUtil.expandAllVolumesUri(fs, fullPath)) {
323-
log.debug("{} Deleting {}", fileActionPrefix, pathToDel);
334+
log.debug("Batch {} {} Deleting {}", batchCount.get(), fileActionPrefix, pathToDel);
324335

325336
if (moveToTrash(pathToDel) || fs.deleteRecursively(pathToDel)) {
326337
// delete succeeded, still want to delete
@@ -368,6 +379,11 @@ public void deleteConfirmedCandidates(SortedMap<String,GcCandidate> confirmedDel
368379
};
369380

370381
deleteThreadPool.execute(deleteTask);
382+
if (timer.hasElapsed(Duration.ofMinutes(1))) {
383+
log.info("Batch {} deleting file {} of {}", batchCount.get(), deleteCounter,
384+
confirmedDeletes.size());
385+
timer.restart();
386+
}
371387
}
372388

373389
deleteThreadPool.shutdown();
@@ -451,7 +467,10 @@ static void minimizeDeletes(SortedMap<String,GcCandidate> confirmedDeletes,
451467

452468
String lastDirRel = null;
453469
Path lastDirAbs = null;
470+
Timer progressTimer = Timer.startNew();
471+
int progressCount = 0;
454472
while (cdIter.hasNext()) {
473+
progressCount++;
455474
Map.Entry<String,GcCandidate> entry = cdIter.next();
456475
String relPath = entry.getKey();
457476
Path absPath = new Path(entry.getValue().getPath());
@@ -492,6 +511,10 @@ static void minimizeDeletes(SortedMap<String,GcCandidate> confirmedDeletes,
492511
}
493512
}
494513
}
514+
if (progressTimer.hasElapsed(Duration.ofMinutes(1))) {
515+
logger.debug("Minimizing delete {} of {}", progressCount, confirmedDeletes.size());
516+
progressTimer.restart();
517+
}
495518
}
496519

497520
/**

server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ public long collect(GarbageCollectionEnvironment gce)
387387

388388
Iterator<GcCandidate> candidatesIter = gce.getCandidates();
389389
long totalBlips = 0;
390+
int batchCount = 0;
390391

391392
while (candidatesIter.hasNext()) {
392393
List<GcCandidate> batchOfCandidates;
@@ -399,19 +400,21 @@ public long collect(GarbageCollectionEnvironment gce)
399400
} finally {
400401
candidatesSpan.end();
401402
}
402-
totalBlips = deleteBatch(gce, batchOfCandidates);
403+
batchCount++;
404+
totalBlips = deleteBatch(gce, batchOfCandidates, batchCount);
403405
}
404406
return totalBlips;
405407
}
406408

407409
/**
408410
* Given a sub-list of possible deletion candidates, process and remove valid deletion candidates.
409411
*/
410-
private long deleteBatch(GarbageCollectionEnvironment gce, List<GcCandidate> currentBatch)
411-
throws InterruptedException, TableNotFoundException, IOException {
412+
private long deleteBatch(GarbageCollectionEnvironment gce, List<GcCandidate> currentBatch,
413+
int batchCount) throws InterruptedException, TableNotFoundException, IOException {
412414

413415
long origSize = currentBatch.size();
414416
gce.incrementCandidatesStat(origSize);
417+
log.debug("Batch {} total deletion candidates: {}", batchCount, origSize);
415418

416419
SortedMap<String,GcCandidate> candidateMap = makeRelative(currentBatch);
417420

0 commit comments

Comments
 (0)