nuggetwheat commented on code in PR #25193:
URL: https://github.com/apache/beam/pull/25193#discussion_r1102222256


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/MetadataSpannerConfig.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.gcp.spanner.changestreams;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.api.gax.retrying.RetrySettings;
+import com.google.api.gax.rpc.StatusCode.Code;
+import com.google.cloud.spanner.Options.RpcPriority;
+import org.apache.beam.sdk.io.gcp.spanner.SpannerConfig;
+import org.apache.beam.sdk.options.ValueProvider;
+import org.apache.beam.sdk.options.ValueProvider.StaticValueProvider;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSet;
+import org.joda.time.Duration;
+
+/**
+ * This class generates a SpannerConfig for the change stream metadata 
database by copying only the
+ * necessary fields from the SpannerConfig of the primary database.
+ */
+public class MetadataSpannerConfig {
+
+  /**
+   * Generates an SpannerConfig that can be used to access the change stream 
metadata database by
+   * copying only the necessary fields from the given primary database 
SpannerConfig and setting the
+   * instance ID and database ID to the supplied metadata values.
+   *
+   * @param primaryConfig The SpannerConfig for accessing the primary database
+   * @param metadataInstanceId The instance ID of the metadata database
+   * @param metadataDatabaseId The database ID of the metadata database
+   * @return the metadata SpannerConfig
+   */
+  public static SpannerConfig create(
+      SpannerConfig primaryConfig, String metadataInstanceId, String 
metadataDatabaseId) {
+
+    checkNotNull(
+        metadataInstanceId, "MetadataSpannerConfig.create requires non-null 
metadata instance id");
+    checkNotNull(
+        metadataDatabaseId, "MetadataSpannerConfig.create requires non-null 
metadata database id");
+
+    // NOTE: databaseRole should NOT be copied to the metadata config
+
+    SpannerConfig config =

Review Comment:
   If a field gets added to SpannerConfig in the future, it's unknown if it 
should be copied to the Metadata config or not, so coming up with a unit test 
now to verify the correct output of this factory with a future added field to 
SpannerConfig isn't possible.
   
   https://github.com/apache/beam/pull/25246 introduces an integration test 
that uses a metadata database that is distinct from the primary database. If a 
new field gets added to SpannerConfig that only makes sense for the primary 
database, then this factory will not copy it into the Metadata config and the 
code will work properly with no change. If the new field should get copied to 
the Metadata config, then the integration test will fail and will require a 
change to this factory class. Likewise, if someone introduces code that copies 
the SpannerConfig and only strips databaseRole and does not handle the new 
field properly, the integration test will catch it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to