Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Journal Sync wrong stats #3988

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -372,8 +372,8 @@ public static class ForceWriteRequest {
private long logId;
private boolean flushed;

public int process(ObjectHashSet<BookieRequestHandler> writeHandlers) {
closeFileIfNecessary();
public int process(ObjectHashSet<BookieRequestHandler> writeHandlers, JournalStats journalStats) {
closeFileIfNecessary(journalStats);

// Notify the waiters that the force write succeeded
for (int i = 0; i < forceWriteWaiters.size(); i++) {
Expand All @@ -390,20 +390,29 @@ public int process(ObjectHashSet<BookieRequestHandler> writeHandlers) {
return forceWriteWaiters.size();
}

private void flushFileToDisk() throws IOException {
private void flushFileToDisk(JournalStats journalStats) throws IOException {
if (!flushed) {
logFile.forceWrite(false);
flushed = true;
long fsyncStartTime = MathUtils.nowInNano();
try {
logFile.forceWrite(false);
flushed = true;
journalStats.getJournalSyncStats().registerSuccessfulEvent(MathUtils.elapsedNanos(fsyncStartTime),
TimeUnit.NANOSECONDS);
} catch (IOException ioe) {
journalStats.getJournalSyncStats()
.registerFailedEvent(MathUtils.elapsedNanos(fsyncStartTime), TimeUnit.NANOSECONDS);
throw ioe;
}
}
}

public void closeFileIfNecessary() {
public void closeFileIfNecessary(JournalStats journalStats) {
// Close if shouldClose is set
if (shouldClose) {
// We should guard against exceptions so its
// safe to call in catch blocks
try {
flushFileToDisk();
flushFileToDisk(journalStats);
logFile.close();
// Call close only once
shouldClose = false;
Expand Down Expand Up @@ -507,7 +516,7 @@ public void run() {
// responses
for (int i = 0; i < requestsCount; i++) {
ForceWriteRequest req = localRequests[i];
numEntriesInLastForceWrite += req.process(writeHandlers);
numEntriesInLastForceWrite += req.process(writeHandlers, journalStats);
localRequests[i] = null;
req.recycle();
}
Expand All @@ -534,17 +543,8 @@ public void run() {
}

private void syncJournal(ForceWriteRequest lastRequest) throws IOException {
long fsyncStartTime = MathUtils.nowInNano();
try {
lastRequest.flushFileToDisk();
journalStats.getJournalSyncStats().registerSuccessfulEvent(MathUtils.elapsedNanos(fsyncStartTime),
TimeUnit.NANOSECONDS);
lastLogMark.setCurLogMark(lastRequest.logId, lastRequest.lastFlushedPosition);
} catch (IOException ioe) {
journalStats.getJournalSyncStats()
.registerFailedEvent(MathUtils.elapsedNanos(fsyncStartTime), TimeUnit.NANOSECONDS);
throw ioe;
}
lastRequest.flushFileToDisk(journalStats);
lastLogMark.setCurLogMark(lastRequest.logId, lastRequest.lastFlushedPosition);
}

// shutdown sync thread
Expand Down