Skip to content

Commit

Permalink
Transfer - Graceful stop does not stop immediately (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Oct 22, 2023
1 parent 45dca6a commit eae9714
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions artifactory/commands/transferfiles/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type transferDelayAction func(phase phaseBase, addedDelayFiles []string) error

// Transfer files using the 'producer-consumer' mechanism and apply a delay action.
func (ftm *transferManager) doTransferWithProducerConsumer(transferAction transferActionWithProducerConsumerType, delayAction transferDelayAction) error {
ftm.pcDetails = newProducerConsumerWrapper()
// Set the producer-consumer value into the referenced value. This allow the Graceful Stop mechanism to access ftm.pcDetails when needed to stop the transfer.
*ftm.pcDetails = newProducerConsumerWrapper()
return ftm.doTransfer(ftm.pcDetails, transferAction, delayAction)
}

Expand Down Expand Up @@ -203,14 +204,14 @@ type producerConsumerWrapper struct {
errorsQueue *clientUtils.ErrorsQueue
}

func newProducerConsumerWrapper() *producerConsumerWrapper {
func newProducerConsumerWrapper() producerConsumerWrapper {
chunkUploaderProducerConsumer := parallel.NewRunner(GetThreads(), tasksMaxCapacity, false)
chunkBuilderProducerConsumer := parallel.NewRunner(GetThreads(), tasksMaxCapacity, false)
chunkUploaderProducerConsumer.SetFinishedNotification(true)
chunkBuilderProducerConsumer.SetFinishedNotification(true)
errorsQueue := clientUtils.NewErrorsQueue(1)

return &producerConsumerWrapper{
return producerConsumerWrapper{
chunkUploaderProducerConsumer: chunkUploaderProducerConsumer,
chunkBuilderProducerConsumer: chunkBuilderProducerConsumer,
errorsQueue: errorsQueue,
Expand Down
3 changes: 2 additions & 1 deletion artifactory/commands/transferfiles/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func (pb *phaseBase) setStopSignal(stopSignal chan os.Signal) {
}

func createTransferPhase(i int) transferPhase {
curPhaseBase := phaseBase{phaseId: i}
// Initialize a pointer to an empty producerConsumerWrapper to allow access the real value in StopGracefully
curPhaseBase := phaseBase{phaseId: i, pcDetails: &producerConsumerWrapper{}}
switch i {
case api.Phase1:
return &fullTransferPhase{phaseBase: curPhaseBase}
Expand Down
3 changes: 2 additions & 1 deletion artifactory/commands/transferfiles/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
const zeroUint32 uint32 = 0

func TestStopGracefully(t *testing.T) {
pBase := &phaseBase{pcDetails: newProducerConsumerWrapper()}
pcWrapper := newProducerConsumerWrapper()
pBase := &phaseBase{pcDetails: &pcWrapper}
chunkUploaderProducerConsumer := pBase.pcDetails.chunkUploaderProducerConsumer
chunkBuilderProducerConsumer := pBase.pcDetails.chunkBuilderProducerConsumer
go func() {
Expand Down
5 changes: 4 additions & 1 deletion artifactory/commands/transferfiles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ func interruptIfRequested(stopSignal chan os.Signal) error {
return err
}
if exist {
stopSignal <- os.Interrupt
select {
case stopSignal <- os.Interrupt:
default:
}
}
return nil
}
Expand Down

0 comments on commit eae9714

Please sign in to comment.