Skip to content

Commit 1e9fea4

Browse files
committed
fix(batch): implement review suggestions
1 parent 7bf805d commit 1e9fea4

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/main/java/io/weaviate/client6/v1/api/collections/batch/BatchContext.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Collection;
99
import java.util.EnumSet;
1010
import java.util.List;
11+
import java.util.Objects;
1112
import java.util.concurrent.ArrayBlockingQueue;
1213
import java.util.concurrent.BlockingQueue;
1314
import java.util.concurrent.CancellationException;
@@ -409,7 +410,7 @@ void setState(State nextState) {
409410
State prev = state;
410411
state = nextState;
411412
state.onEnter(prev);
412-
stateChanged.signal();
413+
stateChanged.signalAll();
413414
} finally {
414415
lock.unlock();
415416
}
@@ -726,18 +727,21 @@ private void onAcks(Event.Acks acks) {
726727
if (!acks.acked().containsAll(removed)) {
727728
throw ProtocolViolationException.incompleteAcks(List.copyOf(removed));
728729
}
729-
acks.acked().forEach(id -> {
730-
TaskHandle task = wip.get(id);
731-
if (task != null) {
732-
task.setAcked();
733-
}
734-
});
730+
acks.acked().stream()
731+
.map(wip::get).filter(Objects::nonNull)
732+
.forEach(TaskHandle::setAcked);
733+
735734
setState(ACTIVE);
736735
}
737736

738737
private void onResults(Event.Results results) {
739-
results.successful().forEach(id -> wip.remove(id).setSuccess());
740-
results.errors().forEach((id, error) -> wip.remove(id).setError(error));
738+
results.successful().stream()
739+
.map(wip::remove).filter(Objects::nonNull)
740+
.forEach(TaskHandle::setSuccess);
741+
742+
results.errors().keySet().stream()
743+
.map(wip::remove).filter(Objects::nonNull)
744+
.forEach(taskHandle -> taskHandle.setError(results.errors().get(taskHandle.id())));
741745
}
742746

743747
private void onBackoff(Event.Backoff backoff) {
@@ -916,7 +920,7 @@ public void onEvent(Event event) {
916920
if (retries == maxRetries) {
917921
onEvent(new Event.ClientError(new IOException("Server unavailable")));
918922
} else {
919-
reconnectAfter(2 ^ retries);
923+
reconnectAfter((long) Math.pow(2, retries));
920924
}
921925
} else if (event == Event.EOF) {
922926
throw ProtocolViolationException.illegalStateTransition(this, event);

src/main/java/io/weaviate/client6/v1/api/collections/batch/DuplicateTaskException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class DuplicateTaskException extends WeaviateException {
1010
private final TaskHandle existing;
1111

1212
DuplicateTaskException(TaskHandle duplicate, TaskHandle existing) {
13-
super("%s cannot be added to the batch while another task with the same ID is in progress");
13+
super(duplicate + " cannot be added to the batch while another task with the same ID is in progress");
1414
this.existing = existing;
1515
}
1616

src/main/java/io/weaviate/client6/v1/api/collections/batch/ProtocolViolationException.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,5 @@ static ProtocolViolationException incompleteAcks(List<String> remaining) {
4343
requireNonNull(remaining, "remaining is null");
4444
return new ProtocolViolationException("IDs from previous Data message missing in Acks: '%s', ... (%d more)"
4545
.formatted(remaining.get(0), remaining.size() - 1));
46-
4746
}
4847
}

0 commit comments

Comments
 (0)