{"record":{"id":"2e029d3b5e8999b3","repo":"apache/pulsar","slug":"failed-to-delete-the-state-value-for-key-s","errorCode":null,"errorMessage":"Failed to delete the state value for key '%s'","messagePattern":"Failed to delete the state value for key '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/state/BKStateStoreImpl.java","lineNumber":156,"sourceCode":"        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to update the state value for key '\" + key + \"'\");\n        }\n    }\n\n    @Override\n    public CompletableFuture<Void> deleteAsync(String key) {\n        return table.delete(\n                Unpooled.wrappedBuffer(key.getBytes(UTF_8)),\n                Options.delete()\n        ).thenApply(ignored -> null);\n    }\n\n    @Override\n    public void delete(String key) {\n        try {\n            result(deleteAsync(key));\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to delete the state value for key '\" + key + \"'\");\n        }\n    }\n\n    @Override\n    public CompletableFuture<ByteBuffer> getAsync(String key) {\n        return table.get(Unpooled.wrappedBuffer(key.getBytes(UTF_8))).thenApply(\n                data -> {\n                    try {\n                        if (data != null) {\n                            ByteBuffer result = ByteBuffer.allocate(data.readableBytes());\n                            data.readBytes(result);\n                            // Set position to off the buffer to the beginning, since the position after the\n                            // read is going to be end of the buffer\n                            // If we do not rewind to the beginning here, users will have to explicitly do\n                            // this in their function code\n                            // in order to use any of the ByteBuffer operations\n                            result.position(0);\n                            return result;","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/state/BKStateStoreImpl.java#L138-L174","documentation":"BKStateStoreImpl.delete blocks on deleteAsync and rethrows failures as a RuntimeException with this message (cause not attached). It means deleting the key's value from the BookKeeper-backed state table failed asynchronously.","triggerScenarios":"Calling delete(key) when the table delete call fails: storage service unreachable, timeout, or table-service internal error while routing the delete to the owning bookie.","commonSituations":"Table service range/routing errors during re-balancing; bookie failures; deleting keys concurrently with table restore/compaction; network partition.","solutions":["Use deleteAsync to capture the real underlying exception.","Check BookKeeper/table service health and retry the delete (deletes are idempotent).","Confirm the state table for the function is open and healthy.","Check for table-service errors around the time of failure in broker/storage logs."],"exampleFix":"// before\nstore.delete(\"stale-key\");\n// after\nstore.deleteAsync(\"stale-key\")\n    .exceptionally(ex -> {\n        log.warn(\"delete failed, key may already be gone\", ex);\n        return null;\n    }).join();","handlingStrategy":"retry","validationCode":"// deletes are idempotent; verify storage reachable first\nstore.getAsync(key).get(5, TimeUnit.SECONDS); // cheap pre-flight","typeGuard":null,"tryCatchPattern":"try {\n    store.delete(key);\n} catch (RuntimeException e) {\n    backoffRetry(() -> store.delete(key), 3); // idempotent, safe to retry\n}","preventionTips":["Retry deletes — they are idempotent and failures are often transient table-service errors.","Avoid deleting keys during table restore/rebalance windows.","Use deleteAsync in event-loop code to respect no-blocking rules."],"tags":["state","bookkeeper","delete","blocking-call"],"backgroundTag":"state-store-operation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}