{"record":{"id":"3aefdabf812fc4c6","repo":"apache/iceberg","slug":"cannot-commit-base-metadata-location-s-is-not-3aefda","errorCode":null,"errorMessage":"Cannot commit: Base metadata location '%s' is not same as the current view metadata location '%s' for %s.%s","messagePattern":"Cannot commit: Base metadata location '(.+?)' is not same as the current view metadata location '(.+?)' for (.+?)\\.(.+?)","errorType":"exception","errorClass":"CommitFailedException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java","lineNumber":166,"sourceCode":"\n        updateHiveView = true;\n        LOG.debug(\"Committing existing view: {}\", fullName);\n      } else {\n        tbl = newHMSView(metadata);\n        LOG.debug(\"Committing new view: {}\", fullName);\n      }\n\n      tbl.setSd(\n          HiveOperationsBase.storageDescriptor(\n              metadata.schema(),\n              metadata.location(),\n              hiveEngineEnabled)); // set to pick up any schema changes\n\n      String metadataLocation =\n          tbl.getParameters().get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP);\n      String baseMetadataLocation = base != null ? base.metadataFileLocation() : null;\n      if (!Objects.equals(baseMetadataLocation, metadataLocation)) {\n        throw new CommitFailedException(\n            \"Cannot commit: Base metadata location '%s' is not same as the current view metadata location '%s' for %s.%s\",\n            baseMetadataLocation, metadataLocation, database, viewName);\n      }\n\n      // get Iceberg props that have been removed\n      Set<String> removedProps = emptySet();\n      if (base != null) {\n        removedProps =\n            base.properties().keySet().stream()\n                .filter(key -> !metadata.properties().containsKey(key))\n                .collect(Collectors.toSet());\n      }\n      HMSTablePropertyHelper.updateHmsTableForIcebergView(\n          newMetadataLocation,\n          tbl,\n          metadata,\n          removedProps,\n          maxHiveTablePropertySize,","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveViewOperations.java#L148-L184","documentation":"HiveViewOperations.doCommit performs Iceberg's optimistic concurrency check: the base metadata location recorded by the client must equal the METADATA_LOCATION_PROP currently in HMS. If they differ, another writer committed between this client's read and write, so a CommitFailedException is thrown and the caller must refresh and retry.","triggerScenarios":"Committing a view update when a concurrent commit changed the view's metadata location in HMS after this client loaded it (base.metadataFileLocation() != current HMS value).","commonSituations":"Multiple concurrent writers to the same view; long-running jobs holding stale view handles; lost commit races under high write concurrency; retries with outdated base metadata.","solutions":["Refresh the view (loadView again) and re-apply the change, then commit — the standard optimistic retry loop.","Catch CommitFailedException in the caller and implement bounded retries with backoff.","Reduce concurrent writers to the same view or serialize view updates via orchestration.","Keep view handles short-lived so base metadata is not stale at commit time."],"exampleFix":"// before\nview.updateSchema().addColumn(\"c\", Types.IntegerType.get()).commit(); // may fail\n// after\nint attempts = 3;\nwhile (attempts-- > 0) {\n  try {\n    view = views.loadView(identifier);\n    view.updateSchema().addColumn(\"c\", Types.IntegerType.get()).commit();\n    break;\n  } catch (CommitFailedException e) { /* refresh and retry */ }\n}","handlingStrategy":"retry","validationCode":"// Verify base is current before commit\nString current = hmsTable.getParameters().get(BaseMetastoreTableOperations.METADATA_LOCATION_PROP);\nif (base != null && !base.metadataFileLocation().equals(current)) {\n  // refresh and rebuild the update before attempting commit\n}","typeGuard":null,"tryCatchPattern":"int retries = 3;\nwhile (retries-- > 0) {\n  try {\n    view = views.loadView(identifier);\n    /* apply update */ .commit();\n    break;\n  } catch (CommitFailedException e) {\n    if (retries == 0) throw e; // backoff then refresh-retry\n  }\n}","preventionTips":["Always implement a refresh-and-retry loop around view commits.","Keep view handles short-lived; reload before each update.","Limit concurrent writers per view or serialize updates.","Use backoff between retries to reduce repeated conflicts."],"tags":["hive-metastore","optimistic-concurrency","commit-conflict","view"],"backgroundTag":"invalid-state-transition","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}