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

Adds SHUTDOWN command as alternate option to sending SIGINT #331

Merged
merged 9 commits into from
Feb 27, 2023

Conversation

zainkabani
Copy link
Contributor

@zainkabani zainkabani commented Feb 24, 2023

A recent change to ECS has made it so we can no longer send signals to our container during ECS draining phase, an alternate option suggested by @dat2 was to add a SHUTDOWN command as an alternative to initiate the drain process.

This PR adds this admin command, which sends a SIGINT to the process

src/admin.rs Outdated
@@ -67,6 +72,11 @@ where
trace!("RESUME");
resume(stream, query_parts[1]).await
}
"SHUTDOWN" => {
trace!("SHUTDOWN");
is_shutdown = true;
Copy link
Collaborator

@levkk levkk Feb 24, 2023

Choose a reason for hiding this comment

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

Why don't you just send TERM signal to itself here?

let pid = std::process::id;
signal::kill(pid, Signal::TERM);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, I originally thought doing this would pick up the PID of the worker thread but it seems to get the main thread PID.

I've updated the implementation to use that instead, thanks!

@zainkabani zainkabani marked this pull request as ready for review February 25, 2023 22:52
src/admin.rs Outdated Show resolved Hide resolved
src/admin.rs Outdated Show resolved Hide resolved

res.put(data_row(&vec![shutdown_success.to_string()]));

res.put(command_complete("SHUTDOWN"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typically this would return a SELECT 1, otherwise clients could get confused? Not entirely sure. If you're returning rows, you want to double check that you're using the right protocol syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently all of our other custom protocol commands which return rows follow this pattern, I can change this to a select 1 but it would be different from the rest of our commands

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're absolutely right. Disregard my comment.

src/main.rs Outdated Show resolved Hide resolved
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you fix indentation here or something else as well? I can't tell from the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was all just formatting, it was indented incorrectly

cur.execute("SELECT 1;")

# Send SHUTDOWN command pgcat while still in transaction
admin_cur.execute("SHUTDOWN")
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 where you want to check if your protocol implementation works by reading the result.

@zainkabani zainkabani changed the title Adds SHUTDOWN command to PgCat as alternate option to sending SIGINT Adds SHUTDOWN command as alternate option to sending SIGINT Feb 27, 2023
Copy link
Collaborator

@levkk levkk left a comment

Choose a reason for hiding this comment

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

LGTM!

@levkk levkk merged commit eb8cfdb into postgresml:main Feb 27, 2023
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.

None yet

2 participants