Skip to content

Commit

Permalink
Forget to close preAllocator log on shutdown (apache#2819)
Browse files Browse the repository at this point in the history
* Forget to close preAllocator log on shutdown

* Fix synchronize problem

* handle InterruptedException
  • Loading branch information
shoothzj authored Oct 22, 2021
1 parent 53954ca commit e10f3fe
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.bookie.EntryLogger.BufferedLogChannel;
Expand Down Expand Up @@ -182,6 +183,24 @@ private synchronized BufferedLogChannel allocateNewLog(File dirForNextEntryLog,
return logChannel;
}


private synchronized void closePreAllocateLog() {
if (preallocatedLogId != -1) {
// if preallocate new log success, release the file channel
try {
BufferedLogChannel bufferedLogChannel = getPreallocationFuture().get(3, TimeUnit.SECONDS);
if (bufferedLogChannel != null) {
bufferedLogChannel.close();
}
} catch (InterruptedException e) {
log.warn("interrupted while release preAllocate log");
Thread.currentThread().interrupt();
} catch (IOException | ExecutionException | TimeoutException e) {
log.warn("release preAllocate log failed, ignore error");
}
}
}

/**
* writes the given id to the "lastId" file in the given directory.
*/
Expand All @@ -208,6 +227,7 @@ private void setLastLogId(File dir, long logId) throws IOException {
*/
void stop() {
// wait until the preallocation finished.
allocatorExecutor.execute(this::closePreAllocateLog);
allocatorExecutor.shutdown();
try {
if (!allocatorExecutor.awaitTermination(5, TimeUnit.SECONDS)) {
Expand All @@ -218,7 +238,6 @@ void stop() {
Thread.currentThread().interrupt();
}
allocatorExecutor.shutdownNow();

log.info("Stopped entry logger preallocator.");
}

Expand Down

0 comments on commit e10f3fe

Please sign in to comment.