Commit 7ef9f80f authored by Matija Obreza's avatar Matija Obreza

Better response to accession upsert

- Catch more exceptions
- Log failed ES documents
- Increased transaction timeout in AccessionUploader
parent 055e0804
......@@ -58,6 +58,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.FacetedPage;
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
......@@ -386,7 +387,14 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
if (!queries.isEmpty()) {
LOG.debug("Indexing {} count={} of provided objects count={}", className, queries.size(), ids.size());
elasticsearchTemplate.bulkIndex(queries);
try {
elasticsearchTemplate.bulkIndex(queries);
} catch (ElasticsearchException e) {
LOG.warn("Elasticsearch bulkIndex failed", e.getMessage());
if (e.getFailedDocuments() != null) {
e.getFailedDocuments().forEach((a, b) -> LOG.warn("Failed document {} {}", a, b));
}
}
}
}
......
......@@ -112,7 +112,7 @@ public class AccessionUploader implements InitializingBean {
* @param updates the updates
* @throws IOException
*/
@Transactional(timeout = 200, isolation = Isolation.READ_UNCOMMITTED, rollbackFor = Throwable.class)
@Transactional(timeout = 250, isolation = Isolation.READ_UNCOMMITTED, rollbackFor = Throwable.class)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE')")
public List<AccessionOpResponse> upsertAccessions(FaoInstitute institute, ArrayNode updates) {
assert (updates.isArray());
......@@ -420,6 +420,7 @@ public class AccessionUploader implements InitializingBean {
}
}
@Transactional(timeout = 250, isolation = Isolation.READ_UNCOMMITTED, rollbackFor = Throwable.class)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE')")
public List<AccessionOpResponse> deleteAccessions(FaoInstitute institute, List<AccessionHeaderJson> identifiers) {
// Security check
......
......@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.persistence.PersistenceException;
import javax.persistence.RollbackException;
import org.apache.commons.lang3.RandomUtils;
......@@ -49,6 +50,7 @@ import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
......@@ -211,7 +213,7 @@ public class AccessionController extends RestController {
for (int tryCount = 0; tryCount < UPLOAD_RETRIES; tryCount++) {
try {
return uploader.upsertAccessions(institute, updates);
} catch (TransactionException | RollbackException | CannotAcquireLockException | DataIntegrityViolationException e) {
} catch (DataAccessException | TransactionException | PersistenceException e) {
return upsert1By1(institute, updates);
} catch (PleaseRetryException e) {
LOG.error("Retry {} of {} tries due to: {}", tryCount, UPLOAD_RETRIES, e.getMessage());
......@@ -287,7 +289,7 @@ public class AccessionController extends RestController {
try {
response = uploader.deleteAccessions(institute, batch);
LOG.info("Deleted {} accessions from {}", response.size(), instCode);
} catch (TransactionException | RollbackException | CannotAcquireLockException | DataIntegrityViolationException e) {
} catch (DataAccessException | TransactionException | PersistenceException e) {
LOG.info("Retrying delete one by one due to {}", e.getMessage());
response = deleteAccessions1by1(institute, batch);
}
......
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