Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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