Skip to content

Commit

Permalink
added more changes worker
Browse files Browse the repository at this point in the history
  • Loading branch information
mindhash committed Aug 7, 2018
1 parent 3724869 commit f987a79
Show file tree
Hide file tree
Showing 291 changed files with 4,115 additions and 554 deletions.
Binary file added bin/create-update-delete-deployment
Binary file not shown.
Binary file added bin/in-cluster-client-configuration
Binary file not shown.
Binary file added bin/out-of-cluster-client-configuration
Binary file not shown.
Binary file added bin/workqueue
Binary file not shown.
Binary file added pkg/darwin_amd64/github.com/pebbe/zmq4.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/discovery.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/dynamic.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/dynamic/fake.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/informers.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/kubernetes.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/pkg/version.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/rest.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/rest/fake.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/rest/watch.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/restmapper.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/scale.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/scale/fake.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/scale/scheme.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/testing.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/tools/auth.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/tools/cache.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/tools/metrics.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/tools/pager.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/tools/record.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/transport.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/util/buffer.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/util/cert.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/util/exec.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/util/homedir.a
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/util/integer.a
Binary file not shown.
Binary file not shown.
Binary file added pkg/darwin_amd64/k8s.io/client-go/util/retry.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions src/github.com/golang/glog
Submodule glog added at 23def4
1 change: 1 addition & 0 deletions src/github.com/google/gofuzz
Submodule gofuzz added at 24818f
1 change: 1 addition & 0 deletions src/github.com/googleapis/gnostic
Submodule gnostic added at 48a0ec
1 change: 1 addition & 0 deletions src/github.com/pebbe/zmq4
Submodule zmq4 added at 5b443b
1 change: 1 addition & 0 deletions src/gopkg.in/yaml.v2
Submodule yaml.v2 added at 5420a8
4 changes: 2 additions & 2 deletions src/hyperview.in/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewApiClient(repoDir string) (*ApiClient, error) {
return nil, err
}

