mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-29 11:10:40 +00:00
db/schema_tables: Fix calculate_schema_digest()
map_reduce() can run the reducer out-of-order which breaks the MD5 hash. Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com> Fixes #357. [tgrabiec]
This commit is contained in:
committed by
Tomasz Grabiec
parent
1a4c8db71a
commit
6cef7d8270
@@ -368,18 +368,24 @@ future<> save_system_keyspace_schema() {
|
||||
return results;
|
||||
});
|
||||
};
|
||||
auto reduce = [] (auto&& hash, auto&& results) {
|
||||
auto reduce = [] (auto& hash, auto&& results) {
|
||||
for (auto&& rs : results) {
|
||||
for (auto&& f : rs.buf().fragments()) {
|
||||
hash->Update(reinterpret_cast<const unsigned char*>(f.begin()), f.size());
|
||||
hash.Update(reinterpret_cast<const unsigned char*>(f.begin()), f.size());
|
||||
}
|
||||
}
|
||||
return std::move(hash);
|
||||
return make_ready_future<>();
|
||||
};
|
||||
return map_reduce(ALL.begin(), ALL.end(), map, std::move(std::make_unique<CryptoPP::Weak::MD5>()), reduce).then([] (auto&& hash) {
|
||||
bytes digest{bytes::initialized_later(), CryptoPP::Weak::MD5::DIGESTSIZE};
|
||||
hash->Final(reinterpret_cast<unsigned char*>(digest.begin()));
|
||||
return utils::UUID_gen::get_name_UUID(digest);
|
||||
return do_with(CryptoPP::Weak::MD5{}, [map, reduce] (auto& hash) {
|
||||
return do_for_each(ALL.begin(), ALL.end(), [&hash, map, reduce] (auto& table) {
|
||||
return map(table).then([&hash, reduce] (auto&& results) {
|
||||
return reduce(hash, results);
|
||||
});
|
||||
}).then([&hash] {
|
||||
bytes digest{bytes::initialized_later(), CryptoPP::Weak::MD5::DIGESTSIZE};
|
||||
hash.Final(reinterpret_cast<unsigned char*>(digest.begin()));
|
||||
return make_ready_future<utils::UUID>(utils::UUID_gen::get_name_UUID(digest));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user