[
https://issues.apache.org/jira/browse/BEAM-7980?focusedWorklogId=299132&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-299132
]
ASF GitHub Bot logged work on BEAM-7980:
----------------------------------------
Author: ASF GitHub Bot
Created on: 22/Aug/19 03:28
Start Date: 22/Aug/19 03:28
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_r316483610
##########
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 {
Review comment:
In the future we could look into inverting this logic by extracting the
exactly-once logic into a separate function that can be shared between the SDK
containers.
----------------------------------------------------------------
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: 299132)
Time Spent: 5.5h (was: 5h 20m)
> 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: 5.5h
> 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)