Skip to content

Commit

Permalink
Add table name as secondary key, because each table manage each synch…
Browse files Browse the repository at this point in the history
…ronizations
  • Loading branch information
Dwordcito committed Oct 6, 2023
1 parent c67501d commit 0581eae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/shared_modules/rsync/src/rsyncImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void RSyncImplementation::startRSync(const RSYNC_HANDLE handle,
checksumCtx.rightCtx.type = IntegrityMsgType::INTEGRITY_CLEAR;
}

m_synchronizationController.start(handle, checksumCtx.rightCtx.id);
m_synchronizationController.start(handle, jsStartParamsTable, checksumCtx.rightCtx.id);
// rightCtx will have the final checksum based on fillChecksum method. After processing all checksum select data
// checksumCtx.rightCtx will have the needed (final) information
messageCreator->send(callbackWrapper, startConfiguration, checksumCtx.rightCtx);
Expand Down Expand Up @@ -160,7 +160,7 @@ void RSyncImplementation::registerSyncId(const RSYNC_HANDLE handle,
{
try
{
m_synchronizationController.checkId(handle, syncData.id);
m_synchronizationController.checkId(handle, syncConfiguration.at("table"), syncData.id);

if (0 == syncData.command.compare("checksum_fail"))
{
Expand Down
29 changes: 17 additions & 12 deletions src/shared_modules/rsync/src/synchronizationController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace RSync
class SynchronizationController final
{
public:
void start(const RSYNC_HANDLE key, const int32_t value)
void start(const RSYNC_HANDLE key, const std::string& table, const int32_t value)
{
std::lock_guard<std::mutex> lock{ m_mutex };
m_data[key] = value;
m_data[key][table] = value;
}

void stop(const RSYNC_HANDLE key)
Expand All @@ -45,7 +45,7 @@ namespace RSync
m_data.clear();
}

void checkId(const RSYNC_HANDLE key, const int32_t value)
void checkId(const RSYNC_HANDLE key, const std::string& table, const int32_t value)
{
std::lock_guard<std::mutex> lock{ m_mutex };
const auto it = m_data.find(key);
Expand All @@ -55,21 +55,26 @@ namespace RSync
}
else
{
if (value < it->second)
{
it->second = value;
}
const auto itTable = it->second.find(table);

if (value > it->second)
if (itTable != it->second.end())
{
Log::debugVerbose << "Sync id: " << std::to_string(value) << " is not the current id: "
<< std::to_string(it->second) << LogEndl;
throw std::runtime_error { "Sync id is not the current id" };
if (value < itTable->second)
{
itTable->second = value;
}

if (value > itTable->second)
{
Log::debugVerbose << "Sync id: " << std::to_string(value) << " is not the current id: "
<< std::to_string(itTable->second) << " for table: "<< table << LogEndl;
throw std::runtime_error { "Sync id is not the current id" };
}
}
}
}
private:
std::unordered_map<RSYNC_HANDLE, int32_t> m_data;
std::unordered_map<RSYNC_HANDLE, std::unordered_map<std::string, int32_t>> m_data;
std::mutex m_mutex;
};
} // namespace RSync
Expand Down

0 comments on commit 0581eae

Please sign in to comment.