Skip to content

Commit a4eaaff

Browse files
committed
GEDS: Fix Object relocation.
1 parent 823af2d commit a4eaaff

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

src/libgeds/GEDS.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -865,45 +865,34 @@ void GEDS::relocate(std::vector<std::shared_ptr<GEDSFileHandle>> &relocatable, b
865865
struct RelocateHelper {
866866
std::mutex mutex;
867867
std::condition_variable cv;
868-
size_t nTasks;
869-
auto lock() { return std::unique_lock<std::mutex>(mutex); }
868+
std::atomic<size_t> nTasks;
870869
};
871870
auto h = std::make_shared<RelocateHelper>();
872871
{
873-
auto lock = h->lock();
872+
std::lock_guard lock(h->mutex);
874873
h->nTasks = relocatable.size();
875874
}
876875

877876
LOG_INFO("Relocating ", relocatable.size(), " objects.");
878877

879878
auto self = shared_from_this();
880-
size_t off = 3 * _config.io_thread_pool_size;
881-
882-
for (size_t offset = 0; offset < relocatable.size(); offset += off) {
883-
auto rbegin = offset;
884-
auto rend = rbegin + off;
885-
if (rend > relocatable.size()) {
886-
rend = relocatable.size();
887-
}
888-
for (auto i = rbegin; i < rend; i++) {
889-
auto fh = relocatable[i];
890-
boost::asio::post(_ioThreadPool, [self, fh, h, force]() {
891-
try {
892-
self->relocate(fh, force);
893-
} catch (...) {
894-
LOG_ERROR("Encountered an exception during relocation ", fh->identifier);
895-
}
896-
{
897-
auto lock = h->lock();
898-
h->nTasks -= 1;
899-
}
900-
h->cv.notify_all();
901-
});
902-
}
903-
auto relocateLock = h->lock();
904-
h->cv.wait(relocateLock, [h]() { return h->nTasks == 0; });
905-
LOG_INFO("Relocated ", relocatable.size(), " objects.");
879+
for (auto fh : relocatable) {
880+
boost::asio::post(_ioThreadPool, [self, fh, h, force]() {
881+
try {
882+
self->relocate(fh, force);
883+
} catch (...) {
884+
LOG_ERROR("Encountered an exception during relocation ", fh->identifier);
885+
}
886+
{
887+
std::lock_guard lock(h->mutex);
888+
h->nTasks -= 1;
889+
}
890+
h->cv.notify_one();
891+
});
906892
}
893+
std::unique_lock lock(h->mutex);
894+
h->cv.wait(lock, [h]() { return h->nTasks == 0; });
895+
LOG_INFO("Relocated ", relocatable.size(), " objects.");
907896
}
908897

909898
void GEDS::relocate(std::shared_ptr<GEDSFileHandle> handle, bool force) {

src/libgeds/GEDSAbstractFileHandle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ template <class T> class GEDSAbstractFileHandle : public GEDSFileHandle {
174174
if (!isValid()) {
175175
return absl::UnavailableError("The file " + identifier + " is no longer valid!");
176176
}
177-
LOG_INFO("Relocating ", identifier);
177+
LOG_INFO("Relocating ", identifier, " (size: ", _file.size(), ") ");
178178
if (_openCount > 0) {
179179
auto message = "Unable to relocate " + identifier + " reason: The file is still in use.";
180180
LOG_ERROR(message);

0 commit comments

Comments
 (0)