{"record":{"id":"7529be6269f27a3f","repo":"apache/iceberg","slug":"failed-to-insert-d-of-d-succeeded","errorCode":null,"errorMessage":"Failed to insert: %d of %d succeeded","messagePattern":"Failed to insert: (.+?) of (.+?) succeeded","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":854,"sourceCode":"\n    return ImmutableMap.<String, String>builder().putAll(entries).buildOrThrow();\n  }\n\n  private boolean insertProperties(Namespace namespace, Map<String, String> properties) {\n    String namespaceName = JdbcUtil.namespaceToString(namespace);\n    String[] args =\n        properties.entrySet().stream()\n            .flatMap(\n                entry -> Stream.of(catalogName, namespaceName, entry.getKey(), entry.getValue()))\n            .toArray(String[]::new);\n\n    int insertedRecords = execute(JdbcUtil.insertPropertiesStatement(properties.size()), args);\n\n    if (insertedRecords == properties.size()) {\n      return true;\n    }\n\n    throw new IllegalStateException(\n        String.format(\n            Locale.ROOT,\n            \"Failed to insert: %d of %d succeeded\",\n            insertedRecords,\n            properties.size()));\n  }\n\n  private boolean updateProperties(Namespace namespace, Map<String, String> properties) {\n    String namespaceName = JdbcUtil.namespaceToString(namespace);\n    Stream<String> caseArgs =\n        properties.entrySet().stream()\n            .flatMap(entry -> Stream.of(entry.getKey(), entry.getValue()));\n    Stream<String> whereArgs =\n        Stream.concat(Stream.of(catalogName, namespaceName), properties.keySet().stream());\n\n    String[] args = Stream.concat(caseArgs, whereArgs).toArray(String[]::new);\n\n    int updatedRecords = execute(JdbcUtil.updatePropertiesStatement(properties.size()), args);","sourceCodeStart":836,"sourceCodeEnd":872,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L836-L872","documentation":"insertProperties() issues a multi-row insert of namespace properties via JdbcUtil.insertPropertiesStatement and expects exactly properties.size() inserted rows. If execute() returns fewer, it throws IllegalStateException \"Failed to insert: %d of %d succeeded\" — an internal invariant violation meaning the catalog state is now partially updated.","triggerScenarios":"createNamespace or setProperties where the bulk INSERT matches fewer rows than submitted: usually a constraint violation on some rows (duplicate property keys for the namespace, e.g. concurrent setProperties inserting the same key) that the JDBC driver partially applied instead of failing atomically.","commonSituations":"Concurrent clients inserting the same property key for the same namespace without ON CONFLICT semantics; databases with quirks around batch insert counts; catalog schema modified so unique constraints differ.","solutions":["Retry the operation; if properties were partially inserted, remove duplicates and re-set them","Avoid concurrent writers to the same namespace properties, or use a database whose insert is atomic per statement","Inspect the namespace properties after failure and reconcile (setProperties again with the full map)","Verify the catalog table's primary key/unique constraints match what this Iceberg version expects"],"exampleFix":"// before\ncatalog.setProperties(ns, newProps);\n// after\nMap<String, String> existing = catalog.loadNamespaceMetadata(ns);\nMap<String, String> onlyNew = newProps.entrySet().stream()\n    .filter(e -> !existing.containsKey(e.getKey()))\n    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));\ncatalog.setProperties(ns, onlyNew);","handlingStrategy":"validation","validationCode":"Map<String, String> existing = catalog.namespaceExists(ns)\n    ? catalog.loadNamespaceMetadata(ns)\n    : Map.of();\nSet<String> dupes = new HashSet<>(props.keySet());\ndupes.retainAll(existing.keySet());\nif (!dupes.isEmpty()) throw new IllegalStateException(\"Keys already present: \" + dupes);","typeGuard":null,"tryCatchPattern":"try {\n  catalog.setProperties(ns, props);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Failed to insert\")) {\n    // partial state: reconcile by re-reading and re-setting full property map\n    Map<String, String> current = catalog.loadNamespaceMetadata(ns);\n    current.putAll(props);\n    catalog.setProperties(ns, current);\n  } else throw e;\n}","preventionTips":["Avoid concurrent setProperties on the same namespace","Pre-check for existing keys before bulk insert of properties","Reconcile catalog properties after any partial-insert failure","Verify unique constraints on the properties catalog table"],"tags":["jdbc","properties","invariant","concurrency"],"backgroundTag":"internal-invariant-violation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}