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

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

                Author: ASF GitHub Bot
            Created on: 01/Sep/19 17:43
            Start Date: 01/Sep/19 17:43
    Worklog Time Spent: 10m 
      Work Description: tweise commented on pull request #9398: [BEAM-7980] 
Exactly once artifact retrieval for Python SDK worker pool
URL: https://github.com/apache/beam/pull/9398#discussion_r319768879
 
 

 ##########
 File path: sdks/python/container/boot.go
 ##########
 @@ -105,18 +107,57 @@ func main() {
 
        // (2) Retrieve and install the staged packages.
 
-       dir := filepath.Join(*semiPersistDir, "staged")
+       func() {
 
-       files, err := artifact.Materialize(ctx, *artifactEndpoint, 
info.GetRetrievalToken(), dir)
-       if err != nil {
-               log.Fatalf("Failed to retrieve staged files: %v", err)
-       }
+        installCompleteFile := filepath.Join(os.TempDir(), 
"beam.install.complete")
 
-       // TODO(herohde): the packages to install should be specified 
explicitly. It
-       // would also be possible to install the SDK in the Dockerfile.
-       if setupErr := installSetupPackages(files, dir); setupErr != nil {
-               log.Fatalf("Failed to install required packages: %v", setupErr)
-       }
+               // skip if install already complete
+               _, err = os.Stat(installCompleteFile)
+               if err == nil {
+                       return
+               }
+
+               // lock to guard from concurrent artifact retrieval and 
installation,
+               // when called by child processes in a worker pool
+               lock, err := lockfile.New(filepath.Join(os.TempDir(), 
"beam.install.lck"))
+               if err != nil {
+                       log.Fatalf("Cannot init artifact retrieval lock: %v", 
err)
+               }
+
+               for err = lock.TryLock(); err != nil; err = lock.TryLock() {
+                       switch err {
+                       case lockfile.ErrBusy, lockfile.ErrNotExist:
+                               time.Sleep(5 * time.Second)
+                               log.Printf("Worker %v waiting for artifact 
retrieval lock: %v", *id, lock)
+                       default:
+                               log.Fatalf("Worker %v could not obtain artifact 
retrieval lock: %v", *id, err)
+                       }
+               }
+               defer lock.Unlock()
+
+               // skip if install already complete
+               _, err = os.Stat(installCompleteFile)
+               if err == nil {
+                       return
+               }
+
+               dir := filepath.Join(*semiPersistDir, "staged")
+
+               files, err := artifact.Materialize(ctx, *artifactEndpoint, 
info.GetRetrievalToken(), dir)
+               if err != nil {
+                       log.Fatalf("Failed to retrieve staged files: %v", err)
+               }
+
+               // TODO(herohde): the packages to install should be specified 
explicitly. It
+               // would also be possible to install the SDK in the Dockerfile.
+               if setupErr := installSetupPackages(files, dir); setupErr != 
nil {
+                       log.Fatalf("Failed to install required packages: %v", 
setupErr)
+               }
+
+               // mark install complete
+               os.OpenFile(installCompleteFile, os.O_RDONLY|os.O_CREATE, 0666)
+
+    }()
 
        // (3) Invoke python
 
 
 Review comment:
   They don't have to be same on Flink, but the staged artifacts have to be 
identical.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


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

    Worklog Id:     (was: 304999)
    Time Spent: 8h 10m  (was: 8h)

> External environment with containerized worker pool
> ---------------------------------------------------
>
>                 Key: BEAM-7980
>                 URL: https://issues.apache.org/jira/browse/BEAM-7980
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-py-harness
>            Reporter: Thomas Weise
>            Assignee: Thomas Weise
>            Priority: Major
>          Time Spent: 8h 10m
>  Remaining Estimate: 0h
>
> Augment Beam Python docker image and boot.go so that it can be used to launch 
> BeamFnExternalWorkerPoolServicer.
> [https://docs.google.com/document/d/1z3LNrRtr8kkiFHonZ5JJM_L4NWNBBNcqRc_yAf6G0VI/edit#heading=h.lnhm75dhvhi0]
>  



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to