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

[#175] Client program that spawn other clients #242

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

marcocapozzoli
Copy link
Collaborator

No description provided.

Comment on lines 15 to 22
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>{};
Copy link
Collaborator

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
Copy link
Collaborator

@angeloprobst angeloprobst Feb 3, 2025

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void execute(vector<string>& request);
void execute(const vector<string>& request);


WorkerClientNode::~WorkerClientNode() {}

void WorkerClientNode::execute(vector<string> &request) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void WorkerClientNode::execute(vector<string> &request) {
void WorkerClientNode::execute(const vector<string> &request) {

Comment on lines 54 to 57
cout << no_match << endl;
message.push_back(no_match);
} else {
cout << query_answer_str << endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Collaborator

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.

Suggested change
build-spawner-image:
build-spawner-image: build

@@ -0,0 +1,28 @@
#!/bin/bash -x
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 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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe?

Suggested change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
WorkerMessage(string &worker_id, string &msg);
WorkerMessage(const string &worker_id, const string &msg);

Comment on lines 28 to 31
WorkerMessage::WorkerMessage(string &worker_id, string &msg) {
this->worker_id = worker_id;
this->msg = msg;
}
Copy link
Collaborator

@angeloprobst angeloprobst Feb 3, 2025

Choose a reason for hiding this comment

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

Suggested change
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) {}

Comment on lines 13 to 21
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;
}
Copy link
Collaborator

@angeloprobst angeloprobst Feb 3, 2025

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.

Suggested change
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;
Copy link
Collaborator

@angeloprobst angeloprobst Feb 3, 2025

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.

Suggested change
string node_id;


private:
string node_id;
string das_node_server_id;
Copy link
Collaborator

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?

Comment on lines 34 to 36
vector<string> message;

message.push_back(this->node_id);
Copy link
Collaborator

@angeloprobst angeloprobst Feb 3, 2025

Choose a reason for hiding this comment

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

Suggested change
vector<string> message;
message.push_back(this->node_id);
vector<string> message = {this->node_id()};

Copy link
Contributor

@andre-senna andre-senna left a 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.

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.

3 participants