From 19ec6177e0be432339a3470b0e296c30375da742 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Tue, 5 Jul 2016 11:06:58 +0800 Subject: [PATCH 1/2] update --- job/error/error.go | 23 -------------------- job/replication/error.go | 10 ++++----- job/replication/transfer.go | 42 ++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 30 deletions(-) delete mode 100644 job/error/error.go diff --git a/job/error/error.go b/job/error/error.go deleted file mode 100644 index 680b1c6c8..000000000 --- a/job/error/error.go +++ /dev/null @@ -1,23 +0,0 @@ -/* - Copyright (c) 2016 VMware, Inc. All Rights Reserved. - Licensed 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 error - -// RetryChecker checks whether a job should retry if encounters an error -type RetryChecker interface { - // Retry : if the error can be disappear after retrying the job, Retry - // returns true - Retry(error) bool -} diff --git a/job/replication/error.go b/job/replication/error.go index 53c7ca219..197dabbd3 100644 --- a/job/replication/error.go +++ b/job/replication/error.go @@ -19,12 +19,10 @@ import ( "net" ) -// ReplicaRetryChecker determines whether a job should be retried when an error occurred -type ReplicaRetryChecker struct { -} - -// Retry ... -func (r *ReplicaRetryChecker) Retry(err error) bool { +func retry(err error) bool { + if err == nil { + return false + } return isTemporary(err) } diff --git a/job/replication/transfer.go b/job/replication/transfer.go index 28ad5aa41..d66802d36 100644 --- a/job/replication/transfer.go +++ b/job/replication/transfer.go @@ -152,6 +152,16 @@ type Checker struct { // Enter check existence of project, if it does not exist, create it, // if it exists, check whether the user has write privilege to it. func (c *Checker) Enter() (string, error) { + state, err := c.enter() + if err != nil && retry(err) { + return models.JobRetrying, err + } + + return state, err + +} + +func (c *Checker) enter() (string, error) { enter: exist, canWrite, err := c.projectExist() if err != nil { @@ -316,6 +326,16 @@ type ManifestPuller struct { // Enter pulls manifest of a tag and checks if all blobs exist in the destination registry func (m *ManifestPuller) Enter() (string, error) { + state, err := m.enter() + if err != nil && retry(err) { + return models.JobRetrying, err + } + + return state, err + +} + +func (m *ManifestPuller) enter() (string, error) { if len(m.tags) == 0 { m.logger.Infof("no tag needs to be replicated, next state is \"finished\"") return models.JobFinished, nil @@ -389,6 +409,16 @@ type BlobTransfer struct { // Enter pulls blobs and then pushs them to destination registry. func (b *BlobTransfer) Enter() (string, error) { + state, err := b.enter() + if err != nil && retry(err) { + return models.JobRetrying, err + } + + return state, err + +} + +func (b *BlobTransfer) enter() (string, error) { name := b.repository tag := b.tags[0] for _, blob := range b.blobs { @@ -416,7 +446,17 @@ type ManifestPusher struct { // Enter checks the existence of manifest in the source registry first, and if it // exists, pushs it to destination registry. The checking operation is to avoid // the situation that the tag is deleted during the blobs transfering -func (m *ManifestPusher) Enter() (string, error) { +func (b *ManifestPusher) Enter() (string, error) { + state, err := b.enter() + if err != nil && retry(err) { + return models.JobRetrying, err + } + + return state, err + +} + +func (m *ManifestPusher) enter() (string, error) { name := m.repository tag := m.tags[0] _, exist, err := m.srcClient.ManifestExist(tag) From e2afc3e51c3c6e0dc2e202dd417414a249186dce Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Tue, 5 Jul 2016 11:22:16 +0800 Subject: [PATCH 2/2] update --- job/replication/delete.go | 11 +++++++++++ job/replication/transfer.go | 16 ++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/job/replication/delete.go b/job/replication/delete.go index 1bec6378f..ce8ef6a98 100644 --- a/job/replication/delete.go +++ b/job/replication/delete.go @@ -74,6 +74,17 @@ func (d *Deleter) Exit() error { // Enter deletes repository or tags func (d *Deleter) Enter() (string, error) { + state, err := d.enter() + if err != nil && retry(err) { + d.logger.Info("waiting for retrying...") + return models.JobRetrying, nil + } + + return state, err + +} + +func (d *Deleter) enter() (string, error) { if len(d.tags) == 0 { tags, err := d.dstClient.ListTag() diff --git a/job/replication/transfer.go b/job/replication/transfer.go index d66802d36..4eee419f4 100644 --- a/job/replication/transfer.go +++ b/job/replication/transfer.go @@ -154,7 +154,8 @@ type Checker struct { func (c *Checker) Enter() (string, error) { state, err := c.enter() if err != nil && retry(err) { - return models.JobRetrying, err + c.logger.Info("waiting for retrying...") + return models.JobRetrying, nil } return state, err @@ -328,7 +329,8 @@ type ManifestPuller struct { func (m *ManifestPuller) Enter() (string, error) { state, err := m.enter() if err != nil && retry(err) { - return models.JobRetrying, err + m.logger.Info("waiting for retrying...") + return models.JobRetrying, nil } return state, err @@ -411,7 +413,8 @@ type BlobTransfer struct { func (b *BlobTransfer) Enter() (string, error) { state, err := b.enter() if err != nil && retry(err) { - return models.JobRetrying, err + b.logger.Info("waiting for retrying...") + return models.JobRetrying, nil } return state, err @@ -446,10 +449,11 @@ type ManifestPusher struct { // Enter checks the existence of manifest in the source registry first, and if it // exists, pushs it to destination registry. The checking operation is to avoid // the situation that the tag is deleted during the blobs transfering -func (b *ManifestPusher) Enter() (string, error) { - state, err := b.enter() +func (m *ManifestPusher) Enter() (string, error) { + state, err := m.enter() if err != nil && retry(err) { - return models.JobRetrying, err + m.logger.Info("waiting for retrying...") + return models.JobRetrying, nil } return state, err