You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2022/11/16 22:50:44 UTC

[GitHub] [samza] xinyuiscool commented on a diff in pull request #1642: SAMZA-2769: [PipelineDrain] Add drainMode to DrainNotification

xinyuiscool commented on code in PR #1642:
URL: https://github.com/apache/samza/pull/1642#discussion_r1024576429


##########
samza-api/src/main/java/org/apache/samza/drain/DrainMode.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.samza.drain;
+
+/**
+ * Defines the type of drain operation.
+ * */
+public enum DrainMode {
+  /**
+   * Simple drain mode is the default behavior of the drain operation.
+   * All intermediate streams and any samza managed state will be drained and the pipeline will be gracefully shutdown
+   * as a result. User state will not be drained.
+   * */
+  SIMPLE;

Review Comment:
   As your javadoc suggests, let's call it default?



##########
samza-api/src/main/java/org/apache/samza/drain/DrainNotification.java:
##########
@@ -35,9 +35,23 @@ public class DrainNotification {
    */
   private final String runId;
 
-  public DrainNotification(UUID uuid, String runId) {
+  /***/
+  private final DrainMode drainMode;
+
+  public DrainNotification(UUID uuid, String runId, DrainMode drainMode) {
+    Preconditions.checkNotNull(uuid);
+    Preconditions.checkNotNull(runId);
+    Preconditions.checkNotNull(drainMode);
     this.uuid = uuid;
     this.runId = runId;
+    this.drainMode = drainMode;
+  }
+
+  /**
+   * Creates a DrainNotification in {@link DrainMode#SIMPLE} mode.
+   * */
+  public static DrainNotification simple(UUID uuid, String runId) {

Review Comment:
   let's just call it create(). We can have another variant factory method for create with other mode.



##########
samza-core/src/main/java/org/apache/samza/drain/DrainUtils.java:
##########
@@ -54,44 +74,34 @@ private DrainUtils() {
    * @return generated uuid for the DrainNotification
    */
   @VisibleForTesting
-  public static UUID writeDrainNotification(MetadataStore metadataStore, String runId) {
+  public static UUID writeSimpleDrainNotification(MetadataStore metadataStore, String runId) {

Review Comment:
   If this is only used for testing, we should be able to test the variant of using DrainNotification. If not user-facing, let's get rid of it.



##########
samza-core/src/main/java/org/apache/samza/drain/DrainUtils.java:
##########
@@ -54,44 +74,34 @@ private DrainUtils() {
    * @return generated uuid for the DrainNotification
    */
   @VisibleForTesting
-  public static UUID writeDrainNotification(MetadataStore metadataStore, String runId) {
+  public static UUID writeSimpleDrainNotification(MetadataStore metadataStore, String runId) {
     Preconditions.checkArgument(metadataStore != null, "MetadataStore cannot be null.");
     Preconditions.checkArgument(!Strings.isNullOrEmpty(runId), "runId should be non-null.");
     LOG.info("Attempting to write DrainNotification to metadata-store for the deployment ID {}", runId);
+    final UUID uuid = UUID.randomUUID();
+    final DrainNotification message = DrainNotification.simple(uuid, runId);
+    return writeDrainNotification(metadataStore, message);
+  }
+
+  /**
+   * Writes a {@link DrainNotification} to an underlying metadata store.
+   * */
+  @VisibleForTesting
+  public static UUID writeDrainNotification(MetadataStore metadataStore, DrainNotification drainNotification) {

Review Comment:
   If it's only used for testing, please make it package private.



##########
samza-core/src/main/java/org/apache/samza/drain/DrainUtils.java:
##########
@@ -45,6 +45,26 @@ public class DrainUtils {
   private DrainUtils() {
   }
 
+  /**
+   * Writes a {@link DrainNotification} to the underlying metastore. This method should be used by external controllers
+   * to issue a DrainNotification to the JobCoordinator and Samza Containers.
+   * @param metadataStore Metadata store to write drain notification to.
+   *
+   * @return generated uuid for the DrainNotification
+   */
+  public static UUID writeSimpleDrainNotification(MetadataStore metadataStore) {

Review Comment:
   Let's just use writeDrainNotification(). We can overload it with other parameters later.



-- 
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: commits-unsubscribe@samza.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org