iremcaginyurtturk opened a new pull request, #1635: URL: https://github.com/apache/iceberg-go/pull/1635
## Problem `CreateNamespace` in the sql catalog resolves the namespace key, returns `ErrNamespaceAlreadyExists` if it is present, and otherwise inserts the properties. Two callers creating the same namespace both pass that check, and the loser's insert violates the primary key on `iceberg_namespace_properties`. The driver's error is returned unwrapped: ``` error inserting namespace properties for namespace '[raw]': constraint failed: UNIQUE constraint failed: iceberg_namespace_properties.catalog_name, iceberg_namespace_properties.namespace, iceberg_namespace_properties.property_key (1555) ``` Callers that write `errors.Is(err, catalog.ErrNamespaceAlreadyExists)` — the contract the other implementations honour, and the natural way to write create-if-absent — see a failure for a namespace that does exist. It surfaces as an intermittent first-run failure in any tool that loads two tables into a new namespace concurrently; that is how I ran into it. ## Fix Re-resolve the namespace key when the insert fails, and return `ErrNamespaceAlreadyExists` if it is present now. An insert that failed for any other reason is returned exactly as before. I kept the pre-check rather than replacing it with an upsert: it keeps the common path a single read, and the behaviour on the raced path is then identical to the non-raced one. ## Testing `TestCreateNamespaceConcurrent` starts eight goroutines that create the same namespace behind a barrier, then asserts exactly one `nil` and seven `ErrNamespaceAlreadyExists`. It reproduces the bug deterministically — on `main` it fails on the first run with the `UNIQUE constraint failed` error above, and passes with the fix. The test's catalog sets a sqlite `busy_timeout` so the writers queue on the file lock rather than failing with `SQLITE_BUSY`, which is separate contention and not what this test is about. `go test ./catalog/...` passes, `gofmt` clean, `golangci-lint run catalog/sql/...` reports 0 issues. I did not open an issue first, per CONTRIBUTING — happy to file one and link it if you would prefer that order. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
