Storage returns error 500 when querying corrupted record
The GC Team observed issues with HTTP 500 status responses and attempted to resolve them by running a re-index on the Indexer Service. During this process, we discovered a problematic record: m19:master-data--Field:SZFIELD09MAY, which was created without any versions. This issue prevents the full re-index operation, consistently resulting in an HTTP 500 status.
Upon investigation, we identified a code segment in the Storage Service that appears to contribute to the issue.
Method: org.opengroup.osdu.storage.service.BatchServiceImpl#getMultipleRecords
for (String recordId : recordIds) {
RecordMetadata recordMetadata = recordsMetadata.get(CollaborationContextUtil.composeIdWithNamespace(recordId, collaborationContext));
if (recordMetadata == null || !recordMetadata.getStatus().equals(RecordState.active)) {
recordsNotFound.add(recordId);
continue;
}
validRecords.put(recordId, recordMetadata.getVersionPath(recordMetadata.getLatestVersion())); // recordMetadata.getLatestVersion() is null
}
This method retrieves metadata for multiple records and attempts to access the latest version of each record. If this.gcsVersionPaths.size()
is 0, it leads to a potential java.lang.IndexOutOfBoundsException
.
Method: org.opengroup.osdu.core.common.model.storage.RecordMetadata#getLatestVersion
public Long getLatestVersion() {
String latestVersionPath = this.gcsVersionPaths.get(this.gcsVersionPaths.size() - 1);
String[] versionTokens = latestVersionPath.split("/");
return Long.parseLong(versionTokens[versionTokens.length - 1]);
}
Exception Stack Trace:
Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
at java.base/java.util.Objects.checkIndex(Objects.java:361)
at java.base/java.util.ArrayList.get(ArrayList.java:427)
at org.opengroup.osdu.core.common.model.storage.RecordMetadata.getLatestVersion(RecordMetadata.java:79)