forked from Alluxio/alluxio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add replay statistics for journal startup
This change adds some new logging messages to the master while replaying the journal. Specifically, it will now log the rate of journal entries applied to the state machine during the startup process. The number of entries in a particular interval are logged along with the current commit index and the expected entries remaining and estimated time left. In the embedded journal Instead, we use the Ratis "Commit Index" which represents batches of journal entries applied to the raft log. We are able to get the last commit index as well as track the most recently applied index which gives us the ability to provide the estimated time remaining. The last SN is more readily available in the UFSJournal since we control that implementation. A new function for the UfsJournalReader needed to be added in order to find the highest sequence number is within a particular journal. This allows us to get the estimated entries remaining and time left during the replay. The method should take O(N) with the number of journal log files. It does not read data from the log files. In the case where there is an error determining the highest SN, an empty optional is returned in which case the information about expected finish time and number of entries remaining is omitted. There is a case where an error occurs when retrieving the final commit index. In this case, the optional variable with the index will not be populated and the estimated time remaining statistics will not be calculated, only the measured rate of entries being applied. pr-link: Alluxio#13107 change-id: cid-1c072dd3380c5316fbe63a3fcd98c2a5c11c8416
- Loading branch information
Showing
7 changed files
with
303 additions
and
8 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
core/server/common/src/main/java/alluxio/master/journal/AbstractJournalProgressLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.journal; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.OptionalLong; | ||
import java.util.StringJoiner; | ||
|
||
/** | ||
* Class to abstract out progress logging for journal replay. | ||
*/ | ||
public abstract class AbstractJournalProgressLogger { | ||
private static final Logger LOG = LoggerFactory.getLogger(AbstractJournalProgressLogger.class); | ||
|
||
// could have been configurable. decided it is not really necessary. | ||
/** Max time to wait before actually logging. */ | ||
public static final long MAX_LOG_INTERVAL_MS = 30_000; | ||
|
||
private long mLastMeasuredTime; | ||
private long mLastCommitIdx; | ||
private long mLogCount; | ||
|
||
private final OptionalLong mEndCommitIdx; | ||
|
||
/** | ||
* Creates a new instance of {@link AbstractJournalProgressLogger}. | ||
* | ||
* @param endComitIdx the final commit index in the journal. Used to estimate completion time | ||
*/ | ||
public AbstractJournalProgressLogger(OptionalLong endComitIdx) { | ||
mEndCommitIdx = endComitIdx; | ||
mLastMeasuredTime = System.currentTimeMillis(); | ||
mLastCommitIdx = 0L; | ||
mLogCount = 0; | ||
} | ||
|
||
/** | ||
* @return the last applied commit index to a journal | ||
*/ | ||
public abstract long getLastAppliedIndex(); | ||
|
||
/** | ||
* @return the name of the journal | ||
*/ | ||
public abstract String getJournalName(); | ||
|
||
/** | ||
* Logs the progress of journal replay. | ||
* | ||
* This method rate limits itself on when it actually calculates and logs the message. If it is | ||
* called too frequently, then it will essentially be a no-op. The return value indicates whether | ||
* a message was logged or not as a result of calling the method. | ||
* | ||
* @return true is a message is logged, false otherwise | ||
*/ | ||
public boolean logProgress() { | ||
long now = System.currentTimeMillis(); | ||
long nextLogTime = | ||
1000L * Math.min(1L << (mLogCount > 30 ? 30 : mLogCount), MAX_LOG_INTERVAL_MS); | ||
// Exit early if log is called too fast. | ||
if ((now - mLastMeasuredTime) < nextLogTime) { | ||
return false; | ||
} | ||
long currCommitIdx = getLastAppliedIndex(); | ||
long timeSinceLastMeasure = (now - mLastMeasuredTime); | ||
long commitIdxRead = currCommitIdx - mLastCommitIdx; | ||
|
||
double commitIdxRateMs = ((double) commitIdxRead) / timeSinceLastMeasure; | ||
StringJoiner logMsg = new StringJoiner("|"); | ||
logMsg.add(getJournalName()); | ||
logMsg.add(String.format("current SN: %d", currCommitIdx)); | ||
logMsg.add(String.format("entries in last %dms=%d", timeSinceLastMeasure, commitIdxRead)); | ||
if (mEndCommitIdx.isPresent()) { | ||
long commitsRemaining = mEndCommitIdx.getAsLong() - currCommitIdx; | ||
double expectedTimeRemaining = ((double) commitsRemaining) / commitIdxRateMs; | ||
if (commitsRemaining > 0) { | ||
logMsg.add(String.format("est. commits left: %d", commitsRemaining)); | ||
} | ||
if (!Double.isNaN(expectedTimeRemaining) && !Double.isInfinite(expectedTimeRemaining) | ||
&& expectedTimeRemaining > 0) { | ||
logMsg.add(String.format("est. time remaining: %.2fms", expectedTimeRemaining)); | ||
} | ||
} | ||
mLogCount++; | ||
LOG.info(logMsg.toString()); | ||
mLastMeasuredTime = now; | ||
mLastCommitIdx = currCommitIdx; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/server/common/src/main/java/alluxio/master/journal/raft/RaftJournalProgressLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.journal.raft; | ||
|
||
import alluxio.master.journal.AbstractJournalProgressLogger; | ||
|
||
import java.util.OptionalLong; | ||
|
||
/** | ||
* Logs journal replay progress for the {@link RaftJournalSystem}. | ||
*/ | ||
public class RaftJournalProgressLogger extends AbstractJournalProgressLogger { | ||
|
||
private final JournalStateMachine mJournal; | ||
|
||
/** | ||
* Creates a new instance of the logger. | ||
* | ||
* @param journal the journal being replayed | ||
* @param endCommitIdx the final commit index in the log to estimate completion times | ||
*/ | ||
public RaftJournalProgressLogger(JournalStateMachine journal, OptionalLong endCommitIdx) { | ||
super(endCommitIdx); | ||
mJournal = journal; | ||
} | ||
|
||
@Override | ||
public long getLastAppliedIndex() { | ||
return mJournal.getLastAppliedCommitIndex(); | ||
} | ||
|
||
@Override | ||
public String getJournalName() { | ||
return "embedded journal"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
core/server/common/src/main/java/alluxio/master/journal/ufs/UfsJournalProgressLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.master.journal.ufs; | ||
|
||
import alluxio.master.journal.AbstractJournalProgressLogger; | ||
|
||
import java.util.OptionalLong; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Journal replay logger for the {@link UfsJournal}. | ||
*/ | ||
public class UfsJournalProgressLogger extends AbstractJournalProgressLogger { | ||
|
||
private final UfsJournal mJournal; | ||
private final Supplier<Long> mCommitSupplier; | ||
|
||
/** | ||
* Creates a new instance of the journal replay progress logger. | ||
* | ||
* @param journal the journal being replayed | ||
* @param endCommitIdx the final commit index (sequence number) in the journal | ||
* @param lastIndexSupplier supplier that gives the last applied commit (sequence number) | ||
*/ | ||
public UfsJournalProgressLogger(UfsJournal journal, OptionalLong endCommitIdx, | ||
Supplier<Long> lastIndexSupplier) { | ||
super(endCommitIdx); | ||
mJournal = journal; | ||
mCommitSupplier = lastIndexSupplier; | ||
} | ||
|
||
@Override | ||
public long getLastAppliedIndex() { | ||
return mCommitSupplier.get(); | ||
} | ||
|
||
@Override | ||
public String getJournalName() { | ||
return mJournal.toString(); | ||
} | ||
} |
Oops, something went wrong.