Commit 19595ea7 authored by Matija Obreza's avatar Matija Obreza

WorldClim DS: handle unique constraint violations when updating DS2 in parallel

parent 4cdf9e55
......@@ -59,6 +59,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.task.TaskExecutor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonParseException;
......@@ -218,7 +219,21 @@ public class WorldClimUpdater implements InitializingBean {
for (int fromIndex = 0; fromIndex < tileIndexes.size(); fromIndex += batchSize) {
HashSet<Long> ids = new HashSet<Long>(tileIndexes.subList(fromIndex, Math.min(fromIndex + batchSize, tileIndexes.size())));
LOG.info("Processing variable {} for tileIndexes: {}-{} of {}", variableName, fromIndex, fromIndex + ids.size(), tileIndexes.size());
dsService.worldclimUpdate(dataset, worldclimDescriptor, ids, buffer, nullValue, factor);
for (int i = 5; i >= 0; i--) {
try {
dsService.worldclimUpdate(dataset, worldclimDescriptor, ids, buffer, nullValue, factor);
break; // break try-5-times loop
} catch (DataIntegrityViolationException e) {
if (i == 0) {
throw e;
}
try {
Thread.sleep(250);
} catch (InterruptedException e1) {
}
}
}
}
LOG.info("Done processing {}", variableName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment