huaxingao commented on code in PR #5122:
URL: https://github.com/apache/polaris/pull/5122#discussion_r3642012505
##########
runtime/service/src/main/java/org/apache/polaris/service/idempotency/EntityIdempotency.java:
##########
@@ -130,24 +126,24 @@ public static Map<String, String> recordKey(
}
private static List<KeyEntry> decode(String raw) {
- if (raw == null || raw.isEmpty()) {
+ if (raw == null || !raw.startsWith(FORMAT_SMILE_V1)) {
return List.of();
}
- if (!raw.startsWith(WINDOW_FORMAT_SMILE_V1)) {
- throw new IllegalArgumentException("Unrecognized idempotency key window
format");
- }
- byte[] smile =
Base64.getUrlDecoder().decode(raw.substring(WINDOW_FORMAT_SMILE_V1.length()));
+ // An unreadable window (bad base64 or SMILE decode failure) is treated as
no live keys rather
+ // than failing the operation: a corrupt property degrades to normal
behavior and the next
+ // recordKey overwrites it.
try {
+ byte[] smile =
Base64.getUrlDecoder().decode(raw.substring(FORMAT_SMILE_V1.length()));
return SMILE_MAPPER.readValue(smile, new TypeReference<List<KeyEntry>>()
{});
- } catch (IOException e) {
- throw new RuntimeException("Failed to decode idempotency key window", e);
+ } catch (IllegalArgumentException | IOException e) {
+ return List.of();
}
}
private static String encode(Collection<KeyEntry> window) {
try {
byte[] smile = SMILE_MAPPER.writeValueAsBytes(window);
- return WINDOW_FORMAT_SMILE_V1 +
Base64.getUrlEncoder().withoutPadding().encodeToString(smile);
+ return FORMAT_SMILE_V1 +
Base64.getUrlEncoder().withoutPadding().encodeToString(smile);
Review Comment:
Thanks for the catch, I completely agree we need a guardrail here. Would it
work for you if I set a very large cap and, when it's exceeded, fail the write
rather than evict? My only hesitation with eviction is that it could drop a
still-live key, which @flyrain flagged as a possible corruption risk.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]