23
23
import java .util .Collection ;
24
24
import java .util .HashMap ;
25
25
import java .util .HashSet ;
26
+ import java .util .Iterator ;
26
27
import java .util .List ;
27
28
import java .util .Map ;
28
29
import java .util .Map .Entry ;
29
30
import java .util .Set ;
30
31
import java .util .UUID ;
32
+ import java .util .concurrent .ExecutionException ;
31
33
import java .util .concurrent .ExecutorService ;
34
+ import java .util .concurrent .Future ;
32
35
import java .util .concurrent .TimeUnit ;
33
36
import java .util .concurrent .atomic .AtomicBoolean ;
34
37
import java .util .concurrent .atomic .AtomicLong ;
@@ -271,9 +274,9 @@ private long removeTabletServerMarkers(Map<UUID,TServerInstance> uidMap,
271
274
return result ;
272
275
}
273
276
274
- private void removeFile (ExecutorService deleteThreadPool , Path path , AtomicLong counter ,
277
+ private Future <?> removeFile (ExecutorService deleteThreadPool , Path path , AtomicLong counter ,
275
278
String msg ) {
276
- deleteThreadPool .execute (() -> {
279
+ return deleteThreadPool .submit (() -> {
277
280
try {
278
281
log .debug (msg );
279
282
if (!useTrash || !fs .moveToTrash (path )) {
@@ -283,42 +286,77 @@ private void removeFile(ExecutorService deleteThreadPool, Path path, AtomicLong
283
286
} catch (FileNotFoundException ex ) {
284
287
// ignored
285
288
} catch (IOException ex ) {
286
- log .error ("Unable to delete wal {}" , path , ex );
289
+ log .error ("Unable to delete {}" , path , ex );
287
290
}
288
291
});
289
292
}
290
293
291
294
private long removeFiles (Collection <Pair <WalState ,Path >> collection , final GCStatus status ) {
292
295
293
296
final ExecutorService deleteThreadPool = ThreadPools .getServerThreadPools ()
294
- .createExecutorService (context .getConfiguration (), Property .GC_DELETE_THREADS );
297
+ .createExecutorService (context .getConfiguration (), Property .GC_DELETE_WAL_THREADS );
298
+
299
+ final Map <Path ,Future <?>> futures = new HashMap <>(collection .size ());
295
300
final AtomicLong counter = new AtomicLong ();
296
301
297
302
for (Pair <WalState ,Path > stateFile : collection ) {
298
303
Path path = stateFile .getSecond ();
299
- removeFile (deleteThreadPool , path , counter ,
300
- "Removing " + stateFile .getFirst () + " WAL " + path );
304
+ futures . put ( path , removeFile (deleteThreadPool , path , counter ,
305
+ "Removing " + stateFile .getFirst () + " WAL " + path )) ;
301
306
}
302
307
308
+ while (!futures .isEmpty ()) {
309
+ Iterator <Entry <Path ,Future <?>>> iter = futures .entrySet ().iterator ();
310
+ while (iter .hasNext ()) {
311
+ Entry <Path ,Future <?>> f = iter .next ();
312
+ if (f .getValue ().isDone ()) {
313
+ try {
314
+ iter .remove ();
315
+ f .getValue ().get ();
316
+ } catch (InterruptedException | ExecutionException e ) {
317
+ throw new RuntimeException ("Uncaught exception deleting wal file" + f .getKey (), e );
318
+ }
319
+ }
320
+ }
321
+ }
303
322
deleteThreadPool .shutdown ();
304
323
try {
305
324
while (!deleteThreadPool .awaitTermination (1000 , TimeUnit .MILLISECONDS )) { // empty
306
325
}
307
326
} catch (InterruptedException e1 ) {
308
327
log .error ("{}" , e1 .getMessage (), e1 );
309
328
}
329
+ status .currentLog .deleted += counter .get ();
310
330
return counter .get ();
311
331
}
312
332
313
333
private long removeFiles (Collection <Path > values ) {
334
+
314
335
final ExecutorService deleteThreadPool = ThreadPools .getServerThreadPools ()
315
- .createExecutorService (context .getConfiguration (), Property .GC_DELETE_THREADS );
336
+ .createExecutorService (context .getConfiguration (), Property .GC_DELETE_WAL_THREADS );
337
+ final Map <Path ,Future <?>> futures = new HashMap <>(values .size ());
316
338
final AtomicLong counter = new AtomicLong ();
317
339
318
340
for (Path path : values ) {
319
- removeFile (deleteThreadPool , path , counter , "Removing recovery log " + path );
341
+ futures .put (path ,
342
+ removeFile (deleteThreadPool , path , counter , "Removing recovery log " + path ));
320
343
}
321
344
345
+ while (!futures .isEmpty ()) {
346
+ Iterator <Entry <Path ,Future <?>>> iter = futures .entrySet ().iterator ();
347
+ while (iter .hasNext ()) {
348
+ Entry <Path ,Future <?>> f = iter .next ();
349
+ if (f .getValue ().isDone ()) {
350
+ try {
351
+ iter .remove ();
352
+ f .getValue ().get ();
353
+ } catch (InterruptedException | ExecutionException e ) {
354
+ throw new RuntimeException ("Uncaught exception deleting recovery log file" + f .getKey (),
355
+ e );
356
+ }
357
+ }
358
+ }
359
+ }
322
360
deleteThreadPool .shutdown ();
323
361
try {
324
362
while (!deleteThreadPool .awaitTermination (1000 , TimeUnit .MILLISECONDS )) { // empty
0 commit comments