Skip to content

[Hadoop] Keep the GCS conflict check, hierarchical namespace and implicit dir repair off for vended tokens - #2281

Merged
yili-db merged 9 commits into
unitycatalog:mainfrom
timothyw553:stack/gcs-hadoop-conflict-check
Nov 19, 2026
Merged

yili-db merged 9 commits into
unitycatalog:mainfrom
timothyw553:stack/gcs-hadoop-conflict-check

Conversation

@timothyw553

@timothyw553 timothyw553 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

Fixes #2278: reading or writing a table on gs:// through Unity Catalog failed on Spark 4.2 and 4.3 with 403 errors from Google.

Why it failed. The token Unity Catalog vends only covers the table's own folder. Google's GCS connector has three settings that make it touch things outside that folder:

  • fs.gs.create.items.conflict.check.enable reads every folder above a new file or folder, so creating a table or writing to it fails. Unity Catalog already tried to turn it off, but Hadoop 3.5 started shipping it as "on" in its own defaults, and our code took that default for the user's choice.
  • fs.gs.hierarchical.namespace.folders.enable reads the bucket's layout when a folder is deleted or renamed. The connector turns it on itself, on every Spark version. Parquet tables fail because their commit deletes folders; Delta tables do not.
  • fs.gs.implicit.dir.repair.enable looks up the parent folder after a folder is deleted, for example by INSERT OVERWRITE on a parquet table. The connector turns it on itself, on every Spark version.

The fix

  • All three are now off on every Spark version, unless the user turns one on themselves (for example with broader credentials, or on a hierarchical-namespace bucket).
  • The Spark docs now use Google's connector 4.0.10 on every Spark version. Hadoop 3.5's own GCS module can't take a vended token, and the old 3.0.2 jar doesn't work on Spark 4.2. With 4.0.10, Spark 4.1 also no longer needs the workaround in #2277.
  • The docs also show the settings for releases before 0.8.0, which don't have this fix. The Spark 4.0.x and 4.1.x commands set the hierarchical namespace and implicit directory repair settings; the 4.2.x command also sets the conflict check, because only Hadoop 3.5 turns it on.
  • With the hierarchical namespace setting off, folder delete and rename on hierarchical-namespace buckets lose the connector's native folder path until users set it back to true.
  • engineSets moved from the S3 builder into CredPropsBuilder (moved with a generalized comment; S3 behavior is unchanged). The GCS-only setOffUnlessEngineSets stays in GcsCredPropsBuilder.
  • The docs also add a short note on Structured Streaming: a checkpoint location gets no Unity Catalog credentials, so the session needs its own access limited to that location.

