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

reload RPC server manifest on SIGHUP (#1684) #1699

Merged
merged 3 commits into from
Aug 27, 2019

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Aug 26, 2019

Fixes #1684

  • Adds a builtin status RPC command to the rpc server, and adds a SIGHUP handler to the rpc server that reloads the manifest. There is some complicated behavior around signals, locks, threads, and processes thanks to the complicated intersection of locks, signals, and Thread.join() in python and posix.
  • status returns: pid, status, timestamp, and optionally error (if the status is error). The timestamp field is the time the last status change occurred.
  • While the status is 'compliling', dbt rpc will only serve builtin requests - it won't even known about non-builtins (so compile/run/compile_project/... won't work).
    • The idea for a lot of this behavior is that if you were to kick off a long-running run_project and then reload the manifest, you'd be able to kill and control the initial process while the manifest was loading and even after it.
  • Windows supports status for completeness, but not SIGHUP.

While I was in here I fixed up some hologram/mypy stuff (mostly pattern-related things and the deprecations module), so this depends on hologram 0.0.2 now.

Jacob Beck added 2 commits August 26, 2019 09:53
Requires git-only hologram branch
TODO: update hologram version + do another release
From the sighup until completion, the sever enters an error state where only builtin commands work
 - management of tasks should keep functioning properly
Add new builtin command 'status'
 - returns 'pid', 'status' enum, 'timestamp'
 - if the status is 'error', an 'error' field is populated
    - just a Dict[str, Any] with, only 'message' for now
@cla-bot cla-bot bot added the cla:yes label Aug 26, 2019
@beckjake beckjake marked this pull request as ready for review August 26, 2019 16:27
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

This is really slick @beckjake! I gave it a spin locally and have a couple of questions (noted inline) and one piece of feedback: If a compilation error occurs, then the rpc server gets into a state where the non-builtin endpoints aren't loaded. The same thing occurs while the manifest is recompiling: it's ok for dbt to not response to requests while this re-compilation is happening, but the response should probably be different.

A query to /run, for instance, results in:

request={'jsonrpc': '2.0', 'method': 'run', 'id': 1, 'params': {'timeout': None, 'sql': 'c2VsZWN0IDEgYXMgaWQ=', 'name': 'foo'}}
{'error': {'code': -32601, 'message': 'Method not found'}, 'id': 1, 'jsonrpc': '2.0'}

Can we instead surface a more semantically meaningful error indicating that there is an error with the project?


@contextmanager
def signhup_replace():
"""Å context manager. Replace the current sighup handler with SIG_IGN on
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this an angstrom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because that's what option + A does on a mac, and I guess I hit option while typing this!


# current_handler should be the handler unless we're already loading a
# new manifest. So if the current handler is the ignore, there was a
# double-hup! We should exit and not touch the signal handler, to make
Copy link
Contributor

Choose a reason for hiding this comment

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

How would a double-hup happen? And why would the response be to exit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The how is easy: send a lot of sighups to the same process at the same time

For the why... I have no idea, which is why I used SIG_IGN instead of SIG_DFL.

@@ -2,8 +2,8 @@
import multiprocessing
import os
import random
import signal
Copy link
Contributor

Choose a reason for hiding this comment

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

these tests are great, but can we move them out of 042_sources_test? I didn't realize these existed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's probably been a long time coming - they just rely on the same base project as the sources tests and I was too lazy to duplicate them all.

@drewbanin
Copy link
Contributor

todo:

  • error message for failure to compile
  • error message for compilation in-progress (use status endpoint)
  • start serving before manifest is loaded

Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

This last round of updates is perfect - ship it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants