This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from lyft/barrier-impl
Barrier support for task plugins
- Loading branch information
Showing
16 changed files
with
471 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
pkg/apis/flyteworkflow/v1alpha1/mocks/ExecutableNodeStatus.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
26 changes: 5 additions & 21 deletions
26
pkg/apis/flyteworkflow/v1alpha1/mocks/ExecutableTaskNodeStatus.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
pkg/apis/flyteworkflow/v1alpha1/mocks/MutableNodeStatus.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 10 additions & 21 deletions
31
pkg/apis/flyteworkflow/v1alpha1/mocks/MutableTaskNodeStatus.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package task | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/lyft/flytestdlib/logger" | ||
"k8s.io/apimachinery/pkg/util/cache" | ||
|
||
"github.com/lyft/flytepropeller/pkg/controller/nodes/task/config" | ||
) | ||
|
||
type BarrierKey = string | ||
|
||
type PluginCallLog struct { | ||
PluginTransition *pluginRequestedTransition | ||
} | ||
|
||
type BarrierTransition struct { | ||
BarrierClockTick uint32 | ||
CallLog PluginCallLog | ||
} | ||
|
||
var NoBarrierTransition = BarrierTransition{BarrierClockTick: 0} | ||
|
||
type barrier struct { | ||
barrierCacheExpiration time.Duration | ||
barrierTransitions *cache.LRUExpireCache | ||
barrierEnabled bool | ||
} | ||
|
||
func (b *barrier) RecordBarrierTransition(ctx context.Context, k BarrierKey, bt BarrierTransition) { | ||
if b.barrierEnabled { | ||
b.barrierTransitions.Add(k, bt, b.barrierCacheExpiration) | ||
} | ||
} | ||
|
||
func (b *barrier) GetPreviousBarrierTransition(ctx context.Context, k BarrierKey) BarrierTransition { | ||
if b.barrierEnabled { | ||
if v, ok := b.barrierTransitions.Get(k); ok { | ||
f, casted := v.(BarrierTransition) | ||
if !casted { | ||
logger.Errorf(ctx, "Failed to cast recorded value to BarrierTransition") | ||
return NoBarrierTransition | ||
} | ||
return f | ||
} | ||
} | ||
return NoBarrierTransition | ||
} | ||
|
||
func NewLRUBarrier(_ context.Context, cfg config.BarrierConfig) *barrier { | ||
b := &barrier{ | ||
barrierEnabled: cfg.Enabled, | ||
} | ||
if cfg.Enabled { | ||
b.barrierCacheExpiration = cfg.CacheTTL.Duration | ||
b.barrierTransitions = cache.NewLRUExpireCache(cfg.CacheSize) | ||
} | ||
return b | ||
} |
Oops, something went wrong.