Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep track of version ids for outdated measures and components #5127

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/utilities/bcl/RemoteBCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ std::vector<BCLSearchResult> RemoteBCL::searchMeasureLibrary(const std::string&

int RemoteBCL::checkForComponentUpdates() {
m_componentsWithUpdates.clear();
m_outdatedComponentVersionIdMap.clear();

for (const BCLComponent& component : LocalBCL::instance().components()) {
// can't start another request until last one is done
Expand Down Expand Up @@ -229,6 +230,7 @@ int RemoteBCL::checkForComponentUpdates() {
std::vector<BCLSearchResult> result = waitForSearch();
if (!result.empty() && result[0].versionId() != component.versionId()) {
m_componentsWithUpdates.push_back(result[0]);
m_outdatedComponentVersionIdMap[component.uid()].push_back(component.versionId());
}
}

Expand All @@ -237,6 +239,7 @@ int RemoteBCL::checkForComponentUpdates() {

int RemoteBCL::checkForMeasureUpdates() {
m_measuresWithUpdates.clear();
m_outdatedMeasureVersionIdMap.clear();

for (const BCLMeasure& measure : LocalBCL::instance().measures()) {
// can't start another request until last one is done
Expand Down Expand Up @@ -270,6 +273,7 @@ int RemoteBCL::checkForMeasureUpdates() {
std::vector<BCLSearchResult> result = waitForSearch();
if (!result.empty() && result[0].versionId() != measure.versionId()) {
m_measuresWithUpdates.push_back(result[0]);
m_outdatedMeasureVersionIdMap[measure.uid()].push_back(measure.versionId());
}
}

Expand All @@ -290,13 +294,19 @@ void RemoteBCL::updateComponents() {
}

for (const BCLSearchResult& component : m_componentsWithUpdates) {
downloadMeasure(component.uid());
downloadComponent(component.uid());
boost::optional<BCLComponent> newComponent = waitForComponentDownload();

if (newComponent) {
boost::optional<BCLComponent> oldComponent = LocalBCL::instance().getComponent(newComponent->uid());
if (oldComponent && oldComponent->versionId() != newComponent->versionId()) {
LocalBCL::instance().removeComponent(*oldComponent);
// delete outdated versions of this component
auto it = m_outdatedComponentVersionIdMap.find(component.uid());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If desired, could just loop over all components here looking for the same uid and different version ids, that would save the need for the new member variables

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer that. I've used a different implementation in #5129, can you review that please?

if (it != m_outdatedComponentVersionIdMap.end()) {
for (const auto& outdatedComponentVersionId : it->second) {
boost::optional<BCLComponent> oldComponent = LocalBCL::instance().getComponent(component.uid(), outdatedComponentVersionId);
if (oldComponent) {
LocalBCL::instance().removeComponent(*oldComponent);
}
}
}
}
}
Expand All @@ -312,11 +322,17 @@ void RemoteBCL::updateMeasures() {
boost::optional<BCLMeasure> newMeasure = waitForMeasureDownload();

if (newMeasure) {
boost::optional<BCLMeasure> oldMeasure = LocalBCL::instance().getMeasure(newMeasure->uid());
if (oldMeasure && oldMeasure->versionId() != newMeasure->versionId()) {
LocalBCL::instance().removeMeasure(*oldMeasure);
// delete outdated versions of this measure
auto it = m_outdatedMeasureVersionIdMap.find(measure.uid());
if (it != m_outdatedMeasureVersionIdMap.end()) {
for (const auto& outdatedMeasureVersionId : it->second) {
boost::optional<BCLMeasure> oldMeasure = LocalBCL::instance().getMeasure(measure.uid(), outdatedMeasureVersionId);
if (oldMeasure) {
LocalBCL::instance().removeMeasure(*oldMeasure);
}
}
}
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/utilities/bcl/RemoteBCL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ class UTILITIES_API RemoteBCL : public BCL
bool validDevAuthKey;

std::vector<BCLSearchResult> m_componentsWithUpdates;
std::map<std::string, std::vector<std::string>> m_outdatedComponentVersionIdMap;

std::vector<BCLSearchResult> m_measuresWithUpdates;
std::map<std::string, std::vector<std::string>> m_outdatedMeasureVersionIdMap;

unsigned m_timeOutSeconds;
};
Expand Down