-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
sql,jobs,ccl: add ability to specify a REASON string with PAUSE JOB #68909
Conversation
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.
Changes in jobs package look good to me.
Reviewable status:
complete! 0 of 0 LGTMs obtained
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.
You've got some build issues. Otherwise, change looks good to me mod the call for the defensive check.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @rhu713)
pkg/jobs/jobs_test.go, line 3181 at r3 (raw file):
Quoted 8 lines of code…
var payloadBytes []byte var payload jobspb.Payload var status string tdb.QueryRow(t, fmt.Sprintf("SELECT status, payload FROM system.jobs where id = %d", jobID)).Scan( &status, &payloadBytes) require.Equal(t, "paused", status) require.NoError(t, protoutil.Unmarshal(payloadBytes, &payload)) require.Equal(t, "for testing", payload.PauseReason)
nit: make yourself some closures for this. Also pass the ID as a parameter to the query:
getStatusAndPayload := func(t *testing.T, id jobspb.ID) (status string, payload jobspb.Payload) {
var payloadBytes []byte
tdb.QueryRow(
t, "SELECT status, payload FROM system.jobs where id = $1", jobID,
).Scan(&status, &payloadBytes)
require.NoError(t, protoutil.Unmarshal(payloadBytes, &payload))
return status, payload
}
checkStatusAndPauseReason := func(t *testing.T, id jobspb.ID, expStatus, expPauseReason string). {
status, payload := getStatusAndPayload(t, id)
require.Equal(t, expStatus, status, "status")
require.Equal(t, expPauseReason, payload.PauseReason, "pause reason")
}
Then these will look like:
{
// Next, pause the job with a reason. Wait for pause and make sure the pause reason is set.
require.NoError(t, registry.PauseRequested(ctx, nil, jobID, "for testing"))
tdb.CheckQueryResultsRetry(t, q, [][]string{{"paused"}})
checkStatusAndPauseReason("paused", "for testing")
}
pkg/jobs/jobs_test.go, line 3197 at r3 (raw file):
require.NoError(t, protoutil.Unmarshal(payloadBytes, &payload)) require.Equal(t, "for testing", payload.PauseReason) fmt.Println(payload)
remove
pkg/sql/control_jobs.go, line 65 at r3 (raw file):
} }
How do you feel about adding an assertion that reason is empty unless the desiredStatus is paused? I know the grammar doesn't allow it but we've been hurt in the past when we change the grammar and then don't realize that assumptions have been violated.
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.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @dt)
pkg/jobs/jobs_test.go, line 3181 at r3 (raw file):
Previously, ajwerner wrote…
var payloadBytes []byte var payload jobspb.Payload var status string tdb.QueryRow(t, fmt.Sprintf("SELECT status, payload FROM system.jobs where id = %d", jobID)).Scan( &status, &payloadBytes) require.Equal(t, "paused", status) require.NoError(t, protoutil.Unmarshal(payloadBytes, &payload)) require.Equal(t, "for testing", payload.PauseReason)
nit: make yourself some closures for this. Also pass the ID as a parameter to the query:
getStatusAndPayload := func(t *testing.T, id jobspb.ID) (status string, payload jobspb.Payload) { var payloadBytes []byte tdb.QueryRow( t, "SELECT status, payload FROM system.jobs where id = $1", jobID, ).Scan(&status, &payloadBytes) require.NoError(t, protoutil.Unmarshal(payloadBytes, &payload)) return status, payload } checkStatusAndPauseReason := func(t *testing.T, id jobspb.ID, expStatus, expPauseReason string). { status, payload := getStatusAndPayload(t, id) require.Equal(t, expStatus, status, "status") require.Equal(t, expPauseReason, payload.PauseReason, "pause reason") }Then these will look like:
{ // Next, pause the job with a reason. Wait for pause and make sure the pause reason is set. require.NoError(t, registry.PauseRequested(ctx, nil, jobID, "for testing")) tdb.CheckQueryResultsRetry(t, q, [][]string{{"paused"}}) checkStatusAndPauseReason("paused", "for testing") }
Done, thanks!
pkg/jobs/jobs_test.go, line 3197 at r3 (raw file):
Previously, ajwerner wrote…
remove
Done
pkg/sql/control_jobs.go, line 65 at r3 (raw file):
Previously, ajwerner wrote…
How do you feel about adding an assertion that reason is empty unless the desiredStatus is paused? I know the grammar doesn't allow it but we've been hurt in the past when we change the grammar and then don't realize that assumptions have been violated.
Okay, added this this defensive check. Let me know what you think.
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.
Reviewed 1 of 15 files at r8, 2 of 6 files at r9.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @dt)
0debb91
to
b73dc9d
Compare
1c59bf0
to
fc9bb9e
Compare
Currently there's not a way to attach a user-specified reason message to a PAUSE JOB command. The reason message is useful to gain visibility into why a job was paused by a user or by the job itself. To address this, an optional WITH REASON = <reason> was added to PAUSE JOB(s) so that a reason can be attached to any PAUSE statement. This commit only adds the WITH REASON syntax to the SQL grammar, without any implementation. Release note (enterprise change): Adds WITH REASON = <reason> to PAUSE JOB statement to gain visibility into why a job was paused. This commit only adds the syntax to the grammar with no implementation.
Previously a WITH REASON clause was added to the PAUSE JOB command to allow a reason string to be attached to a pause command. This change allows for this string to be propagated all the way into the hander for pause requests in the jobs code. Release note: None
Previously a WITH REASON clause was added to the PAUSE JOB command to allow a reason string to be attached to a pause command. This change persists this pause reason string into the payload of the job every time a pause is requested. Release note (enterprise change): Adds WITH REASON = <reason> to PAUSE JOB statement to gain visibility into why a job was paused by allowing pauses to be attached to a reason string. This reason is then persisted in the payload of the job and can be queried later.
bors r+ |
Build succeeded: |
@@ -6060,11 +6060,25 @@ pause_jobs_stmt: | |||
Command: tree.PauseJob, | |||
} | |||
} | |||
| PAUSE JOB a_expr WITH REASON '=' string_or_placeholder |
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.
Sorry for the late comment, but I'm curious what the motivation was to include the =
token? Was PAUSE JOB a_expr WITH REASON string_or_placeholder
an ambiguous syntax?
Add ability to specify a REASON string with PAUSE JOB, persist this string in the job's payload. See individual commits.