tr: don't lock for immutable fields

This commit is contained in:
Michael Schurter 2018-06-29 15:39:22 -07:00
parent f473cd03d6
commit 67874e761f
2 changed files with 7 additions and 10 deletions

View file

@ -20,8 +20,10 @@ import (
)
type TaskRunner struct {
// allocID is immutable so store a copy to access without locks
allocID string
// allocID and taskName are immutable so store a copy to access without
// locks
allocID string
taskName string
alloc *structs.Allocation
allocLock sync.Mutex
@ -108,6 +110,7 @@ func NewTaskRunner(config *Config) (*TaskRunner, error) {
clientConfig: config.ClientConfig,
task: config.Task,
taskDir: config.TaskDir,
taskName: config.Task.Name,
envBuilder: envBuilder,
state: config.State,
ctx: trCtx,
@ -173,7 +176,7 @@ func (tr *TaskRunner) initLabels() {
},
{
Name: "task",
Value: tr.Name(),
Value: tr.taskName,
},
}
}
@ -303,7 +306,7 @@ func (tr *TaskRunner) initDriver() error {
driverCtx := driver.NewDriverContext(
alloc.Job.Name,
alloc.TaskGroup,
tr.Name(),
tr.taskName,
tr.allocID,
tr.clientConfig, // XXX Why does it need this
tr.clientConfig.Node, // XXX THIS I NEED TO FIX

View file

@ -2,12 +2,6 @@ package taskrunner
import "github.com/hashicorp/nomad/nomad/structs"
func (tr *TaskRunner) Name() string {
tr.taskLock.RLock()
defer tr.taskLock.RUnlock()
return tr.task.Name
}
func (tr *TaskRunner) Task() *structs.Task {
tr.taskLock.RLock()
defer tr.taskLock.RUnlock()