Skip to content

Commit

Permalink
Merge "External build failures are terminal"
Browse files Browse the repository at this point in the history
  • Loading branch information
sykesm authored and Gerrit Code Review committed Nov 7, 2019
2 parents e0e133a + 78cc7fe commit cd97bc3
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 170 deletions.
42 changes: 18 additions & 24 deletions core/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,10 @@ type Router struct {
func (r *Router) getInstance(ccid string) Instance {
r.mutex.Lock()
defer r.mutex.Unlock()

// Note, to resolve the locking problem which existed in the previous code, we never delete
// references from the map. In this way, it is safe to release the lock and operate
// on the returned reference

if r.containers == nil {
r.containers = map[string]Instance{}
}

vm, ok := r.containers[ccid]
if !ok {
return UninitializedInstance{}
Expand All @@ -86,43 +82,41 @@ func (r *Router) getInstance(ccid string) Instance {
}

func (r *Router) Build(ccid string) error {
// for now, the package ID we retrieve from the FS is always the ccid
// the chaincode uses for registration
packageID := ccid

var instance Instance

var externalErr error
if r.ExternalVM != nil {
metadata, codeStream, err := r.PackageProvider.GetChaincodePackage(packageID)
// for now, the package ID we retrieve from the FS is always the ccid
// the chaincode uses for registration
metadata, codeStream, err := r.PackageProvider.GetChaincodePackage(ccid)
if err != nil {
return errors.WithMessage(err, "get chaincode package for external build failed")
return errors.WithMessage(err, "failed to get chaincode package for external build")
}
defer codeStream.Close()

instance, err = r.ExternalVM.Build(ccid, metadata, codeStream)
if err != nil {
return errors.WithMessage(err, "external builder failed")
}
instance, externalErr = r.ExternalVM.Build(ccid, metadata, codeStream)
codeStream.Close()
}

var dockerErr error
if r.ExternalVM == nil || externalErr != nil {
if instance == nil {
metadata, codeStream, err := r.PackageProvider.GetChaincodePackage(ccid)
if err != nil {
return errors.WithMessage(err, "get chaincode package for docker build failed")
return errors.WithMessage(err, "failed to get chaincode package for docker build")
}
instance, dockerErr = r.DockerVM.Build(ccid, metadata, codeStream)
codeStream.Close()
}
defer codeStream.Close()

if dockerErr != nil {
return errors.WithMessagef(dockerErr, "failed external (%s) and docker build", externalErr)
instance, err = r.DockerVM.Build(ccid, metadata, codeStream)
if err != nil {
return errors.WithMessage(err, "docker build failed")
}
}

r.mutex.Lock()
defer r.mutex.Unlock()

if r.containers == nil {
r.containers = map[string]Instance{}
}

r.containers[ccid] = instance

return nil
Expand Down
Loading

0 comments on commit cd97bc3

Please sign in to comment.