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

bulkio: Support running BACKUP under transaction. #50775

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

miretskiy
Copy link
Contributor

@miretskiy miretskiy commented Jun 29, 2020

Informs #47539

Allow execution of BACKUP statement under explicit transaction,
provided the "DETACHED" option is specified:

BACKUP TO <location_uri> ... WITH DETACHED

When backup runs in detached mode, we do not wait for the job
completion. Instead, we return the job id to the caller, and
the job executes asynchronously.

Release notes (enterprise change): BACKUP can now run in "detached" mode.
That is, we do not wait for the BACKUP job to finish. Instead, the
job ID is returned immediately, and the job itself runs in background.

@miretskiy miretskiy requested review from a team and pbardea and removed request for a team June 29, 2020 19:25
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@pbardea pbardea left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @miretskiy, and @pbardea)


pkg/ccl/backupccl/backup_test.go, line 3473 at r1 (raw file):

}

func waitForSuccessfulJob(t *testing.T, tc *testcluster.TestCluster, id int64) {

By the way, we have something like this in jobsutil.WaitForJob that we use in some of the backup tests as well as import and create stats test.

Could we make that method nudge the registry and re-use it?


pkg/ccl/backupccl/backup_test.go, line 3492 at r1 (raw file):

	db := sqlDB.DB.(*gosql.DB)

	// running backup under transaction requires DETACHED

nit: comment sentence formatting


pkg/ccl/backupccl/backup_test.go, line 3507 at r1 (raw file):

	// Backup again, under explicit transaction.
	tx, err = db.Begin()
	require.NoError(t, err)

Thanks for cleaning these up!


pkg/ccl/backupccl/backup_test.go, line 3511 at r1 (raw file):

	require.NoError(t, err)
	require.NoError(t, tx.Commit())
	waitForSuccessfulJob(t, tc, jobID)

Can we also add a test for rolling back the transaction instead of committing?


pkg/jobs/registry.go, line 383 at r1 (raw file):

// CreateAdoptableJobWithTxn creates a job which will be adopted for execution at a later time
// by some node in a cluster.

nit: s/in a cluster/in the cluster/


pkg/jobs/registry.go, line 388 at r1 (raw file):

) (*Job, error) {
	j := r.NewJob(record)
	if err := j.WithTxn(txn).insert(

I think it's worth adding a comment explicitly mentioning that we purposely create a lease with an invalid node ID so that the registry will adopt it later.


pkg/jobs/registry.go, line 1033 at r1 (raw file):

	}
	nodeStatusMap := map[roachpb.NodeID]*nodeStatus{
		// 0 is not a valid node ID, but we treat it as an always-dead node so that

should we update this comment since it's not clear what 0 is referring to anymore? Something like "We treat invalidNodeID as an ..."

@pbardea
Copy link
Contributor

pbardea commented Jun 30, 2020

Also wanted to flag that it looks like there are a couple of proto generated files included here - probably due to the Go version upgrade.

Also, I don't think "improvement" is a release category. I think the closest category would be "enterprise change".

@miretskiy miretskiy force-pushed the txn_backup branch 3 times, most recently from 39e5fdd to e824f33 Compare July 1, 2020 20:48
@miretskiy miretskiy requested a review from pbardea July 1, 2020 20:48
Copy link
Contributor Author

@miretskiy miretskiy left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @miretskiy, and @pbardea)


pkg/ccl/backupccl/backup_test.go, line 3473 at r1 (raw file):

Previously, pbardea (Paul Bardea) wrote…

By the way, we have something like this in jobsutil.WaitForJob that we use in some of the backup tests as well as import and create stats test.

Could we make that method nudge the registry and re-use it?

I saw that... But, tbh, I wasn't comfortable adding nudge to that utility; and if I'm going to write a wrapper right here (to nudge and call jobsutil.WaitForJob), then I thought that it might actually be more readable if this happened inline, right here. If you feel strongly, I can switch.


pkg/ccl/backupccl/backup_test.go, line 3507 at r1 (raw file):

Previously, pbardea (Paul Bardea) wrote…

Thanks for cleaning these up!

Done.


pkg/jobs/registry.go, line 388 at r1 (raw file):

Previously, pbardea (Paul Bardea) wrote…

I think it's worth adding a comment explicitly mentioning that we purposely create a lease with an invalid node ID so that the registry will adopt it later.

Done.


pkg/jobs/registry.go, line 1033 at r1 (raw file):

Previously, pbardea (Paul Bardea) wrote…

should we update this comment since it's not clear what 0 is referring to anymore? Something like "We treat invalidNodeID as an ..."

Done.

Copy link
Contributor Author

@miretskiy miretskiy left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt and @pbardea)


pkg/ccl/backupccl/backup_test.go, line 3511 at r1 (raw file):

Previously, pbardea (Paul Bardea) wrote…

Can we also add a test for rolling back the transaction instead of committing?

Done.

@miretskiy miretskiy force-pushed the txn_backup branch 2 times, most recently from a75615a to f9502d0 Compare July 1, 2020 23:18
@miretskiy
Copy link
Contributor Author

@pbardea @dt ready for another look;

pkg/jobs/registry.go Outdated Show resolved Hide resolved
pkg/ccl/utilccl/jobutils.go Outdated Show resolved Hide resolved
@miretskiy
Copy link
Contributor Author

bors r+

@miretskiy
Copy link
Contributor Author

bors r-

@craig
Copy link
Contributor

craig bot commented Jul 2, 2020

Canceled

Allow execution of BACKUP statement under explicit transaction,
provided the "DETACHED" option is specified:

```
BACKUP TO <location_uri> ... WITH DETACHED
```

When backup runs in `detached` mode, we do not wait for the job
completion.  Instead, we return the job id to the caller, and
the job executes asynchronously.

Release notes (enterprise change): BACKUP can now run in "detached" mode.
That is, we do not wait for the BACKUP job to finish.  Instead, the
job ID is returned immediately, and the job itself runs in background.
@miretskiy
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 2, 2020

Build failed

@miretskiy
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 2, 2020

Build failed (retrying...)

@miretskiy
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 2, 2020

Already running a review

@craig
Copy link
Contributor

craig bot commented Jul 2, 2020

Build succeeded

@craig craig bot merged commit 1b6f9d0 into cockroachdb:master Jul 2, 2020
@dt
Copy link
Member

dt commented Jul 3, 2020

closes #47539?

@miretskiy
Copy link
Contributor Author

Closes #47539

@miretskiy
Copy link
Contributor Author

miretskiy commented Jul 3, 2020 via email

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.

4 participants