Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Add mutex to more session handler actions
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnGarbutt committed Aug 20, 2019
1 parent 50d1c72 commit d3c7e45
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions internal/pkg/v2/dacd/brick_manager_impl/session_action_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,54 @@ func (s *sessionActionHandler) handleCreate(action datamodel.SessionAction) {
}

func (s *sessionActionHandler) handleDelete(action datamodel.SessionAction) {
// TODO... mutex, etc?
s.doUnmount(action)
if !action.Session.Status.DeleteSkipCopyDataOut && !action.Session.Status.CopyDataOutComplete {
s.fsProvider.DataCopyOut(action.Session)
}
s.fsProvider.Delete(action.Session)
s.sessionRegistry.DeleteSession(action.Session)
s.actions.CompleteSessionAction(action)
s.processWithMutex(action, func() (datamodel.Session, error) {
if err := s.doUnmount(action); err != nil {
log.Println("failed unmount during delete", action.Session.Name)
}
if !action.Session.Status.DeleteSkipCopyDataOut && !action.Session.Status.CopyDataOutComplete {
if err := s.fsProvider.DataCopyOut(action.Session); err != nil {
log.Println("failed DataCopyOut during delete", action.Session.Name)
}
}

if err := s.fsProvider.Delete(action.Session); err != nil {
return action.Session, err
}

return action.Session, s.sessionRegistry.DeleteSession(action.Session)
})
}

func (s *sessionActionHandler) handleCopyIn(action datamodel.SessionAction) {
s.fsProvider.DataCopyIn(action.Session)
s.actions.CompleteSessionAction(action)
s.processWithMutex(action, func() (datamodel.Session, error) {
err := s.fsProvider.DataCopyIn(action.Session)
if err != nil {
return action.Session, err
}

session, err := s.sessionRegistry.GetSession(action.Session.Name)
if err != nil {
session = action.Session
}
session.Status.CopyDataInComplete = true
return s.sessionRegistry.UpdateSession(session)
})
}

func (s *sessionActionHandler) handleCopyOut(action datamodel.SessionAction) {
s.processWithMutex(action, func() (datamodel.Session, error) {
err := s.fsProvider.DataCopyOut(action.Session)
if err != nil {
return action.Session, err
}

session, err := s.sessionRegistry.GetSession(action.Session.Name)
if err != nil {
session = action.Session
}
session.Status.CopyDataOutComplete = true
return s.sessionRegistry.UpdateSession(session)
})
}

func (s *sessionActionHandler) handleMount(action datamodel.SessionAction) {
Expand All @@ -149,7 +184,8 @@ func (s *sessionActionHandler) handleMount(action datamodel.SessionAction) {
s.actions.CompleteSessionAction(action)
}

func (s *sessionActionHandler) doUnmount(action datamodel.SessionAction) {
func (s *sessionActionHandler) doUnmount(action datamodel.SessionAction) error {
var lastError error
if action.Session.ActualSizeBytes > 0 {
s.fsProvider.Unmount(action.Session,
datamodel.AttachmentSession{Hosts: action.Session.RequestedAttachHosts})
Expand All @@ -161,14 +197,10 @@ func (s *sessionActionHandler) doUnmount(action datamodel.SessionAction) {
datamodel.AttachmentSession{Hosts: action.Session.RequestedAttachHosts})
}
}
return lastError
}

func (s *sessionActionHandler) handleUnmount(action datamodel.SessionAction) {
s.doUnmount(action)
s.actions.CompleteSessionAction(action)
}

func (s *sessionActionHandler) handleCopyOut(action datamodel.SessionAction) {
s.fsProvider.DataCopyOut(action.Session)
// TODO: update session.CopyDataOutComplete, mutex, etc.
s.actions.CompleteSessionAction(action)
}

0 comments on commit d3c7e45

Please sign in to comment.