Skip to content

Commit

Permalink
process batchWriteSize <= 0, update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Dec 18, 2023
1 parent adadde9 commit 6c65c54
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/main/asciidoc/reference/configure-data-settings.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ Limit amount of results returned by server. Non-positive value means no limit.

*Default*: `10 000`.

[[configure-data-settings.batch-write-size]]
=== batchWriteSize

Maximum batch size for batch write operations. Non-positive value means no limit.

*Default*: `100`.

[[configure-data-settings.keep-original-key-types]]
=== keepOriginalKeyTypes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private <T> void applyBufferedBatchWrite(Iterable<T> documents, String setName,
List<T> docsList = new ArrayList<>();

for (T doc : documents) {
if (docsList.size() == batchSize) {
if (batchWriteSizeMatch(batchSize, docsList.size())) {
batchWriteAllDocuments(docsList, setName, operationName);
docsList.clear();
}
Expand Down Expand Up @@ -431,7 +431,7 @@ public <T> void deleteByIds(Iterable<?> ids, Class<T> entityClass) {
int batchSize = converter.getAerospikeDataSettings().getBatchWriteSize();
List<Object> idsList = new ArrayList<>();
for (Object id : ids) {
if (idsList.size() == batchSize) {
if (batchWriteSizeMatch(batchSize, idsList.size())) {
deleteByIds(idsList, setName);
idsList.clear();
}
Expand Down Expand Up @@ -818,7 +818,7 @@ public <T, S> List<S> findByIds(Iterable<?> ids, Class<T> entityClass, Class<S>
List<S> result = new ArrayList<>();

for (Object id : ids) {
if (idsList.size() == batchSize) {
if (batchWriteSizeMatch(batchSize, idsList.size())) {
result = Stream.concat(
result.stream(),
((List<S>) findByIdsUsingQuery(idsList, entityClass, targetClass, setName, null)).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ public <T> BatchWriteData<T> getBatchWriteForUpdate(T document, String setName)
entity.hasVersionProperty());
}

protected boolean batchWriteSizeMatch(int batchSize, int currentSize) {
return batchSize > 0 && currentSize == batchSize;
}

protected void validateForBatchWrite(Iterable<?> iterable, String nameOfIterable) {
Assert.notNull(iterable, nameOfIterable + " must not be null!");
Assert.isTrue(batchWriteSupported(), "Batch write operations are supported starting with the major " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private <T> Flux<T> applyBufferedBatchWrite(Iterable<? extends T> documents, Str
Flux<T> result = Flux.empty();

for (T doc : documents) {
if (docsList.size() == batchSize) {
if (batchWriteSizeMatch(batchSize, docsList.size())) {
result = Flux.concat(result, batchWriteAllDocuments(docsList, setName, operationName));
docsList.clear();
}
Expand Down Expand Up @@ -436,7 +436,7 @@ public Mono<Void> deleteByIds(Iterable<?> ids, String setName) {
List<Object> idsList = new ArrayList<>();
Flux<Void> result = Flux.empty();
for (Object id : ids) {
if (idsList.size() == batchSize) {
if (batchWriteSizeMatch(batchSize, idsList.size())) {
result = deleteByIds(idsList, setName).concatWith(result);
idsList.clear();
}
Expand Down Expand Up @@ -735,7 +735,7 @@ public <T> Flux<T> findByIds(Iterable<?> ids, Class<T> targetClass, String setNa
Flux<T> result = Flux.empty();

for (Object id : ids) {
if (idsList.size() == batchSize) {
if (batchWriteSizeMatch(batchSize, idsList.size())) {
result = Flux.concat(result, findByIds(idsList, targetClass, setName));
idsList.clear();
}
Expand Down

0 comments on commit 6c65c54

Please sign in to comment.