Skip to content

Conversation

@jimson-msft
Copy link
Contributor

No description provided.

@jimson-msft jimson-msft requested a review from a team as a code owner March 15, 2021 20:38
@jimson-msft
Copy link
Contributor Author

jimson-msft commented Mar 15, 2021

@shishirb-MSFT This is a reupload of the previous pr, unfortunately when we created the snapshot the PR did not get copied over, mind re-reviewing? #Closed

_adminConfigs.Refresh();
}


Copy link
Contributor Author

@jimson-msft jimson-msft Mar 15, 2021

Choose a reason for hiding this comment

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

nit: space #Closed

JsonParser::JsonParser(const std::string& jsonFilePath, bool alwaysCreateFile) :
_jsonFilePath(jsonFilePath)
{
if (!boost::filesystem::exists(_jsonFilePath) && alwaysCreateFile)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 15, 2021

Choose a reason for hiding this comment

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

alwaysCreateFile [](start = 53, length = 16)

Check alwaysCreateFile first (cheaper) in the conditional. Same comment for the force check on line 28. #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's okay but curious why you chose to split into separate if statements rather than combine with &&.


In reply to: 594671740 [](ancestors = 594671740)


void DownloadManager::RefreshConfigs() const
{
_taskThread.SchedBlock([&]()
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 15, 2021

Choose a reason for hiding this comment

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

SchedBlock [](start = 16, length = 10)

No need to block, so use Sched() with 'this' as the tag. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be SchedImmediate() so downloads immediately get the new configs I think


In reply to: 594674119 [](ancestors = 594674119)

{
break;
}
if (_refreshEvent.IsSignaled())
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 15, 2021

Choose a reason for hiding this comment

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

_refreshEvent [](start = 16, length = 13)

Combining the event signaled check with the idle loop means we still have a delay in reading config values.
Instead, accept fnRefreshConfigs in the constructor and store it as a static member and call it from _SignalHandler directly. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some additional refactoring that might make the class more flexible if we need to support other signals, but let me know what you think


In reply to: 594676272 [](ancestors = 594676272)

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 16, 2021

Choose a reason for hiding this comment

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

It's strange to have a callback function go back into the caller to achieve its task. It is more straightforward to have ProcessController itself handle the shutdown in this case.
Moreover, you now have two copies of the lambda to handle SIGINT and SIGTERM.

In general, refactoring early to support a future unknown requirement is not always good because you never know whether the change as it is today will apply to that requirement.


In reply to: 595355095 [](ancestors = 595355095,594676272)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, alright will revert


In reply to: 595415616 [](ancestors = 595415616,595355095,594676272)

DoLogInfo("Received signal %d. Initiating shutdown.", signalNumber);
_shutdownEvent.SetEvent();
}
if (signalNumber == SIGHUP)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 15, 2021

Choose a reason for hiding this comment

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

if [](start = 8, length = 2)

else if #Closed

DownloadStatus GetDownloadStatus(const std::string& downloadId) const;

bool IsIdle() const;
void RefreshConfigs() const;
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 15, 2021

Choose a reason for hiding this comment

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

RefreshConfigs [](start = 9, length = 14)

RefreshAdminConfigs - to be clear and consistent. #Closed

#include <unordered_map>
#include "ban_list.h"

class ConfigManager;
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 15, 2021

Choose a reason for hiding this comment

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

ConfigManager [](start = 6, length = 13)

fwd declaration should be enough here #Closed

using namespace std::chrono_literals; // NOLINT(build/namespaces) how else should we use chrono literals?

class ProcessController
class ProcessController : DONonCopyable
Copy link
Contributor Author

@jimson-msft jimson-msft Mar 16, 2021

Choose a reason for hiding this comment

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

: DONonCopyable [](start = 24, length = 15)

Perhaps there is no need to make this a singleton as there are no non-static members #Resolved

Copy link
Collaborator

Choose a reason for hiding this comment

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

Non-copyable doesn't make it a singleton because you can create multiple instances of this class.


In reply to: 595354139 [](ancestors = 595354139)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, there's a convention for singleton involving static instance of the class itself and a private constructor


In reply to: 595411879 [](ancestors = 595411879,595354139)


void DownloadManager::RefreshAdminConfigs() const
{
_taskThread.SchedImmediate([&]()
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 16, 2021

Choose a reason for hiding this comment

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

& [](start = 32, length = 1)

Capture 'this' instead. The capture-all option is generally discouraged because it will capture more stuff than is needed. There's nothing other than 'this' to capture here but better to get used to that practice. #Closed

else if (signalNumber == SIGHUP)
{
_sighupHandler = std::move(fnHandler);
}
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 16, 2021

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

Depending on how this will change based on my refactoring comment, add an else case here with DO_ASSERT(false). #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think I'll revert the changes and just make the constructor accept the callback for refreshing configs


In reply to: 595419554 [](ancestors = 595419554)

{
public:
ProcessController()
ProcessController(std::function<void()>& fnRefreshConfigs)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 16, 2021

Choose a reason for hiding this comment

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

& [](start = 43, length = 1)

Since you are using std::move, use && here #Closed

DoLogInfo("Started, %s", msdoutil::ComponentVersion().c_str());

ProcessController procController;
std::function<void()> fnRefreshConfigs = [&downloadManager]()
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Mar 16, 2021

Choose a reason for hiding this comment

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

std::function<void()> [](start = 0, length = 25)

Can use auto here but consider writing the lambda inline on line 111. It will also satisfy the && parameter type. #Closed

Copy link
Contributor Author

@jimson-msft jimson-msft Mar 16, 2021

Choose a reason for hiding this comment

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

Right, able to write inline due to parameter type being an rvalue reference with the change to use && above


In reply to: 595575443 [](ancestors = 595575443)

@jimson-msft
Copy link
Contributor Author

jimson-msft commented Mar 16, 2021

Verified this change works on iteration 5.
Modified /etc/deliveryoptimization/admin-config.json to contain:
{
"DOCacheHost": "www.microsoft.com"
}
ran sudo systemctl kill -s SIGHUP deliveryoptimization-agent.service to refresh configs

With do plugin installed, did an apt install of npm and verified through logging that client configs were refreshed, bad mcc host was banned, and download finished succesfully. #Closed

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT left a comment

Choose a reason for hiding this comment

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

:shipit:

@jimson-msft jimson-msft merged commit 713fe55 into main Mar 16, 2021
@jimson-msft jimson-msft deleted the user/jimson/handle_sighup branch March 16, 2021 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants