github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/commands/transferfiles/producerconsumer.go (about) 1 package transferfiles 2 3 import ( 4 "sync" 5 6 "github.com/jfrog/gofrog/parallel" 7 clientUtils "github.com/jfrog/jfrog-client-go/utils" 8 ) 9 10 type producerConsumerWrapper struct { 11 // This Producer-Consumer is used to upload chunks, initialized in newProducerConsumerWrapper; each uploading thread waits to be given tasks from the queue. 12 chunkUploaderProducerConsumer parallel.Runner 13 // This Producer-Consumer is used to execute AQLs and build chunks from the AQLs' results. The chunks data is sent to the go routines that will upload them. 14 // Initialized in newProducerConsumerWrapper; each builder thread waits to be given tasks from the queue. 15 chunkBuilderProducerConsumer parallel.Runner 16 // Errors related to chunkUploaderProducerConsumer and chunkBuilderProducerConsumer are logged in this queue. 17 errorsQueue *clientUtils.ErrorsQueue 18 // This variable holds the total number of upload chunk that were sent to the source Artifactory instance to process. 19 // Together with this mutex, they control the load on the user plugin and couple it to the local number of threads. 20 totalProcessedUploadChunks int 21 processedUploadChunksMutex sync.Mutex 22 } 23 24 // Checks whether the total number of upload chunks sent is lower than the number of threads, and if so, increments it. 25 // Returns true if the total number was indeed incremented. 26 func (producerConsumerWrapper *producerConsumerWrapper) incProcessedChunksWhenPossible() bool { 27 producerConsumerWrapper.processedUploadChunksMutex.Lock() 28 defer producerConsumerWrapper.processedUploadChunksMutex.Unlock() 29 if producerConsumerWrapper.totalProcessedUploadChunks < GetChunkUploaderThreads() { 30 producerConsumerWrapper.totalProcessedUploadChunks++ 31 return true 32 } 33 return false 34 } 35 36 // Reduces the current total number of upload chunks processed. Called when an upload chunks doesn't require polling for status - 37 // if it's done processing, or an error occurred when sending it. 38 func (producerConsumerWrapper *producerConsumerWrapper) decProcessedChunks() { 39 producerConsumerWrapper.processedUploadChunksMutex.Lock() 40 defer producerConsumerWrapper.processedUploadChunksMutex.Unlock() 41 producerConsumerWrapper.totalProcessedUploadChunks-- 42 }