Fix consecutive hyphens in export id#6194
Conversation
Signed-off-by: Hai Yan <oeyh@amazon.com>
| return truncateString(snapshotId, EXPORT_TASK_ID_MAX_LENGTH - 16) + "-export-" + UUID.randomUUID().toString().substring(0, 8); | ||
| String truncatedSnapshotId = truncateString(snapshotId, EXPORT_TASK_ID_MAX_LENGTH - 16); | ||
| // Remove trailing hyphens to prevent consecutive hyphens in the export task identifier | ||
| truncatedSnapshotId = truncatedSnapshotId.replaceAll("-+$", ""); |
There was a problem hiding this comment.
I think using "replaceAll" is expensive due to regular expressions. You can use either
- a while loop like
int endIndex = truncatedSnapshotId.length();
while (endIndex > 0 && truncatedSnapshotId.charAt(endIndex - 1) == '-') {
endIndex--;
}
truncatedSnapshotId = truncatedSnapshotId.substring(0, endIndex);
or use Apache StringUtils like this
import org.apache.commons.lang3.StringUtils;
truncatedSnapshotId = StringUtils.stripEnd(truncatedSnapshotId, "-");
There was a problem hiding this comment.
Creating an export only happens once per database. I think this is fine.
There was a problem hiding this comment.
Yes, this runs only once when pipeline starts.
| return truncateString(snapshotId, EXPORT_TASK_ID_MAX_LENGTH - 16) + "-export-" + UUID.randomUUID().toString().substring(0, 8); | ||
| String truncatedSnapshotId = truncateString(snapshotId, EXPORT_TASK_ID_MAX_LENGTH - 16); | ||
| // Remove trailing hyphens to prevent consecutive hyphens in the export task identifier | ||
| truncatedSnapshotId = truncatedSnapshotId.replaceAll("-+$", ""); |
There was a problem hiding this comment.
Creating an export only happens once per database. I think this is fine.
| String truncatedSnapshotId = truncateString(snapshotId, EXPORT_TASK_ID_MAX_LENGTH - 16); | ||
| // Remove trailing hyphens to prevent consecutive hyphens in the export task identifier | ||
| truncatedSnapshotId = truncatedSnapshotId.replaceAll("-+$", ""); | ||
| return truncatedSnapshotId + "-export-" + UUID.randomUUID().toString().substring(0, 8); |
There was a problem hiding this comment.
Are there any other export restrictions which we might hit?
There was a problem hiding this comment.
These are the naming restrictions:
- Identifiers must begin with a letter;
- must contain only ASCII letters, digits, and hyphens;
- and must not end with a hyphen or contain two consecutive hyphens.
- cannot be longer than 60 characters
The snapshot Id, which is used as first part of the export id here, conforms to similar rules, so after truncating and preventing consecutive hyphens, we should be good.
Description
Fixed the RDS export task ID generation to prevent consecutive hyphens in export task identifiers that cause RDS validation failures.
Issues Resolved
Resolves #6186
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.