-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(Spanner): integrate SourceConfigParser to centralize shard configuration loading for SourceDbToSpanner pipelines. #3854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pratickchokhani
wants to merge
16
commits into
GoogleCloudPlatform:main
Choose a base branch
from
pratickchokhani:shard-config-bulk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b60077d
feat(Spanner): integrate SourceConfigParser to centralize shard confi…
pratickchokhani 21872c2
test(Spanner): Integration test fix.
pratickchokhani ac7b26d
feat(Spanner): refactor CassandraIOWrapperFactory to accept SourceCon…
pratickchokhani a9be7e4
fix: resolve Astra token parsing issue and add integration test for A…
pratickchokhani b8fc634
Nit fixes.
pratickchokhani 41af345
Cassandra to use SourceConnectionConfig
pratickchokhani 0357168
Extend unit test coverage
pratickchokhani 6effde9
Astra DB Integration test update
pratickchokhani 7a7fddd
feat: updated the documentation to reflect the config changes.
pratickchokhani 00def7a
refactor: propagate SourceConnectionConfig through connector interfac…
pratickchokhani a6f89e6
refactor: simplify Shard configuration handling by passing the Shard …
pratickchokhani 2e4fb33
fix(Spanner): removed stale validations.
pratickchokhani a053d4a
PR fixes
pratickchokhani 2cb0f53
Readme fix.
pratickchokhani 77121fc
minor refactoring.
pratickchokhani 2d3b2a3
refactor: unify shard configuration format and update E2E tests to us…
pratickchokhani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,55 +236,34 @@ protected void createAndUploadReverseMultiShardConfigToGcs( | |
| gcsResourceManager.createArtifact("input/shard.json", shardFileContents); | ||
| } | ||
|
|
||
| protected void createAndUploadBulkShardConfigToGcs( | ||
| ArrayList<DataShard> dataShardsList, GcsResourceManager gcsResourceManager) { | ||
| JSONObject bulkConfig = new JSONObject(); | ||
| bulkConfig.put("configType", "dataflow"); | ||
|
|
||
| JSONObject shardConfigBulk = new JSONObject(); | ||
|
|
||
| JSONObject schemaSourceJson = new JSONObject(); | ||
| schemaSourceJson.put("dataShardId", ""); | ||
| schemaSourceJson.put("host", ""); | ||
| schemaSourceJson.put("user", ""); | ||
| schemaSourceJson.put("password", ""); | ||
| schemaSourceJson.put("port", ""); | ||
| schemaSourceJson.put("dbName", ""); | ||
| shardConfigBulk.put("schemaSource", schemaSourceJson); | ||
|
|
||
| JSONArray dataShardsArray = new JSONArray(); | ||
| protected void createAndUploadShardConfigToGcs( | ||
| List<DataShard> dataShardsList, GcsResourceManager gcsResourceManager) { | ||
| JSONObject config = new JSONObject(); | ||
| JSONArray shardConfigs = new JSONArray(); | ||
|
|
||
| if (dataShardsList != null) { | ||
| for (DataShard shardData : dataShardsList) { | ||
| JSONObject shardJson = new JSONObject(); | ||
|
|
||
| shardJson.put("dataShardId", shardData.dataShardId); | ||
| shardJson.put("logicalShardId", shardData.dataShardId); | ||
| shardJson.put("host", shardData.host); | ||
| shardJson.put("user", shardData.user); | ||
| shardJson.put("password", shardData.password); | ||
| shardJson.put("port", shardData.port); | ||
| shardJson.put("dbName", shardData.dbName); | ||
| shardJson.put("namespace", shardData.namespace); | ||
| shardJson.put("connectionProperties", shardData.connectionProperties); | ||
|
|
||
| JSONArray databasesArray = new JSONArray(); | ||
|
|
||
| for (Database dbData : shardData.databases) { | ||
| JSONObject dbJson = new JSONObject(); | ||
| dbJson.put("dbName", dbData.dbName); | ||
| dbJson.put("databaseId", dbData.databaseId); | ||
| dbJson.put("refDataShardId", dbData.refDataShardId); | ||
| databasesArray.put(dbJson); | ||
| if (shardData.namespace != null) { | ||
| shardJson.put("namespace", shardData.namespace); | ||
| } | ||
| if (shardData.connectionProperties != null) { | ||
| shardJson.put("connectionProperties", shardData.connectionProperties); | ||
| } | ||
| shardJson.put("databases", databasesArray); | ||
| dataShardsArray.put(shardJson); | ||
| shardConfigs.put(shardJson); | ||
| } | ||
| } | ||
| shardConfigBulk.put("dataShards", dataShardsArray); | ||
|
|
||
| bulkConfig.put("shardConfigurationBulk", shardConfigBulk); | ||
| String shardFileContents = bulkConfig.toString(); | ||
| config.put("shardConfigs", shardConfigs); | ||
| String shardFileContents = config.toString(); | ||
| LOG.info("Shard file contents: {}", shardFileContents); | ||
| gcsResourceManager.createArtifact("input/shard-bulk.json", shardFileContents); | ||
| gcsResourceManager.createArtifact("input/shard-config.json", shardFileContents); | ||
| } | ||
|
|
||
| protected void createAndUploadShardContextFileToGcs( | ||
|
|
@@ -316,40 +295,44 @@ protected PipelineLauncher.LaunchInfo launchBulkDataflowJob( | |
| Boolean multiSharded) | ||
| throws IOException { | ||
| // launch dataflow template | ||
| if (multiSharded) { | ||
| flexTemplateDataflowJobResourceManager = | ||
| FlexTemplateDataflowJobResourceManager.builder(jobName) | ||
| .withTemplateName("Sourcedb_to_Spanner_Flex") | ||
| .withTemplateModulePath("v2/sourcedb-to-spanner") | ||
| .addParameter("instanceId", spannerResourceManager.getInstanceId()) | ||
| .addParameter("databaseId", spannerResourceManager.getDatabaseId()) | ||
| .addParameter("projectId", PROJECT) | ||
| .addParameter("outputDirectory", "gs://" + artifactBucketName) | ||
| .addParameter("sessionFilePath", getGcsPath("input/session.json", gcsResourceManager)) | ||
| .addParameter( | ||
| "sourceConfigURL", getGcsPath("input/shard-bulk.json", gcsResourceManager)) | ||
| .addEnvironmentVariable( | ||
| "additionalExperiments", Collections.singletonList("disable_runner_v2")) | ||
| .build(); | ||
| } else { | ||
| flexTemplateDataflowJobResourceManager = | ||
| FlexTemplateDataflowJobResourceManager.builder(jobName) | ||
| .withTemplateName("Sourcedb_to_Spanner_Flex") | ||
| .withTemplateModulePath("v2/sourcedb-to-spanner") | ||
| .addParameter("instanceId", spannerResourceManager.getInstanceId()) | ||
| .addParameter("databaseId", spannerResourceManager.getDatabaseId()) | ||
| .addParameter("projectId", PROJECT) | ||
| .addParameter("outputDirectory", "gs://" + artifactBucketName) | ||
| .addParameter("sessionFilePath", getGcsPath("input/session.json", gcsResourceManager)) | ||
| .addParameter("sourceConfigURL", cloudSqlResourceManager.getUri()) | ||
| .addParameter("username", cloudSqlResourceManager.getUsername()) | ||
| .addParameter("password", cloudSqlResourceManager.getPassword()) | ||
| .addParameter("jdbcDriverClassName", "com.mysql.jdbc.Driver") | ||
| .addEnvironmentVariable( | ||
| "additionalExperiments", Collections.singletonList("disable_runner_v2")) | ||
| .build(); | ||
| if (!multiSharded) { | ||
| DataShard dataShard = | ||
| new DataShard( | ||
| "shard1", | ||
| cloudSqlResourceManager.getHost(), | ||
| cloudSqlResourceManager.getUsername(), | ||
| cloudSqlResourceManager.getPassword(), | ||
| String.valueOf(cloudSqlResourceManager.getPort()), | ||
| cloudSqlResourceManager.getDatabaseName(), | ||
| null, | ||
| "useSSL=false&allowPublicKeyRetrieval=true", | ||
| new ArrayList<>()); | ||
|
|
||
| ArrayList<DataShard> shards = new ArrayList<>(); | ||
| shards.add(dataShard); | ||
| createAndUploadShardConfigToGcs(shards, gcsResourceManager); | ||
| } | ||
|
|
||
| FlexTemplateDataflowJobResourceManager.Builder builder = | ||
| FlexTemplateDataflowJobResourceManager.builder(jobName) | ||
| .withTemplateName("Sourcedb_to_Spanner_Flex") | ||
| .withTemplateModulePath("v2/sourcedb-to-spanner") | ||
| .addParameter("instanceId", spannerResourceManager.getInstanceId()) | ||
| .addParameter("databaseId", spannerResourceManager.getDatabaseId()) | ||
| .addParameter("projectId", PROJECT) | ||
| .addParameter("outputDirectory", "gs://" + artifactBucketName) | ||
| .addParameter("sessionFilePath", getGcsPath("input/session.json", gcsResourceManager)) | ||
| .addParameter( | ||
| "sourceConfigURL", getGcsPath("input/shard-config.json", gcsResourceManager)) | ||
| .addEnvironmentVariable( | ||
| "additionalExperiments", Collections.singletonList("disable_runner_v2")); | ||
|
|
||
| if (!multiSharded) { | ||
| builder.addParameter("jdbcDriverClassName", "com.mysql.jdbc.Driver"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the updated flow, the sharded and non-sharded flows are basically the same. Why do we need this special handling ? |
||
| } | ||
|
|
||
| flexTemplateDataflowJobResourceManager = builder.build(); | ||
|
|
||
| // Run | ||
| PipelineLauncher.LaunchInfo jobInfo = flexTemplateDataflowJobResourceManager.launchJob(); | ||
| assertThatPipeline(jobInfo).isRunning(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.