You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "loserwang1024 (via GitHub)" <gi...@apache.org> on 2026/09/08 07:08:07 UTC
[I] [Bug] Fetch may fail during non-atomic remote log offset updates [fluss]
loserwang1024 opened a new issue, #4247:
URL: https://github.com/apache/fluss/issues/4247
### Search before asking
- [x] I searched in the [issues](https://github.com/apache/fluss/issues) and found nothing similar.
### Fluss version
0.9.0 (latest release)
### Please describe the bug š
### Description
A fetch may temporarily fail with `LOG_OFFSET_OUT_OF_RANGE_EXCEPTION` after local log segments have been removed but before `remoteLogEndOffset` is updated.
The relevant update sequence after committing a remote log manifest is:
```java
logTablet.updateRemoteLogStartOffset(newRemoteLogStartOffset);
logTablet.updateHighestCopiedEndOffset(
newRemoteLogManifest.getHighestCopiedEndOffset());
logTablet.updateRemoteLogEndOffset(newRemoteLogEndOffset);
```
`updateHighestCopiedEndOffset()` immediately invokes local segment cleanup:
```java
public void updateHighestCopiedEndOffset(long highestCopiedEndOffset) {
if (highestCopiedEndOffset > this.highestCopiedEndOffset) {
this.highestCopiedEndOffset = highestCopiedEndOffset;
deleteSegmentsAlreadyExistsInRemote();
}
}
```
However, remote fetch eligibility is checked against `remoteLogEndOffset`:
```java
public boolean canFetchFromRemoteLog(long fetchOffset) {
return remoteLogStartOffset <= fetchOffset
&& fetchOffset < remoteLogEndOffset;
}
```
This creates a window where:
```text
remoteLogEndOffset < fetchOffset < localLogStartOffset
```
The offset is no longer available locally, but remote fetching is still rejected.
### Reproduction
```java
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.fluss.server.log.remote;
import org.apache.fluss.metadata.TableBucket;
import org.apache.fluss.remote.RemoteLogManifest;
import org.apache.fluss.remote.RemoteLogSegment;
import org.apache.fluss.rpc.entity.FetchLogResultForBucket;
import org.apache.fluss.rpc.protocol.ApiError;
import org.apache.fluss.rpc.protocol.Errors;
import org.apache.fluss.server.entity.FetchReqInfo;
import org.apache.fluss.server.log.FetchParams;
import org.apache.fluss.server.log.LogTablet;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import static org.apache.fluss.record.TestData.DATA1_TABLE_ID;
import static org.assertj.core.api.Assertions.assertThat;
/** ITCase for the atomicity of remote-log offset updates and local segment cleanup. */
final class RemoteLogOffsetUpdateITCase extends RemoteLogTestBase {
@Test
void testFetchBetweenHighestCopiedAndRemoteEndOffsetUpdates() throws Exception {
TableBucket tableBucket = new TableBucket(DATA1_TABLE_ID, 0);
makeLogTableAsLeader(tableBucket, false);
LogTablet logTablet = replicaManager.getReplicaOrException(tableBucket).getLogTablet();
// Local segments are [0,10), [10,20), [20,30), [30,40), and [40,50).
addMultiSegmentsToLogTablet(logTablet, 5);
// Materialize the remote segments so that the same fetch can recover once the remote-log
// end offset catches up.
List<RemoteLogSegment> remoteSegments = new ArrayList<>();
for (int i = 0; i < 4; i++) {
remoteSegments.add(copyLogSegmentToRemote(logTablet, remoteLogStorage, i));
}
RemoteLogTablet remoteLogTablet = remoteLogManager.remoteLogTablet(tableBucket);
remoteLogTablet.loadRemoteLogManifest(
new RemoteLogManifest(
logTablet.getPhysicalTablePath(), tableBucket, remoteSegments, 40L));
// Simulate the state before the next manifest update: remote is readable up to offset 20,
// while local still covers offset 25.
logTablet.updateRemoteLogStartOffset(0L);
logTablet.updateRemoteLogEndOffset(20L);
assertThat(logTablet.localLogStartOffset()).isEqualTo(20L);
assertThat(logTablet.canFetchFromRemoteLog(25L)).isFalse();
FetchLogResultForBucket localResult = fetch(tableBucket, 25L);
assertThat(localResult.getError()).isEqualTo(ApiError.NONE);
assertThat(localResult.fetchFromRemote()).isFalse();
// This is the update order used by LogTieringTask: advancing the copied watermark deletes
// the segment containing offset 25 before remoteLogEndOffset opens the remote-read gate.
// todo: this is the key test
logTablet.updateHighestCopiedEndOffset(40L);
assertThat(logTablet.localLogStartOffset()).isEqualTo(30L);
assertThat(logTablet.canFetchFromRemoteLog(25L)).isFalse();
FetchLogResultForBucket gapResult = fetch(tableBucket, 25L);
assertThat(gapResult.getErrorCode())
.isEqualTo(Errors.LOG_OFFSET_OUT_OF_RANGE_EXCEPTION.code());
assertThat(gapResult.fetchFromRemote()).isFalse();
// Once the following update runs, the same offset is immediately readable from remote.
logTablet.updateRemoteLogEndOffset(40L);
assertThat(logTablet.canFetchFromRemoteLog(25L)).isTrue();
FetchLogResultForBucket remoteResult = fetch(tableBucket, 25L);
assertThat(remoteResult.getError()).isEqualTo(ApiError.NONE);
assertThat(remoteResult.fetchFromRemote()).isTrue();
}
private FetchLogResultForBucket fetch(TableBucket tableBucket, long fetchOffset)
throws Exception {
CompletableFuture<Map<TableBucket, FetchLogResultForBucket>> future =
new CompletableFuture<>();
replicaManager.fetchLogRecords(
new FetchParams(-1, Integer.MAX_VALUE),
Collections.singletonMap(
tableBucket,
new FetchReqInfo(
tableBucket.getTableId(), fetchOffset, 1024 * 1024)),
null,
future::complete);
return future.get().get(tableBucket);
}
}
```
### Solution
_No response_
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Fetch may fail during non-atomic remote log offset updates [fluss]
Posted by "ss666 (via GitHub)" <gi...@apache.org>.
ss666 commented on issue #4247:
URL: https://github.com/apache/fluss/issues/4247#issuecomment-5584115923
Could it be assigned to me?
I found that the same non-atomic update also occurs in `ReplicaManager.notifyRemoteLogOffsets()` and `RemoteLogManager.registerReplica()`, where the three offsets are applied in the same order.
Iād like to fix this by introducing a single `LogTablet.updateRemoteLogOffsets(startOffset, endOffset, highestCopiedEndOffset)` method. It will publish the entire remotely readable offset range first and then perform local segment cleanup once, with all three call sites routed through this method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Fetch may fail during non-atomic remote log offset updates [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong closed issue #4247: [Bug] Fetch may fail during non-atomic remote log offset updates
URL: https://github.com/apache/fluss/issues/4247
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Fetch may fail during non-atomic remote log offset updates [fluss]
Posted by "loserwang1024 (via GitHub)" <gi...@apache.org>.
loserwang1024 commented on issue #4247:
URL: https://github.com/apache/fluss/issues/4247#issuecomment-5584788973
@ss666 have you used Fluss in your production?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Fetch may fail during non-atomic remote log offset updates [fluss]
Posted by "ss666 (via GitHub)" <gi...@apache.org>.
ss666 commented on issue #4247:
URL: https://github.com/apache/fluss/issues/4247#issuecomment-5587043155
Thanks for the follow-up! I've reviewed the PR, and it looks good to me.
Have not used Fluss in production yet, but I'm interested in getting more involved in the Fluss community, learning from it, and contributing more PRs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org