Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions app/lb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,16 @@ func (s *Server) processRun(ctx context.Context, logger logrus.FieldLogger, stre
break
}

cont.Worker.ResetErrorCount()

response, err := s.relayReponse(logger, stream, cont, resCh)

if response != nil && response.Cached {
// Add container to worker cache if we got any response.
cont.ID = response.ContainerId
s.addCache(cont, def)
if response != nil {
cont.Worker.ResetErrorCount()

if response.Cached {
// Add container to worker cache if we got cached response.
cont.ID = response.ContainerId
s.addCache(cont, def)
}
}

logger.WithFields(logrus.Fields{"took": time.Since(start), "mcpu": cont.mCPU}).Info("grpc:lb:Run")
Expand Down Expand Up @@ -329,36 +331,36 @@ func (s *Server) removeCache(w *Worker, def *script.Definition, containerID stri

s.mu.Lock()

if w.RemoveCache(def, containerID) {
// Remove worker container with specified definition from cache map.
if m, ok := s.workerContainersCached[defHash]; ok {
if _, ok = m[containerID]; ok {
removedContainer = true
w.RemoveCache(def, containerID)

delete(m, containerID)
}
// Remove worker container with specified definition from cache map.
if m, ok := s.workerContainersCached[defHash]; ok {
if _, ok = m[containerID]; ok {
removedContainer = true

if len(m) == 0 {
delete(s.workerContainersCached, defHash)
}
delete(m, containerID)
}

// Decrease refcount of script index for given worker.
if m, ok := s.workersByIndex[idx]; ok {
if v, ok := m[w.ID]; ok {
removedIdx = true
if len(m) == 0 {
delete(s.workerContainersCached, defHash)
}
}

if v <= 1 {
delete(m, w.ID)
} else {
m[w.ID]--
}
}
// Decrease refcount of script index for given worker.
if m, ok := s.workersByIndex[idx]; ok {
if v, ok := m[w.ID]; ok {
removedIdx = true

if len(m) == 0 {
delete(s.workersByIndex, idx)
if v <= 1 {
delete(m, w.ID)
} else {
m[w.ID]--
}
}

if len(m) == 0 {
delete(s.workersByIndex, idx)
}
}

s.mu.Unlock()
Expand Down
8 changes: 8 additions & 0 deletions app/lb/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ type WorkerContainer struct {
async uint32
}

func (w *WorkerContainer) String() string {
if w.ID == "" {
return fmt.Sprintf("{ID:Fresh, Worker:%s}", w.Worker.ID)
}

return fmt.Sprintf("{ID:%s, Worker:%s}", w.ID, w.Worker.ID)
}

// Conns returns number of current connections.
func (w *WorkerContainer) Conns() uint32 {
return atomic.LoadUint32(&w.conns)
Expand Down
8 changes: 0 additions & 8 deletions app/script/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ package script

import (
"errors"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var (
// gRPC errors.

// ErrSourceNotAvailable signals that specified source hash was not found.
ErrSourceNotAvailable = status.Error(codes.FailedPrecondition, "source not available")

// Result errors.

// ErrIncorrectData signals when output structure is malformed.
Expand Down
2 changes: 1 addition & 1 deletion app/script/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (r *DockerRunner) Run(ctx context.Context, logger logrus.FieldLogger, reque
// Check and refresh source and environment.
if r.fileRepo.Get(def.SourceHash) == "" || (def.Environment != "" && r.fileRepo.Get(def.Environment) == "") {
logger.Error("grpc:script:Run source not available")
return nil, ErrSourceNotAvailable
return nil, common.ErrSourceNotAvailable
}

r.taskWaitGroup.Add(1)
Expand Down