repo_info, err := rest_client.NewRESTClient(server_addr, c.RepoUriPath, http.DefaultClient)
repo_attrs, err := rest_client.NewRESTClient(server_addr, c.RepoUriPath, http.DefaultClient)
if err != nil {
return nil, err
}
Expand All @@ -65,7 +65,7 @@ func NewApiClient(repoDir string) (*ApiClient, error) {
code_sync := code_sync.NewClient(c.ServerAddr, repo_fs)

return &ApiClient {
repoInfo: repo_info,
repoInfo: repo_attrs,
codeSync: code_sync,
repoFS: repo_fs,
}, nil
Expand Down
47 changes: 47 additions & 0 deletions src/hyperview.in/server/base/backoff/backoff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package backoff

import "time"

//backoff ported from cenkalti/backoff

// BackOff is a backoff policy for retrying an operation.
type BackOff interface {
// returns duration
NextBackOff() time.Duration

// Reset to initial state.
Reset()
}

// Stop indicates that no more retries should be made for use in NextBackOff().
const Stop time.Duration = -1

// ZeroBackOff is a fixed backoff policy whose backoff time is always zero,
// meaning that the operation is retried immediately without waiting, indefinitely.
type ZeroBackOff struct{}

func (b *ZeroBackOff) Reset() {}

func (b *ZeroBackOff) NextBackOff() time.Duration { return 0 }

// StopBackOff is a fixed backoff policy that always returns backoff.Stop for
// NextBackOff(), meaning that the operation should never be retried.
type StopBackOff struct{}

func (b *StopBackOff) Reset() {}

func (b *StopBackOff) NextBackOff() time.Duration { return Stop }

// ConstantBackOff is a backoff policy that always returns the same backoff delay.
// This is in contrast to an exponential backoff policy,
// which returns a delay that grows longer as you call NextBackOff() over and over again.
type ConstantBackOff struct {
Interval time.Duration
}

func (b *ConstantBackOff) Reset() {}
func (b *ConstantBackOff) NextBackOff() time.Duration { return b.Interval }

func NewConstantBackOff(d time.Duration) *ConstantBackOff {
return &ConstantBackOff{Interval: d}
}
59 changes: 59 additions & 0 deletions src/hyperview.in/server/base/backoff/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package backoff

import (
"context"
"time"
)

// BackOffContext is a backoff policy that stops retrying after the context
// is canceled.
type BackOffContext interface {
BackOff
Context() context.Context
}

type backOffContext struct {
BackOff
ctx context.Context
}

// WithContext returns a BackOffContext with context ctx
//
// ctx must not be nil
func WithContext(b BackOff, ctx context.Context) BackOffContext {
if ctx == nil {
panic("nil context")
}

if b, ok := b.(*backOffContext); ok {
return &backOffContext{
BackOff: b.BackOff,
ctx: ctx,
}
}

return &backOffContext{
BackOff: b,
ctx: ctx,
}
}

func ensureContext(b BackOff) BackOffContext {
if cb, ok := b.(BackOffContext); ok {
return cb
}
return WithContext(b, context.Background())
}

func (b *backOffContext) Context() context.Context {
return b.ctx
}

func (b *backOffContext) NextBackOff() time.Duration {
select {
case <-b.Context().Done():
return Stop
default:
return b.BackOff.NextBackOff()
}
}
147 changes: 147 additions & 0 deletions src/hyperview.in/server/base/backoff/exponential.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package backoff

import (
"math/rand"
"time"
)

/*
ExponentialBackOff is a backoff implementation that increases the backoff
period for each retry attempt using a randomization function that grows exponentially.
NextBackOff() is calculated using the following formula:
randomized interval =
RetryInterval * (random value in range [1 - RandomizationFactor, 1 + RandomizationFactor])
In other words NextBackOff() will range between the randomization factor
percentage below and above the retry interval.
For example, given the following parameters:
RetryInterval = 2
RandomizationFactor = 0.5
Multiplier = 2
the actual backoff period used in the next retry attempt will range between 1 and 3 seconds,
multiplied by the exponential, that is, between 2 and 6 seconds.
Note: MaxInterval caps the RetryInterval and not the randomized interval.
If the time elapsed since an ExponentialBackOff instance is created goes past the
MaxElapsedTime, then the method NextBackOff() starts returning backoff.Stop.
The elapsed time can be reset by calling Reset().
Example: Given the following default arguments, for 10 tries the sequence will be,
and assuming we go over the MaxElapsedTime on the 10th try:
Request # RetryInterval (seconds) Randomized Interval (seconds)
1 0.5 [0.25, 0.75]
2 0.75 [0.375, 1.125]
3 1.125 [0.562, 1.687]
4 1.687 [0.8435, 2.53]
5 2.53 [1.265, 3.795]
6 3.795 [1.897, 5.692]
7 5.692 [2.846, 8.538]
8 8.538 [4.269, 12.807]
9 12.807 [6.403, 19.210]
10 19.210 backoff.Stop
Note: Implementation is not thread-safe.
*/

type ExponentialBackOff struct {
InitialInterval time.Duration
RandomizationFactor float64
Multiplier float64
MaxInterval time.Duration
// After MaxElapsedTime the ExponentialBackOff stops.
// It never stops if MaxElapsedTime == 0.
MaxElapsedTime time.Duration
Clock Clock

currentInterval time.Duration
startTime time.Time
random *rand.Rand
}

// Clock is an interface that returns current time for BackOff.
type Clock interface {
Now() time.Time
}

// Default values for ExponentialBackOff.
const (
DefaultInitialInterval = 500 * time.Millisecond
DefaultRandomizationFactor = 0.5
DefaultMultiplier = 1.5
DefaultMaxInterval = 60 * time.Second
DefaultMaxElapsedTime = 15 * time.Minute
)

// NewExponentialBackOff creates an instance of ExponentialBackOff using default values.
func NewExponentialBackOff() *ExponentialBackOff {
b := &ExponentialBackOff{
InitialInterval: DefaultInitialInterval,
RandomizationFactor: DefaultRandomizationFactor,
Multiplier: DefaultMultiplier,
MaxInterval: DefaultMaxInterval,
MaxElapsedTime: DefaultMaxElapsedTime,
Clock: SystemClock,
random: rand.New(rand.NewSource(time.Now().UnixNano())),
}
b.Reset()
return b
}

type systemClock struct{}

func (t systemClock) Now() time.Time {
return time.Now()
}

// SystemClock implements Clock interface that uses time.Now().
var SystemClock = systemClock{}

// Reset the interval back to the initial retry interval and restarts the timer.
func (b *ExponentialBackOff) Reset() {
b.currentInterval = b.InitialInterval
b.startTime = b.Clock.Now()
}

// NextBackOff calculates the next backoff interval using the formula:
// Randomized interval = RetryInterval +/- (RandomizationFactor * RetryInterval)
func (b *ExponentialBackOff) NextBackOff() time.Duration {
// Make sure we have not gone over the maximum elapsed time.
if b.MaxElapsedTime != 0 && b.GetElapsedTime() > b.MaxElapsedTime {
return Stop
}
defer b.incrementCurrentInterval()
if b.random == nil {
b.random = rand.New(rand.NewSource(time.Now().UnixNano()))
}
return getRandomValueFromInterval(b.RandomizationFactor, b.random.Float64(), b.currentInterval)
}

// GetElapsedTime returns the elapsed time since an ExponentialBackOff instance
// is created and is reset when Reset() is called.
//
// The elapsed time is computed using time.Now().UnixNano(). It is
// safe to call even while the backoff policy is used by a running
// ticker.
func (b *ExponentialBackOff) GetElapsedTime() time.Duration {
return b.Clock.Now().Sub(b.startTime)
}

// Increments the current interval by multiplying it with the multiplier.
func (b *ExponentialBackOff) incrementCurrentInterval() {
// Check for overflow, if overflow is detected set the current interval to the max interval.
if float64(b.currentInterval) >= float64(b.MaxInterval)/b.Multiplier {
b.currentInterval = b.MaxInterval
} else {
b.currentInterval = time.Duration(float64(b.currentInterval) * b.Multiplier)
}
}

// Returns a random value from the following interval:
// [randomizationFactor * currentInterval, randomizationFactor * currentInterval].
func getRandomValueFromInterval(randomizationFactor, random float64, currentInterval time.Duration) time.Duration {
var delta = randomizationFactor * float64(currentInterval)
var minInterval = float64(currentInterval) - delta
var maxInterval = float64(currentInterval) + delta

// Get a random value from the range [minInterval, maxInterval].
// The formula used below has a +1 because if the minInterval is 1 and the maxInterval is 3 then
// we want a 33% chance for selecting either 1, 2 or 3.
return time.Duration(minInterval + (random * (maxInterval - minInterval + 1)))
}
78 changes: 78 additions & 0 deletions src/hyperview.in/server/base/backoff/retry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package backoff

import "time"

// An Operation is executing by Retry() or RetryNotify().
// The operation will be retried using a backoff policy if it returns an error.
type Operation func() error

// Notify is a notify-on-error function. It receives an operation error and
// backoff delay if the operation failed (with an error).
//
// NOTE that if the backoff policy stated to stop retrying,
// the notify function isn't called.
type Notify func(error, time.Duration)

// Retry the operation o until it does not return error or BackOff stops.
// o is guaranteed to be run at least once.
// It is the caller's responsibility to reset b after Retry returns.
//
// If o returns a *PermanentError, the operation is not retried, and the
// wrapped error is returned.
//
// Retry sleeps the goroutine for the duration returned by BackOff after a
// failed operation returns.
func Retry(o Operation, b BackOff) error { return RetryNotify(o, b, nil) }

// RetryNotify calls notify function with the error and wait duration
// for each failed attempt before sleep.
func RetryNotify(operation Operation, b BackOff, notify Notify) error {
var err error
var next time.Duration

cb := ensureContext(b)

b.Reset()
for {
if err = operation(); err == nil {
return nil
}

if permanent, ok := err.(*PermanentError); ok {
return permanent.Err
}

if next = b.NextBackOff(); next == Stop {
return err
}

if notify != nil {
notify(err, next)
}

t := time.NewTimer(next)

select {
case <-cb.Context().Done():
t.Stop()
return err
case <-t.C:
}
}
}

// PermanentError signals that the operation should not be retried.
type PermanentError struct {
Err error
}

func (e *PermanentError) Error() string {
return e.Err.Error()
}

// Permanent wraps the given err in a *PermanentError.
func Permanent(err error) *PermanentError {
return &PermanentError{
Err: err,
}
}
Loading

0 comments on commit f987a79

Please sign in to comment.