Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer - Graceful stop does not stop immediately #1005

Merged
merged 2 commits into from
Oct 22, 2023
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
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
Loading