Area: API Issues
Sub-Area: Logical Models API / Transaction Collision Errors
Applies to: OSS + Cloud
Issue
You link physical datasets and their columns to a logical model with the setLogicalParent, linkPhysicalChild or unlinkPhysicalChild GraphQL mutations, or with the OpenAPI /openapi/v3/logical/<child_urn>/relationship/physicalInstanceOf/<parent_urn> endpoint. A backfill job that sends many of these calls in parallel gets intermittent failures. A failed call often succeeds when you run it again alone.
On DataHub v1.6.0.1 and later (and current DataHub Cloud releases), a write that runs out of retries on a database deadlock or serialization conflict returns:
- OpenAPI and Rest.li: HTTP
503with"code": "DATABASE_TRANSACTION_CONFLICT","retryable": true, and aRetry-Afterheader. - GraphQL: an error with message
Failed to add after 3 retries due to transaction conflictand extensions"code": 503,"type": "SERVICE_UNAVAILABLE". The GraphQL HTTP status stays 200.
On versions before v1.6.0.1, the same failure comes back as a generic server error with the message Failed to add after 3 retries.
In self-hosted GMS logs you see warnings like this before the call fails:
Retryable PersistenceException with backoff: sqlState=40001, vendorCode=1213, message=...
Retryable PersistenceException with backoff (retries exhausted): sqlState=..., vendorCode=..., message=...
SQLState 40001 or 40P01, or MySQL vendor code 1213, means a deadlock or serialization conflict in the database.
You Might Be Asking
- Why do logical model link calls fail when I run them in parallel, but work one at a time?
- What does
DATABASE_TRANSACTION_CONFLICTmean, and should my script retry it? - What does
EBEAN_MAX_TRANSACTION_RETRYdo, and can I raise it? - Is this a bug, or something I can fix in my job or my configuration?
Cause
Each link call writes the logicalParent aspect on the physical dataset and on each linked schema field. GMS locks the existing rows for those aspects in the database while it writes. When many calls write overlapping rows at the same time, the database detects a deadlock or serialization conflict and aborts one of the transactions.
GMS retries the aborted transaction itself, with a backoff between attempts (50 ms at first, up to 1000 ms by default). EBEAN_MAX_TRANSACTION_RETRY sets the number of retries. The default is 3 retries, so 4 attempts in total. If every attempt hits a conflict, GMS returns the error above to your client.
Solution
1. Lower the concurrency of your backfill
Run the link calls one at a time, or with a small number of workers. Don't send calls for the same dataset or the same logical model in parallel. This removes most conflicts on its own.
2. Retry on the conflict error
On v1.6.0.1 and later, the conflict error is retryable. Treat HTTP 503 with code DATABASE_TRANSACTION_CONFLICT (OpenAPI) or a GraphQL error of type SERVICE_UNAVAILABLE as a signal to wait and try again. For OpenAPI, wait at least the number of seconds in the Retry-After header.
This example links one physical dataset to a logical model through the OpenAPI endpoint from the Logical Models guide, and retries on 503:
import time
import requests
def link_with_retry(session, gms_url, child_urn, parent_urn, column_map, max_attempts=5):
url = f"{gms_url}/openapi/v3/logical/{child_urn}/relationship/physicalInstanceOf/{parent_urn}"
for attempt in range(1, max_attempts + 1):
resp = session.post(url, json=column_map)
if resp.status_code != 503:
resp.raise_for_status()
return resp
time.sleep(int(resp.headers.get("Retry-After", "1")) * attempt)
resp.raise_for_status()
session = requests.Session()
session.headers["Authorization"] = "Bearer <your-access-token>"
for child_urn, parent_urn, column_map in mappings:
link_with_retry(session, "<your-gms-url>", child_urn, parent_urn, column_map)
column_map maps each logical column name to its physical column name, for example {"customer_id": "cust_id"}.
3. Raise the server retry limit (self-hosted only)
If you run DataHub yourself, you can give GMS more attempts before it returns the error. Set the environment variable EBEAN_MAX_TRANSACTION_RETRY (for example to 7) on:
- GMS, always.
- The standalone MCE consumer, if you run one. It applies writes that arrive through Kafka.
EBEAN_MAX_TRANSACTION_RETRY doesn't apply to the MAE consumer.
With the DataHub Helm chart, add it through extraEnvs:
datahub-gms:
extraEnvs:
- name: EBEAN_MAX_TRANSACTION_RETRY
value: "7"
datahub-mce-consumer:
extraEnvs:
- name: EBEAN_MAX_TRANSACTION_RETRY
value: "7"
With Docker Compose, add EBEAN_MAX_TRANSACTION_RETRY: "7" to the environment of your GMS service and, if you run one, your MCE consumer service. Restart the pods or containers after the change. The backoff settings EBEAN_RETRY_INITIAL_BACKOFF_MS and EBEAN_RETRY_MAX_BACKOFF_MS are in the same table of the environment variables reference.
DataHub Cloud customers can't set these variables. If you still see conflict errors on Cloud after you lower concurrency and add retries, contact DataHub Support.
4. Upgrade if you run PostgreSQL on an older version
On self-hosted PostgreSQL, DataHub v1.6.0.1 and later take row locks for aspect writes in a fixed primary-key order. This prevents a class of lock-order deadlocks between multi-row writes such as logical model linking. Version v1.6.0.1 also adds the opt-in EBEAN_ENTITY_WRITE_ADVISORY_LOCK_ENABLED setting (PostgreSQL only, default false). It serializes concurrent writers to the same entity, and it waits with no timeout until the lock is free. MySQL already locks rows in index order, so these changes don't change MySQL behavior.
5. Check the result
Run the backfill again, or a sample of it. On self-hosted deployments, check the GMS logs for retries exhausted warnings. If you still get DATABASE_TRANSACTION_CONFLICT errors after your retries, lower the concurrency further.
Authorization errors are a different problem
Setting a logical parent requires the Edit Entity privilege on both the physical child and the logical parent. Clearing a link requires Edit Entity on the child only. If your calls fail with an authorization error instead of a transaction conflict, grant those privileges to the calling user or service account. See Logical parent (logicalParent aspect) in the policies guide.