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(issues1798): force expired data block after create timestamp exceed FORCE_EXPIRED_DELTA_MILLS #1804

Merged
merged 1 commit into from
Aug 15, 2024
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 @@ -22,25 +22,30 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

@EventLoopSafe public class DataBlock extends AbstractReferenceCounted {
private static final int UNREAD_INIT = -1;
private static final long FORCE_EXPIRED_DELTA_MILLS = TimeUnit.MINUTES.toMillis(4);
private final long objectId;
private final DataBlockIndex dataBlockIndex;
private final CompletableFuture<DataBlock> loadCf = new CompletableFuture<>();
private final CompletableFuture<DataBlock> freeCf = new CompletableFuture<>();
private final AtomicInteger unreadCnt = new AtomicInteger(UNREAD_INIT);
private ObjectReader.DataBlockGroup dataBlockGroup;
private final long createTimestamp;
private long lastAccessTimestamp;

private final ReadStatusChangeListener listener;
private final Time time;

public DataBlock(long objectId, DataBlockIndex dataBlockIndex, ReadStatusChangeListener observeListener, Time time) {
public DataBlock(long objectId, DataBlockIndex dataBlockIndex, ReadStatusChangeListener observeListener,
Time time) {
this.objectId = objectId;
this.dataBlockIndex = dataBlockIndex;
this.listener = observeListener;
this.createTimestamp = time.milliseconds();
this.lastAccessTimestamp = time.milliseconds();
this.time = time;
}
Expand Down Expand Up @@ -109,7 +114,7 @@ public void markRead() {
}

public boolean isExpired(long expiredTimestamp) {
return lastAccessTimestamp < expiredTimestamp;
return lastAccessTimestamp < expiredTimestamp || (createTimestamp + FORCE_EXPIRED_DELTA_MILLS) < expiredTimestamp;
}

@Override
Expand Down
Loading