sql/tenant: synch clear range data on tenant drop request#55935
sql/tenant: synch clear range data on tenant drop request#55935craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
9673e32 to
edb51f2
Compare
2383bfa to
f0e42e4
Compare
f0e42e4 to
497018f
Compare
497018f to
cc3027a
Compare
ajwerner
left a comment
There was a problem hiding this comment.
Is this what we want or do we want to have a separate function from destroy tenant to actually do the gc and row removal? That function should validate the state of the tenant row. My feeling is the latter because it will more closely mimic behavior of an async job. Will give us flexibility to remove tenants later and to deal with already dropped tenants which have not yet been GC'd.
Reviewed 1 of 7 files at r1.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, @spaskob, and @tbg)
pkg/ccl/backupccl/backup_test.go, line 5864 at r1 (raw file):
restoreDB.Exec(t, `SELECT crdb_internal.destroy_tenant(10)`) restoreDB.CheckQueryResults(t, `select * from system.tenants`, [][]string{})
Can you use the kv.DB to scan the entire tenant prefix and ensure that it is empty?
cc3027a to
88296b6
Compare
spaskob
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, and @tbg)
pkg/ccl/backupccl/backup_test.go, line 5864 at r1 (raw file):
Previously, ajwerner wrote…
Can you use the kv.DB to scan the entire tenant prefix and ensure that it is empty?
Done.
spaskob
left a comment
There was a problem hiding this comment.
PTAL
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, and @tbg)
88296b6 to
4a1ce62
Compare
Discussed offline - the functions for these are separated, if there's a need it will be trivial to define a new builtin to just GC the tenant. |
|
oh, whoops, looks like it dropped my other comment because it was submitted after an update but it said:
|
3ba44fc to
2bda1fb
Compare
spaskob
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, and @tbg)
pkg/sql/tenant.go, line 238 at r1 (raw file):
Previously, dt (David Taylor) wrote…
I think it is weird to pass this a txn and then we clearRange not using that txn. Indeed, passing a txn is weird since clear range isn't transaction-safe.
Done.
pkg/sql/tenant.go
Outdated
|
|
||
| return nil | ||
| } | ||
| if err := p.execCfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { |
There was a problem hiding this comment.
might be worth a comment explaining why we're db.Txn'ing, e.g. something like "confirm tenant is ready to be cleared. This uses a standalone txn that must commit before we move on, since we will be acting non-transactionally on the result when we ClearRange."
853ac8f to
e820719
Compare
spaskob
left a comment
There was a problem hiding this comment.
PTAL
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @dt, @spaskob, and @tbg)
pkg/sql/tenant.go, line 287 at r2 (raw file):
Previously, dt (David Taylor) wrote…
These checks are repeated in DeleteTenantRecord, which got me looking at who calls it outside here, and I'm not sure about the benefit of splitting out and exporting both
DeleteTenantRecordandClearTenantas standalone functions: we really should never be calling the latter without the former first.I'm thinking it might make sense to un-export them or just inlining them in this method instad, and then making the majority of this method (form this line onwards) an exported function, with this planner method just becoming a wrapper around it (that checks p's txnImplicit and then calls the function). Then RESTORE can call this function to check, clear and delete all at once, and we don't need the repeated checks?
Done.
pkg/sql/tenant.go, line 313 at r2 (raw file):
Previously, dt (David Taylor) wrote…
should we
return p.txn.Commit()before we let go of txn? we did non-txn'l side effects (clearing range) so I'm wary of leaving p.txn uncommitted, but I might just be paranoid.Alternatively, we could just fire up our own txn again and completely ignore p.Txn (other than asserting it is implicit) which might be cleaner if we do the method/function re-org I mention above, because then this function isn't passed a txn at all which makes clear that it isn't transactional.
Done.
pkg/sql/tenant.go
Outdated
| return errors.Errorf("gc_tenant cannot be used inside a transaction") | ||
| } | ||
|
|
||
| info, err := getTenantRecord(ctx, p.execCfg, p.txn, tenID) |
There was a problem hiding this comment.
nit: if we're going to use p.Txn here, I'd Commit() it here, after err check before moving on to call GCTenant using its results?
75794f5 to
fad24d5
Compare
Informs cockroachdb#47904. This is a stop gap solution that will perform the operation synchronously inside the transaction that marks the tenant row as DROP and finally deletes the row. This PR is intended to be backported to 20.2 release branch. The long-term solution that implements cockroachdb#48775 is done in cockroachdb#55756 and will be our long term approach for release 21.0 and beyond. Release note: none.
fad24d5 to
3145bc4
Compare
|
bors r+ |
|
Build succeeded: |
Informs #47904.
This is a stop gap solution that will perform the operation
synchronously inside the transaction that marks the tenant row
as DROP and finally deletes the row.
This PR is intended to be backported to 20.2 release branch.
The long-term solution that implements #48775 is done in #55756
and will be our long term approach for release 21.0 and beyond.
Release note: none.