Skip to content

Commit c1618e8

Browse files
committed
Parallelize dir-sync on graceful shutdowns
This will make normal ATS shutdowns come down quicker, specially on boxes with a lot of drives. This is similar to the new parallel sync options under normal operations, except this will always Parallelize as much as needed.
1 parent 6dfaadd commit c1618e8

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

src/iocore/cache/CacheDir.cc

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "ts/ats_probe.h"
3434
#include "iocore/eventsystem/Tasks.h"
3535

36+
#include <thread>
3637
#include <unordered_map>
3738

3839
#ifdef LOOP_CHECK_MODE
@@ -958,20 +959,42 @@ Directory::entries_used()
958959
}
959960

960961
/*
961-
* this function flushes the cache meta data to disk when
962+
* This function flushes the cache meta data to disk when
962963
* the cache is shutdown. Must *NOT* be used during regular
963-
* operation.
964+
* operation. Stripes are synced in parallel, one thread per
965+
* physical disk.
964966
*/
965967

966968
void
967969
sync_cache_dir_on_shutdown()
968970
{
969-
Dbg(dbg_ctl_cache_dir_sync, "sync started");
970-
EThread *t = reinterpret_cast<EThread *>(0xdeadbeef);
971+
Dbg(dbg_ctl_cache_dir_sync, "shutdown sync started");
972+
973+
std::unordered_map<CacheDisk *, std::vector<int>> drive_stripe_map;
974+
971975
for (int i = 0; i < gnstripes; i++) {
972-
gstripes[i]->shutdown(t);
976+
drive_stripe_map[gstripes[i]->disk].push_back(i);
973977
}
974-
Dbg(dbg_ctl_cache_dir_sync, "sync done");
978+
979+
std::vector<std::thread> threads;
980+
981+
threads.reserve(drive_stripe_map.size());
982+
for (auto &[disk, indices] : drive_stripe_map) {
983+
Dbg(dbg_ctl_cache_dir_sync, "Disk %s: syncing %zu stripe(s)", disk->path, indices.size());
984+
threads.emplace_back([&indices]() {
985+
EThread *t = reinterpret_cast<EThread *>(0xdeadbeef);
986+
987+
for (int idx : indices) {
988+
gstripes[idx]->shutdown(t);
989+
}
990+
});
991+
}
992+
993+
for (auto &thr : threads) {
994+
thr.join();
995+
}
996+
997+
Dbg(dbg_ctl_cache_dir_sync, "shutdown sync done");
975998
}
976999

9771000
int

0 commit comments

Comments
 (0)