dimas-b commented on code in PR #5122:
URL: https://github.com/apache/polaris/pull/5122#discussion_r3647374339


##########
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:
   Yes, failing the most recent request that overflows the UUID "window" sounds 
preferable to silintly ignoring unexpired idempotency keys.
   
   The question is which error code should be use?.. I think 503 would be 
appropriate. WDYT?
   
   Cf. #5144



-- 
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]

Reply via email to