{"record":{"id":"4bcac6dc05d10522","repo":"zhisheng17/flink-learning","slug":"could-not-find-key-in-configmap-configmapname","errorCode":null,"errorMessage":"Could not find {key} in ConfigMap {configMapName}","messagePattern":"Could not find (.+?) in ConfigMap (.+?)","errorType":"exception","errorClass":"NotExistException","httpStatus":null,"severity":"error","filePath":"flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStore.java","lineNumber":240,"sourceCode":"\t * @param key Key in ConfigMap\n\t *\n\t * @return The retrieved state handle from the specified ConfigMap and key\n\t *\n\t * @throws IOException if the method failed to deserialize the stored state handle\n\t * @throws NotExistException when the name does not exist\n\t * @throws Exception if get state handle from ConfigMap failed\n\t */\n\t@Override\n\tpublic RetrievableStateHandle<T> getAndLock(String key) throws Exception {\n\t\tcheckNotNull(key, \"Key in ConfigMap.\");\n\n\t\tfinal Optional<KubernetesConfigMap> optional = kubeClient.getConfigMap(configMapName);\n\t\tif (optional.isPresent()) {\n\t\t\tfinal KubernetesConfigMap configMap = optional.get();\n\t\t\tif (configMap.getData().containsKey(key)) {\n\t\t\t\treturn deserializeObject(configMap.getData().get(key));\n\t\t\t} else {\n\t\t\t\tthrow getKeyNotExistException(key);\n\t\t\t}\n\t\t} else {\n\t\t\tthrow getConfigMapNotExistException();\n\t\t}\n\t}\n\n\t/**\n\t * Gets all available state handles from Kubernetes.\n\t *\n\t * @return All state handles from ConfigMap.\n\t */\n\t@Override\n\tpublic List<Tuple2<RetrievableStateHandle<T>, String>> getAllAndLock() {\n\n\t\treturn kubeClient.getConfigMap(configMapName)\n\t\t\t.map(\n\t\t\t\tconfigMap -> {\n\t\t\t\t\tfinal List<Tuple2<RetrievableStateHandle<T>, String>> stateHandles = new ArrayList<>();","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-k8s/flink-k8s/src/main/java/org/apache/flink/kubernetes/highavailability/KubernetesStateHandleStore.java#L222-L258","documentation":"KubernetesStateHandleStore.getAndLock looks up the given key in the named ConfigMap and throws getKeyNotExistException (a KeyNotFoundException) when the ConfigMap exists but does not contain the requested state-handle key. In Flink's HA setup this means the job's state handle entry is missing from Kubernetes storage. Callers treat it as 'no state stored yet' for that key.","triggerScenarios":"Calling getAndLock(configMapName, key) where kubeClient.getConfigMap(configMapName) returns a present ConfigMap but configMap.getData().containsKey(key) is false — the key was never written, was removed, or the wrong key name is requested.","commonSituations":"HA recovery pointing at a fresh/empty ConfigMap after a namespace was recreated, mismatched job/HA storage path keys between config and what was actually stored, or an external actor pruned keys from the ConfigMap.","solutions":["Verify the key name and HA storage path configuration (high-availability.storageDir / cluster-id) match what was originally written","Check the ConfigMap contents (kubectl get configmap <name> -o yaml) to confirm which keys exist","If state was genuinely lost, restart the job as a fresh start rather than HA recovery","Restore the ConfigMap from backup or recreate the state handles before retrying"],"exampleFix":"// before\nOptional<CompletedCheckpoint> checkpoint = stateHandleStore.getAndLock(configMapName, \"job-state-handle\");\n// after\nOptional<KubernetesConfigMap> cm = kubeClient.getConfigMap(configMapName);\nif (cm.isPresent() && cm.get().getData().containsKey(\"job-state-handle\")) {\n    Optional<CompletedCheckpoint> checkpoint = stateHandleStore.getAndLock(configMapName, \"job-state-handle\");\n} else {\n    // fall back to fresh start or restore from alternative storage\n}","handlingStrategy":"validation","validationCode":"KubernetesConfigMap cm = kubeClient.getConfigMap(configMapName).orElse(null);\nif (cm == null) { /* ConfigMap missing: handle 56 case */ }\nif (cm != null && !cm.getData().containsKey(key)) {\n    LOG.warn(\"Key {} absent from ConfigMap {}\", key, configMapName);\n    return Optional.empty(); // skip lock/recovery\n}","typeGuard":null,"tryCatchPattern":"try {\n    return stateHandleStore.getAndLock(configMapName, key);\n} catch (KeyNotFoundException e) {\n    LOG.warn(\"No stored state for key {} in {}\", key, configMapName);\n    return Optional.empty(); // fall back to fresh start\n}","preventionTips":["Verify HA storage path and cluster-id configuration before recovery","Snapshot/backup HA ConfigMaps before maintenance","Avoid external cleanup of Flink HA ConfigMaps"],"tags":["kubernetes","flink","high-availability","state"],"backgroundTag":"resource-not-found","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}