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

ChunkRunner spawning a thousands of chunk-checkpoint-timer threads #120

Open
wants to merge 3 commits into
base: main
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 @@ -13,8 +13,6 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.batch.api.chunk.CheckpointAlgorithm;
import javax.batch.api.chunk.ItemProcessor;
Expand Down Expand Up @@ -313,7 +311,7 @@ private void readProcessWriteItems() throws Exception {
processingInfo.chunkState == ChunkState.RETRYING ||
processingInfo.chunkState == ChunkState.TO_END_RETRY) {
if (processingInfo.chunkState == ChunkState.TO_START_NEW || processingInfo.chunkState == ChunkState.TO_END_RETRY) {
processingInfo.reset();
processingInfo.reset(timeLimit);
}
//if during Chunk RETRYING, and an item is skipped, the ut is still active so no need to begin a new one
if (tm.getStatus() != Status.STATUS_ACTIVE) {
Expand Down Expand Up @@ -505,16 +503,8 @@ private void checkIfEndRetry(final ProcessingInfo processingInfo) {
}

private void beginCheckpoint(final ProcessingInfo processingInfo) throws Exception {
if (checkpointPolicy.equals("item")) {
if (timeLimit > 0) {
final Timer timer = new Timer("chunk-checkpoint-timer", true);
timer.schedule(new TimerTask() {
@Override
public void run() {
processingInfo.timerExpired = true;
}
}, timeLimit * 1000);
}
if (checkpointPolicy.equals("item") && timeLimit > 0) {
processingInfo.expiresAt = timeLimit * 1_000_000L + System.nanoTime();
}
//if chunk is already RETRYING, do not change it to RUNNING
if (processingInfo.chunkState == ChunkState.TO_RETRY) {
Expand Down Expand Up @@ -542,7 +532,7 @@ private boolean isReadyToCheckpoint(final ProcessingInfo processingInfo) throws
return true;
}
if (timeLimit > 0) {
return processingInfo.timerExpired;
return processingInfo.timerExpired();
}
return false;
}
Expand Down Expand Up @@ -838,7 +828,7 @@ private static final class ProcessingInfo {
*/
int count;

boolean timerExpired;
long expiresAt;
ItemState itemState = ItemState.RUNNING;
ChunkState chunkState = ChunkState.TO_START_NEW;

Expand All @@ -858,9 +848,9 @@ private static final class ProcessingInfo {
*/
Integer failurePoint;

private void reset() {
private void reset(final int timeLimit) {
count = 0;
timerExpired = false;
expiresAt = timeLimit * 1_000_000L + System.nanoTime();
itemState = ItemState.RUNNING;
chunkState = ChunkState.RUNNING;
failurePoint = null;
Expand All @@ -871,12 +861,16 @@ private boolean toStopItem() {
itemState == ItemState.TO_RETRY_READ || itemState == ItemState.TO_RETRY_PROCESS ||
itemState == ItemState.TO_RETRY_WRITE;
}

private boolean timerExpired() {
return System.nanoTime() > expiresAt;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("ProcessingInfo{");
sb.append("count=").append(count);
sb.append(", timerExpired=").append(timerExpired);
sb.append(", timerExpired=").append(timerExpired());
sb.append(", itemState=").append(itemState);
sb.append(", chunkState=").append(chunkState);
sb.append(", checkpointPosition=").append(checkpointPosition);
Expand Down