-
Notifications
You must be signed in to change notification settings - Fork 2
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
[#175] Client program that spawn other clients #242
base: master
Are you sure you want to change the base?
Conversation
shared_ptr<Message> message = StarNode::message_factory(command, args); | ||
if (message) { | ||
return message; | ||
} | ||
if (command == WORKER_NOTIFICATION) { | ||
return shared_ptr<Message>(new WorkerMessage(args[0], args[1])); | ||
} | ||
return shared_ptr<Message>{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a change request, it's more like a tip.
The following code does the same, but it's a bit simpler and complies to the Modern C++ style recommendations.
auto message = StarNode::message_factory(command, args); // <== here
if (message) {
return message;
}
if (command == WORKER_NOTIFICATION) {
return make_shared<WorkerMessage>(args[0], args[1]); // <== here
}
return nullptr; // <== here
|
||
#include "StarNode.h" | ||
|
||
#define DEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard-coded but DEBUG
is supposed to be set only while running the build process by the building tool, in our case, Bazel
. By default, Bazel
does not set -DNDEBUG
(see here), which means that DEBUG
is always enabled unless we instruct Bazel
to not doing it.
The way we are currently running the build process does not allow us to pass options to Bazel
, but, once we consider our services stable and ready for production, the build process will be adjusted in order to allow non-debug builds.
In short, you can, and should, remove this #define DEBUG
.
|
||
~WorkerClientNode(); | ||
|
||
void execute(vector<string>& request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void execute(vector<string>& request); | |
void execute(const vector<string>& request); |
|
||
WorkerClientNode::~WorkerClientNode() {} | ||
|
||
void WorkerClientNode::execute(vector<string> &request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void WorkerClientNode::execute(vector<string> &request) { | |
void WorkerClientNode::execute(const vector<string> &request) { |
cout << no_match << endl; | ||
message.push_back(no_match); | ||
} else { | ||
cout << query_answer_str << endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cout << no_match << endl; | |
message.push_back(no_match); | |
} else { | |
cout << query_answer_str << endl; | |
#ifdef DEBUG | |
cout << no_match << endl; | |
#endif | |
message.push_back(no_match); | |
} else { | |
#ifdef DEBUG | |
cout << query_answer_str << endl; | |
#endif |
Makefile
Outdated
@@ -28,6 +28,9 @@ github-runner: | |||
build-image: | |||
cd src && bash -x scripts/docker_image_build.sh | |||
|
|||
build-spawner-image: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on src/scripts/docker_image_spawner_build.sh
file.
build-spawner-image: | |
build-spawner-image: build |
@@ -0,0 +1,28 @@ | |||
#!/bin/bash -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the dependencies in this script should be replaced by dependencies of a target in the Makefile
.
I mean, as the building image (L9) and the build process (L16) already have target entries in the Makefile
, this script should only run the docker buildx ...
command (L28) for the spawner and have its own Makefile
target entry with its deps set accordingly.
|
||
~SentinelServerNode(); | ||
|
||
void storage_message(string &worker_id, string &message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?
void storage_message(string &worker_id, string &message); | |
void storage_message(const string &worker_id, const string &message); |
Please set them const
if the strings are not supposed to be changed inside the function.
public: | ||
string worker_id; | ||
string msg; | ||
WorkerMessage(string &worker_id, string &msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WorkerMessage(string &worker_id, string &msg); | |
WorkerMessage(const string &worker_id, const string &msg); |
WorkerMessage::WorkerMessage(string &worker_id, string &msg) { | ||
this->worker_id = worker_id; | ||
this->msg = msg; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WorkerMessage::WorkerMessage(string &worker_id, string &msg) { | |
this->worker_id = worker_id; | |
this->msg = msg; | |
} | |
WorkerMessage::WorkerMessage(const string &worker_id, const string &msg) | |
: worker_id(worker_id), msg(msg) {} |
WorkerClientNode::WorkerClientNode( | ||
const string &node_id, | ||
const string &server_id, | ||
const string &das_node_server_id | ||
) : StarNode(node_id, server_id) { | ||
this->node_id = node_id; | ||
this->server_id = server_id; | ||
this->das_node_server_id = das_node_server_id; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StarNode
is already storing server_id
(attr has the same name), and DistributedAlgorithmNode
(parent of StarNode
) is also storing node_id
as my_node_id
(private) but accessible via node_id()
function.
WorkerClientNode::WorkerClientNode( | |
const string &node_id, | |
const string &server_id, | |
const string &das_node_server_id | |
) : StarNode(node_id, server_id) { | |
this->node_id = node_id; | |
this->server_id = server_id; | |
this->das_node_server_id = das_node_server_id; | |
} | |
WorkerClientNode::WorkerClientNode( | |
const string &node_id, const string &server_id, const string &das_node_server_id | |
) : das_node_server_id(das_node_server_id), StarNode(node_id, server_id) {} |
void execute(vector<string>& request); | ||
|
||
private: | ||
string node_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already defined in DistributedAlgorithNode
as my_node_id
(private) but accessible via node_id()
function - it can removed here.
string node_id; |
|
||
private: | ||
string node_id; | ||
string das_node_server_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this any different from server_id
defined in StarNode
?
vector<string> message; | ||
|
||
message.push_back(this->node_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector<string> message; | |
message.push_back(this->node_id); | |
vector<string> message = {this->node_id()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't revise C++ style as @angeloprobst and @eddiebrissow are more reliable in this regard.
But There's a design flaw in this approach which I don't think can be fixed in this PR. This flaw is not your fault, actually it's mine. The way I was envisioning the algorithm execution is not actually well coupled with our architecture. I'm already working on this.
Regarding this PR, my suggestion is to fix it as the other revisor(s) suggested but keep it UNMERGED. You will probably need pieces of this code later on.
No description provided.