Testing

  • New unit tests; the existing ones still pass. The unit tests in this repo still use connector 3.0.2 on purpose; the real-GCS runs below use 4.0.10.
  • On a real GCS bucket, with Spark 4.0, 4.1, 4.2 and 4.3 and connector 4.0.10, using a Unity Catalog server that vends GCS credentials (#2260, #2273): Delta and parquet tables, managed tables, and path reads and writes in Spark SQL all work. A Spark session also kept working past the one-hour token expiry.
  • On Spark 4.0 and 4.1, turning any of them on by hand makes tests fail: the bucket-layout one breaks non-Delta table writes, the folder one breaks everything, the folder-repair one breaks INSERT OVERWRITE on parquet tables.

Not covered. Reading a bare gs:// path with the DataFrame API (spark.read.parquet("gs://...")) doesn't use Unity Catalog credentials on any version. This PR doesn't change that.

@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

Reading or writing a table on gs:// through Unity Catalog failed on Spark 4.2
and 4.3 with 403 errors from Google. The vended token only covers the table's
folder, and two checks of Google's connector look beyond it:

- fs.gs.create.items.conflict.check.enable reads the folders above a table.
  GcsCredPropsBuilder meant to turn it off unless the user sets it, with
  conf.get(key, "false"). Hadoop 3.5 now ships this key as true in its built-in
  core-default.xml, so conf.get found that and left the check on.
- fs.gs.hierarchical.namespace.folders.enable (on by default in newer
  connectors) reads the bucket's layout when writing files.

Both are now false unless the user set them, telling a user value from Hadoop's
built-in default by the source of the value.

The Spark docs now use Google's connector jar (4.0.10) on every Spark version,
since Hadoop 3.5's own hadoop-gcp module cannot take a vended token; with this
connector, Spark 4.1 also no longer needs the vectored-read workaround.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553
timothyw553 force-pushed the stack/gcs-hadoop-conflict-check branch from 7c40922 to 26107cc Compare November 18, 2026 00:46
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

…a GCS prop tests

Add the two fs.gs.* settings to the Spark 4.2.x GCS command, explain how to turn the checks back on, reword the engineSets javadoc, and cover core-site.xml values and the HNS key in GcsCredPropsTest.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

…n the docs

Real-GCS runs on Spark 4.0 and 4.1 with connector 4.0.10 show both settings break access when on: the bucket-layout lookup (on by default in the connector) breaks non-Delta writes, the folder check breaks everything. Add the bucket-layout setting to the 4.0.x and 4.1.x commands and describe both defaults in the note.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

1 similar comment
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Posting as a comment. Fixed since the last head: the 4.2.x example now sets both fs.gs settings, and the note names the connector's own HNS default and the Spark rows it applies to.

Still open at ba3f5fb:

  • The constructor comment in GcsCredPropsBuilder says the HNS lookup runs on writes (inline).
  • The docs note claims about writes and access need a named operation, or removal (inline).
  • Test fixture and core-site.xml coverage in GcsCredPropsTest (inline).
  • Two nits on the shared base class (inline).
  • Description: please say that folder delete and rename on HNS buckets lose the connector's native folder path until users opt back in, and mention the engineSets move into CredPropsBuilder (a pure move for S3).

// more than the table's own path, which a UC-vended downscoped token (scoped to a table's path
// prefix) is not allowed to do, so the call returns 403:
// - the conflict check stats every ancestor directory on file creation;
// - the hierarchical namespace lookup reads the bucket's layout when writing files.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] The bullet says the hierarchical namespace lookup reads the bucket's layout when writing files. At gcsio v4.0.10 with the default settings, the lookup runs only from folder delete (gcsio/src/main/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageFileSystemImpl.java line 351) and directory rename (line 795). isHnsOptimized (line 1317) returns early unless fs.gs.hierarchical.namespace.folders.optimization.enable is true, which defaults to false, so mkdirs and create do not reach the lookup. Suggested wording: 'the hierarchical namespace lookup reads the bucket's layout when deleting or renaming a folder.'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and I checked it. With only the HNS setting forced on, a parquet write on Spark 4.1 fails with a 403 at GoogleCloudStorageFileSystemImpl.delete (line 351), reached from FileOutputCommitter.abortTask in the parquet commit. Delta writes pass. Reworded the comment to say the lookup runs when a folder is deleted or renamed. I only saw delete in my runs, not rename.

Unity Catalog vends cannot do, so access fails:

- `fs.gs.hierarchical.namespace.folders.enable` reads the bucket's layout. The connector turns it on itself, on every
Spark version, and it breaks writes to non-Delta tables.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] This note says the HNS setting 'breaks writes to non-Delta tables' and the conflict check 'breaks all access'. The connector source does not show either one. At v4.0.10 the HNS flag gates the bucket-layout lookup only in folder delete (GoogleCloudStorageFileSystemImpl.java line 351) and directory rename (line 795). Please name the operation that fails for each setting, or drop the claim.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Reworded. HNS: reads the bucket layout on folder delete or rename, so parquet tables fail (their commit deletes folders) and Delta tables don't. Conflict check: with it forced on, creating _delta_log fails on Error getting 'gs://.../data' object, because it stats the folders above the table, so creating a table or writing to it fails. I haven't tested reads alone, so I dropped "all access".

+ HNS_FOLDERS_KEY
+ "</name><value>true</value></property>"
+ "</configuration>";
conf.addResource(new ByteArrayInputStream(defaults.getBytes(UTF_8)), "core-default.xml");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] This fixture puts fs.gs.hierarchical.namespace.folders.enable at true in core-default.xml, and the assertion below it checks that value. Hadoop 3.5.0's core-default.xml has no HNS key. The true default comes from the connector (gcs/CONFIGURATION.md at v4.0.10). Consider removing that entry from the fixture, or saying in a comment where the true comes from.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Hadoop 3.5.0's core-default.xml has the conflict key but no HNS key; the true comes from the connector. The fixture now only has the conflict key, asserts the HNS key is absent from the Hadoop conf, and checks both keys come out false. The test javadoc says where the HNS true comes from.

conf.addResource(new ByteArrayInputStream(defaults.getBytes(UTF_8)), "core-default.xml");
conf.addResource(new ByteArrayInputStream(site.getBytes(UTF_8)), "core-site.xml");

