beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Work logged] (BEAM-4684) Support @RequiresStableInput on Dataflow runner in Java SDK
Date Thu, 13 Sep 2018 18:03:00 GMT

     [ https://issues.apache.org/jira/browse/BEAM-4684?focusedWorklogId=144039&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-144039
]

ASF GitHub Bot logged work on BEAM-4684:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Sep/18 18:02
            Start Date: 13/Sep/18 18:02
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on a change in pull request #6220: [BEAM-4684]
Add integration test for support of @RequiresStableInput
URL: https://github.com/apache/beam/pull/6220#discussion_r217477536
 
 

 ##########
 File path: sdks/java/core/src/main/java/org/apache/beam/sdk/util/FilePatternMatchingShardedFile.java
 ##########
 @@ -0,0 +1,138 @@
+/*
+ * 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.util;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+import com.google.common.io.CharStreams;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.channels.Channels;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.beam.sdk.io.FileSystems;
+import org.apache.beam.sdk.io.fs.MatchResult.Metadata;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.joda.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A sharded file which matches a given file pattern.
+ *
+ * <p>Note that file matching should only occur once the file system is in a stable
state and
+ * guaranteed to provide a consistent result during file pattern matching.
+ */
+public class FilePatternMatchingShardedFile implements ShardedFile {
+
+  private static final Logger LOG = LoggerFactory.getLogger(FilePatternMatchingShardedFile.class);
+
+  private static final int MAX_READ_RETRIES = 4;
+  private static final Duration DEFAULT_SLEEP_DURATION = Duration.standardSeconds(10L);
+  static final FluentBackoff BACK_OFF_FACTORY =
+      FluentBackoff.DEFAULT
+          .withInitialBackoff(DEFAULT_SLEEP_DURATION)
+          .withMaxRetries(MAX_READ_RETRIES);
+
+  private final String filePattern;
+
+  /**
+   * Constructs an {@link FilePatternMatchingShardedFile} for the given file pattern.
+   *
+   * <p>Note that file matching should only occur once the file system is in a stable
state and
+   * guaranteed to provide a consistent result during file pattern matching.
+   */
+  public FilePatternMatchingShardedFile(String filePattern) {
+    checkArgument(
+        !Strings.isNullOrEmpty(filePattern),
+        "Expected valid file path, but received %s",
+        filePattern);
+    this.filePattern = filePattern;
+  }
+
+  @Override
+  public List<String> readFilesWithRetries(Sleeper sleeper, BackOff backOff)
+      throws IOException, InterruptedException {
+    IOException lastException = null;
+
+    do {
+      try {
+        Collection<Metadata> files = FileSystems.match(filePattern).metadata();
+        LOG.debug(
+            "Found file(s) {} by matching the path: {}",
+            files
+                .stream()
+                .map(Metadata::resourceId)
+                .map(ResourceId::getFilename)
+                .collect(Collectors.joining(",")),
+            filePattern);
+        if (files.isEmpty()) {
+          continue;
+        }
+        // Read data from file paths
+        return readLines(files);
+      } catch (IOException e) {
+        // Ignore and retry
+        lastException = e;
+        LOG.warn("Error in file reading. Ignore and retry.");
+      }
+    } while (BackOffUtils.next(sleeper, backOff));
+    // Failed after max retries
+    throw new IOException(
+        String.format("Unable to read file(s) after retrying %d times", MAX_READ_RETRIES),
+        lastException);
+  }
+
+  /** Discovers all shards of this file using the provided {@link Sleeper} and {@link BackOff}.
*/
 
 Review comment:
   This comment doesn't make sense, please fix up in a following PR.
   
   It looks like its a common error in the other implementations.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 144039)
    Time Spent: 3h 10m  (was: 3h)

> Support @RequiresStableInput on Dataflow runner in Java SDK
> -----------------------------------------------------------
>
>                 Key: BEAM-4684
>                 URL: https://issues.apache.org/jira/browse/BEAM-4684
>             Project: Beam
>          Issue Type: New Feature
>          Components: runner-dataflow
>            Reporter: Yueyang Qiu
>            Assignee: Yueyang Qiu
>            Priority: Major
>          Time Spent: 3h 10m
>  Remaining Estimate: 0h
>
> https://docs.google.com/document/d/117yRKbbcEdm3eIKB_26BHOJGmHSZl1YNoF0RqWGtqAM



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message