Merge pull request #409 from sameo/topic/fat-lock
Serialize Update and Sandbox/Container creation operations
This commit is contained in:
commit
3c7f3ab2ec
3 changed files with 22 additions and 12 deletions
|
@ -230,6 +230,10 @@ func ensureSaneLogPath(logPath string) error {
|
||||||
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) {
|
func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) {
|
||||||
logrus.Debugf("CreateContainerRequest %+v", req)
|
logrus.Debugf("CreateContainerRequest %+v", req)
|
||||||
s.Update()
|
s.Update()
|
||||||
|
|
||||||
|
s.updateLock.RLock()
|
||||||
|
defer s.updateLock.RUnlock()
|
||||||
|
|
||||||
sbID := req.PodSandboxId
|
sbID := req.PodSandboxId
|
||||||
if sbID == "" {
|
if sbID == "" {
|
||||||
return nil, fmt.Errorf("PodSandboxId should not be empty")
|
return nil, fmt.Errorf("PodSandboxId should not be empty")
|
||||||
|
|
|
@ -65,6 +65,9 @@ func (s *Server) runContainer(container *oci.Container, cgroupParent string) err
|
||||||
|
|
||||||
// RunPodSandbox creates and runs a pod-level sandbox.
|
// RunPodSandbox creates and runs a pod-level sandbox.
|
||||||
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) {
|
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) {
|
||||||
|
s.updateLock.RLock()
|
||||||
|
defer s.updateLock.RUnlock()
|
||||||
|
|
||||||
logrus.Debugf("RunPodSandboxRequest %+v", req)
|
logrus.Debugf("RunPodSandboxRequest %+v", req)
|
||||||
var processLabel, mountLabel, netNsPath, resolvPath string
|
var processLabel, mountLabel, netNsPath, resolvPath string
|
||||||
// process req.Name
|
// process req.Name
|
||||||
|
@ -91,18 +94,6 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err = s.podIDIndex.Add(id); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
if err2 := s.podIDIndex.Delete(id); err2 != nil {
|
|
||||||
logrus.Warnf("couldn't delete pod id %s from idIndex", id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
podContainer, err := s.storage.CreatePodSandbox(s.imageContext,
|
podContainer, err := s.storage.CreatePodSandbox(s.imageContext,
|
||||||
name, id,
|
name, id,
|
||||||
s.config.PauseImage, "",
|
s.config.PauseImage, "",
|
||||||
|
@ -292,6 +283,17 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
s.addSandbox(sb)
|
s.addSandbox(sb)
|
||||||
|
if err = s.podIDIndex.Add(id); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
if err2 := s.podIDIndex.Delete(id); err2 != nil {
|
||||||
|
logrus.Warnf("couldn't delete pod id %s from idIndex", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
for k, v := range annotations {
|
for k, v := range annotations {
|
||||||
g.AddAnnotation(k, v)
|
g.AddAnnotation(k, v)
|
||||||
|
|
|
@ -35,6 +35,7 @@ type Server struct {
|
||||||
images storage.ImageServer
|
images storage.ImageServer
|
||||||
storage storage.RuntimeServer
|
storage storage.RuntimeServer
|
||||||
stateLock sync.Mutex
|
stateLock sync.Mutex
|
||||||
|
updateLock sync.RWMutex
|
||||||
state *serverState
|
state *serverState
|
||||||
netPlugin ocicni.CNIPlugin
|
netPlugin ocicni.CNIPlugin
|
||||||
podNameIndex *registrar.Registrar
|
podNameIndex *registrar.Registrar
|
||||||
|
@ -288,6 +289,9 @@ func (s *Server) Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) update() error {
|
func (s *Server) update() error {
|
||||||
|
s.updateLock.Lock()
|
||||||
|
defer s.updateLock.Unlock()
|
||||||
|
|
||||||
containers, err := s.store.Containers()
|
containers, err := s.store.Containers()
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
logrus.Warnf("could not read containers and sandboxes: %v", err)
|
logrus.Warnf("could not read containers and sandboxes: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue