Skip to content

Commit

Permalink
refactor(s3stream/wal): simplify makeWriteOffsetMatchWindow
Browse files Browse the repository at this point in the history
Signed-off-by: Ning Yu <ningyu@automq.com>
  • Loading branch information
Chillax-0v0 committed Jan 2, 2024
1 parent b5fcdef commit ba1fd85
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,25 +347,15 @@ private void writeBlockData(BlockBatch blocks) throws IOException {
S3StreamMetricsManager.recordStageLatency(MetricsLevel.DEBUG, timer.elapsedAs(TimeUnit.NANOSECONDS), S3Stage.APPEND_WAL_WRITE);
}

private void makeWriteOffsetMatchWindow(long newWindowEndOffset) throws IOException, OverCapacityException {
private void makeWriteOffsetMatchWindow(long newWindowEndOffset) throws IOException {
// align to block size
newWindowEndOffset = WALUtil.alignLargeByBlockSize(newWindowEndOffset);
long windowStartOffset = windowCoreData.getStartOffset();
long windowMaxLength = windowCoreData.getMaxLength();
if (newWindowEndOffset > windowStartOffset + windowMaxLength) {
long newWindowMaxLength = newWindowEndOffset - windowStartOffset + scaleUnit;
if (newWindowMaxLength > upperLimit) {
// exceed upper limit
if (newWindowEndOffset - windowStartOffset <= upperLimit) {
// however, the new window length is still larger than upper limit, so we just set it to upper limit
newWindowMaxLength = upperLimit;
} else {
// the new window length is bigger than upper limit, reject this write request
LOGGER.error("new windows size {} exceeds upper limit {}, reject this write request, window start offset: {}, new window end offset: {}",
newWindowMaxLength, upperLimit, windowStartOffset, newWindowEndOffset);
throw new OverCapacityException(String.format("new windows size exceeds upper limit %d", upperLimit));
}
}
// endOffset - startOffset <= block.maxSize <= upperLimit in {@link #sealAndNewBlockLocked}
assert newWindowEndOffset - windowStartOffset <= upperLimit;
long newWindowMaxLength = Math.min(newWindowEndOffset - windowStartOffset + scaleUnit, upperLimit);
windowCoreData.scaleOutWindow(walHeaderFlusher, newWindowMaxLength);
}
}
Expand Down

0 comments on commit ba1fd85

Please sign in to comment.