assertThat(tableProps(conf)).containsEntry(CONFLICT_CHECK_KEY, "true");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] This case uses the same true in both resources and asserts only the conflict key, so the HNS key is not covered on the core-site.xml path. Suggested: set core-site.xml to false for one of the two keys, and assert both keys.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: the case now sets both keys to true in core-site.xml on top of the default and asserts both. I didn't use false for one key, because that is also the forced value, so it couldn't tell "respected" from "overridden".

* core-default.xml}, including {@code true} for the conflict check, so reading the key with a
* fallback of {@code false} would find that default and keep the check on.
*/
protected void setOffUnlessEngineSets(String key) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] setOffUnlessEngineSets is GCS-specific policy in the shared base class, and GcsCredPropsBuilder is its only caller. Consider making it private in GcsCredPropsBuilder, and keeping engineSets here since S3 also uses it. If it stays here, the javadoc could describe only the contract: sets key to false unless the engine's configuration sets it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a private method in GcsCredPropsBuilder with a one-line javadoc. engineSets stays in the base class for S3.

return false;
}
String[] sources = hadoopConf().getPropertySources(key);
return sources == null || !Arrays.stream(sources).allMatch("core-default.xml"::equals);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] This branch treats a key with no recorded source as engine-set, so a value Hadoop does not attribute is kept rather than replaced. getPropertySources returns null when Hadoop records no source for the key. A one-line comment saying so would make the choice visible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment: Hadoop records no source for a key it did not load from a resource, so that counts as set.

Real-GCS runs show INSERT OVERWRITE on a parquet table fails on Spark 4.0 to 4.3: deleting the partition folder makes Google's connector recreate the parent folder, which a table-scoped token cannot touch. Turn fs.gs.implicit.dir.repair.enable off the same way as the other two GCS checks, and add it to the docs commands and note.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

…S policy in GcsCredPropsBuilder, add streaming checkpoint note

Say which connector operation each setting breaks (folder delete or rename for the hierarchical namespace lookup, parent folder stats on create for the conflict check), move setOffUnlessEngineSets into GcsCredPropsBuilder, and cover core-site.xml values for both keys. Add a docs note that a streaming checkpoint location gets no Unity Catalog credentials.

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

@timothyw553

Copy link
Copy Markdown
Collaborator Author

Thanks, all inline points are addressed in the latest commit. Description updated: folder delete and rename on hierarchical-namespace buckets lose the connector's native folder path until users opt back in, and engineSets moved into CredPropsBuilder as a pure move for S3. The latest commit also adds a short docs note on Structured Streaming: a checkpoint location gets no Unity Catalog credentials, so the session needs its own access limited to that location.

…omment, note the HNS tradeoff

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

…ts rule once

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

1 similar comment
@timothyw553

Copy link
Copy Markdown
Collaborator Author

/review

…pplies to renewing credentials

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553

Copy link
Copy Markdown
Collaborator Author

Addressed the review nits that change behavior or test coverage: the repair key is asserted in the tests, each key is tested independently, the engineSets comment is fixed, the HNS tradeoff is in the docs note, and the streaming docs line is narrowed to the default renewing credentials. I checked on real Spark 4.2 that the conflict-check default comes from core-default.xml, and that overwriting a parquet table to empty then reading it works with the repair setting off.

I'm leaving the remaining nits as they are (the engineSets Javadoc wording, the PR title, the --packages version note, and the sources == null test), since they are wording-only or low risk. Happy to change any of them if you'd like.

@yili-db

yili-db commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Posting as a comment at e3ad8b6. Earlier items are addressed: the constructor wording for HNS and the conflict check, the operations named in the docs note, the fixture, the core-site case, the helper placement, the null-source comment, and the description. The streaming auth-type sentence holds for the default renewing credentials.

Still open: the implicit-repair example (inline, in the constructor comment and the docs note).

Optional, inline: the pre-0.8.0 note on the Hadoop 3.5 default, and the engineSets Javadoc.

Optional, title: the title says 'on Hadoop 3.5', but only the conflict check is Hadoop 3.5 specific. The other two keys are off on every Spark version. A title such as '[Hadoop] Keep the GCS conflict check, hierarchical namespace and implicit dir repair off for vended tokens' would match the change.

