From d377defa313e13f2bf1a992be93dac883b9122aa Mon Sep 17 00:00:00 2001 From: benthompson15 Date: Thu, 21 Nov 2019 15:14:58 -0600 Subject: [PATCH] MCOL-3577: update syncNow with prefix to behave like syncNow no prefix. This should be corrected eventually but is safer now as previous implementation would possibly result in deadlock. --- storage-manager/src/Synchronizer.cpp | 31 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/storage-manager/src/Synchronizer.cpp b/storage-manager/src/Synchronizer.cpp index 5425b60ed..7e86f8e2d 100644 --- a/storage-manager/src/Synchronizer.cpp +++ b/storage-manager/src/Synchronizer.cpp @@ -299,22 +299,23 @@ void Synchronizer::periodicSync() void Synchronizer::syncNow(const bf::path &prefix) { boost::unique_lock lock(mutex); - - // this is pretty hacky. when time permits, implement something better. - // - // Issue all of the pendingOps for the given prefix - // recreate the threadpool (dtor returns once all jobs have finished) - // resume normal operation - + + // This should ensure that all pendingOps have been added as jobs + // and waits for them to complete. until pendingOps is empty. + // this should be redone to only remove items of given prefix eventually + blockNewJobs = true; - for (auto &job : pendingOps) - if (job.first.find(prefix.string()) == 0) + while (pendingOps.size() != 0 && opsInProgress.size() != 0) + { + for (auto &job : pendingOps) makeJob(job.first); - uncommittedJournalSize[prefix] = 0; - lock.unlock(); - threadPool.reset(new ThreadPool()); - threadPool->setMaxThreads(maxUploads); - lock.lock(); + for (auto it = uncommittedJournalSize.begin(); it != uncommittedJournalSize.end(); ++it) + it->second = 0; + lock.unlock(); + while (opsInProgress.size() > 0) + boost::this_thread::sleep_for(boost::chrono::seconds(1)); + lock.lock(); + } blockNewJobs = false; } @@ -328,7 +329,7 @@ void Synchronizer::syncNow() // Leaving S3 storage and local metadata directories sync'd for snapshot backups. blockNewJobs = true; - while (pendingOps.size() != 0) + while (pendingOps.size() != 0 && opsInProgress.size() != 0) { for (auto &job : pendingOps) makeJob(job.first);