Skip to content

[Java] Support cross-project metadata databases in SpannerIO.readChangeStream - #41880

Open
sakshammalik260-cse wants to merge 1 commit into
apache:masterfrom
sakshammalik260-cse:feat/41863-spanner-metadata-project
Open

sakshammalik260-cse wants to merge 1 commit into
apache:masterfrom
sakshammalik260-cse:feat/41863-spanner-metadata-project

Conversation

@sakshammalik260-cse

Copy link
Copy Markdown

Summary

Closes #41863.

Adds an optional withMetadataProjectId() configuration method to SpannerIO.ReadChangeStream, allowing change-stream metadata to be stored in a Google Cloud Spanner database in a different project from the source database.

Problem

Currently, the metadata configuration always inherits the source database's project ID. Users managing databases across multiple GCP projects cannot configure a centralized metadata database in a separate project.

Solution

  • Introduces withMetadataProjectId(String) through the existing immutable AutoValue builder.
  • Preserves the existing MetadataSpannerConfigFactory configuration policy.
  • Applies the optional project override before metadata dialect detection and DAO construction.
  • Preserves credential handling, retry settings, and database-role isolation.
  • Defaults to the source project when the metadata project is omitted.
  • Maintains backward compatibility with existing pipelines.

No new production dependencies, additional network requests, or per-record processing are introduced.

Usage

SpannerIO.readChangeStream()
    .withProjectId("source-project")
    .withInstanceId("source-instance")
    .withDatabaseId("source-database")
    .withMetadataProjectId("metadata-project")
    .withMetadataInstance("metadata-instance")
    .withMetadataDatabase("metadata-database");

Testing and Validation

84 targeted local unit tests passed with zero failures or skips.

Regression coverage includes:

  • Default, explicit, and cross-project metadata selection.
  • Source and metadata configuration isolation.
  • Fluent setter ordering and immutability.
  • Metadata dialect detection and DAO routing.
  • Worker-side configuration serialization.
  • Project-specific database and administration client isolation.
  • Credential, retry policy, and database-role preservation.
  • Existing metadata configuration validation.

Controlled mutation testing confirmed that the regression tests detect swapped dialect configurations, missing project overrides, and incorrectly delayed project overrides.

The following quality checks passed:

  • Java compilation and static analysis.
  • Spotless.
  • Checkstyle.
  • Changelog validation.
  • Apache RAT.
  • git diff --check.

Live cross-project Spanner and IAM integration testing was not performed.

Add an optional metadata project override while preserving existing metadata configuration policies and default behavior.

Generated-by: OpenAI Codex
@sakshammalik260-cse

Copy link
Copy Markdown
Author

/gemini review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📋 Review Summary

This PR adds support for configuring a separate GCP project for the change stream partition metadata database via SpannerIO.ReadChangeStream.withMetadataProjectId(String) (closing #41863). The implementation cleanly delegates project override logic to MetadataSpannerConfigFactory.create, preserves backward compatibility when unset or cleared, and includes comprehensive unit tests.

🔍 General Feedback

  • The changes to SpannerIO, MetadataSpannerConfigFactory, and SpannerIOReadChangeStreamTest are well-structured, adhere to existing AutoValue and SpannerConfig conventions, and properly handle dialect resolution and DAO routing across projects.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions github-actions Bot added java io gcp spanner size/m M: 50-249 lines changed labels Dec 2, 2026
@sakshammalik260-cse

Copy link
Copy Markdown
Author

Hi @scwhittle, could you please review this PR when you have a chance?

It addresses #41863 by adding optional cross-project metadata database support while preserving the existing metadata configuration policy and backward compatibility.

All 84 targeted local unit tests and quality checks passed. The initial Gemini review was also positive. The official CI workflows are currently awaiting approval.

I'd appreciate your feedback. Thank you!

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@sakshammalik260-cse

Copy link
Copy Markdown
Author

assign set of reviewers

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @nielm for label spanner.
Backup reviewer: damccorm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

assertEquals("metadata-project", copy.getMetadataProjectId());
SpannerConfig metadata =
assertRouting(
configured, "metadata-project", TEST_METADATA_INSTANCE, TEST_METADATA_DATABASE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

assertRouting(
copy, "metadata-project", TEST_METADATA_INSTANCE, TEST_METADATA_DATABASE); ?

Comment on lines +2201 to +2204
* <p>The metadata instance and database still default to the source instance and database
* names, interpreted in this project. Access requires permissions to read and write metadata
* and update its schema in the metadata database. This does not change the source
* configuration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the user specifies an instance, we require setting the database.
If user specifies the project, to be consistent we should also require instance and database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Allow for a metadata database in a different GCP project in SpannerIO.readChangeStream

2 participants