Comment on lines +31 to +32
// - the implicit directory repair recreates the parent folder after a directory delete, such
// as the partition delete of INSERT OVERWRITE on a parquet table; the connector turns it on

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] The implicit directory repair bullet names the wrong failing call. In folder delete, the parent lookup starts before the delete (gcsio/src/main/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageFileSystemImpl.java lines 342-344). The repair awaits that lookup with getFromFuture (line 932), so an IOException there ends the delete. The placeholder write (createEmptyObject, line 946) catches IOException and only logs a warning (line 950), so the write alone cannot fail the delete. Please name the parent lookup in folder delete as the failing call, or show and cite the INSERT OVERWRITE path that fails, or drop the INSERT OVERWRITE example.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the failing call is the parent lookup in folder delete, not the placeholder write. The INSERT OVERWRITE trace is InsertIntoHadoopFsRelationCommand.deleteMatchingPartitions → GoogleHadoopFileSystem.delete → GoogleCloudStorageFileSystemImpl.delete (397) → repairImplicitDirectory (932) → getFromFuture, failing with "Error accessing gs://.../data/". Reworded to "looks up the parent folder" in the comment, docs and description. I kept the INSERT OVERWRITE example because that is the path that fails, and turning the setting off fixes it.

- `fs.gs.create.items.conflict.check.enable` reads every folder above a new file or folder. Hadoop 3.5 (Spark 4.2.x)
turns it on. Creating a table or writing to it fails.
- `fs.gs.implicit.dir.repair.enable` recreates the parent folder after a folder is deleted. The connector turns it on
itself, and it breaks `INSERT OVERWRITE` on parquet tables.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Same point as the comment on GcsCredPropsBuilder.java: the failing call is the parent lookup in folder delete, not the placeholder write. Please name that call, cite the INSERT OVERWRITE path, or drop the example.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same fix as the constructor comment: the note now says the setting looks up the parent folder after a folder is deleted, and the INSERT OVERWRITE example stays since that path fails in my runs.


From 0.8.0 Unity Catalog turns all three off itself, so the `--conf` lines for them in the commands above can be
dropped. If your credentials are broad enough for those calls (for example on a hierarchical-namespace bucket), set
one to `true` in your Spark config and the connector keeps your value. With the hierarchical namespace setting off,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Optional: Hadoop 3.5's built-in true for the conflict check does not count as an opt-in, because the engine's configuration does not set it. Anyone who relied on that default must now set the key explicitly. Saying so here would help them find it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, thanks.


/**
* Whether the engine's configuration sets {@code key} itself: a value counts as the engine's own
* unless every recorded source is {@code core-default.xml}.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Optional: the Javadoc states the rule but no longer names the Hadoop defaults it is meant to skip. Naming them here, for example S3A's default provider list and Hadoop 3.5's GCS conflict-check default, would explain why core-default.xml is special.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added both examples back.

…air call; document the Hadoop 3.5 default

Co-authored-by: Isaac <[email protected]>
Signed-off-by: Timothy Wang <[email protected]>
@timothyw553 timothyw553 changed the title [Hadoop] Keep the GCS parent-folder and bucket checks off on Hadoop 3.5 [Hadoop] Keep the GCS conflict check, hierarchical namespace and implicit dir repair off for vended tokens Nov 19, 2026
@yili-db

yili-db commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Approving at af36b5e. The earlier items are addressed: the implicit-repair wording (the parent lookup in folder delete, which matches the connector source), the Hadoop 3.5 conflict-check opt-in sentence, the engineSets Javadoc, and the title.

Follow-up, not blocking: the PR description says the conflict-check setting 'breaks everything'. The docs now say that creating a table or writing to it fails, and reads were not tested. Please align the description with the docs, or drop 'breaks everything'.

Nits, inline: one long line in the pre-0.8.0 note, and no test for the sources == null branch of engineSets.

From 0.8.0 Unity Catalog turns all three off itself, so the `--conf` lines for them in the commands above can be
dropped. If your credentials are broad enough for those calls (for example on a hierarchical-namespace bucket), set
one to `true` in your Spark config and the connector keeps your value. Hadoop 3.5's own `true` for the conflict check
does not count as setting it, so if you relied on that default, set the key to `true` yourself. With the hierarchical namespace setting off,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Nit: this line is 144 characters, much longer than the lines around it. Splitting the Hadoop 3.5 caveat and the hierarchical namespace caveat into separate lines would match the note's wrapping.

}
// No recorded source means we cannot show the value came from defaults, so respect it.
String[] sources = hadoopConf().getPropertySources(key);
return sources == null || !Arrays.stream(sources).allMatch("core-default.xml"::equals);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Assisted] Nit: no test covers this sources == null branch. A test with a Configuration whose getPropertySources returns null, asserting that the HNS key stays true, would cover it. Optional.

@yili-db
yili-db merged commit ee92978 into unitycatalog:main Nov 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Spark] GCS access fails with 403 on Spark 4.2 and 4.3

2 participants