pabloem commented on a change in pull request #16581: URL: https://github.com/apache/beam/pull/16581#discussion_r796077888
########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dofn/InitializeDoFn.java ########## @@ -0,0 +1,98 @@ +/* + * 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.dofn; + +import java.io.Serializable; +import java.util.Optional; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.DaoFactory; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.PartitionMetadataDao; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.mapper.MapperFactory; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.InitialPartition; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.PartitionMetadata; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.PartitionMetadata.State; +import org.apache.beam.sdk.transforms.DoFn; + +/** + * A SplittableDoFn (SDF) that is responsible for initializing the change stream Connector. It + * handles the creation of the partition metadata table and the insertion of a fake partition (see + * {@link InitialPartition#PARTITION_TOKEN}), which will be used to dispatch the change streams + * query. + */ +public class InitializeDoFn extends DoFn<byte[], PartitionMetadata> implements Serializable { + + private static final long serialVersionUID = -8921188388649003102L; + + /** Heartbeat interval for all change stream queries will be of 2 seconds. */ + // Be careful when changing this interval, as it needs to be less than the checkpointing interval + // in Dataflow. Otherwise, if there are no records within checkpoint intervals, the consuming of + // a change stream query might get stuck. + private static final long DEFAULT_HEARTBEAT_MILLIS = 2000; + + private final DaoFactory daoFactory; + private final MapperFactory mapperFactory; + // The change streams query start time + private final com.google.cloud.Timestamp startTimestamp; + // The change streams query end time + private final com.google.cloud.Timestamp endTimestamp; + + public InitializeDoFn( Review comment: We discussed this at some point - but it may be possible to restart a pipeline where we don't want to re-create a metadata table. Do you htink that could be considered later on at osme point? ########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/dofn/InitializeDoFn.java ########## @@ -0,0 +1,98 @@ +/* + * 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.dofn; + +import java.io.Serializable; +import java.util.Optional; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.DaoFactory; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.dao.PartitionMetadataDao; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.mapper.MapperFactory; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.InitialPartition; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.PartitionMetadata; +import org.apache.beam.sdk.io.gcp.spanner.changestreams.model.PartitionMetadata.State; +import org.apache.beam.sdk.transforms.DoFn; + +/** + * A SplittableDoFn (SDF) that is responsible for initializing the change stream Connector. It Review comment: this DoFn is not splittable, though this is clear from the code. Can you update this docstring? (it's okay to do on a followup pr) -- 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]
