Skip to content

Commit

Permalink
sql: stop observing the CommitTimestamp in TRUNCATE
Browse files Browse the repository at this point in the history
In #40581 we stopped observing the commit timestamp to write it into table
descriptors. In this change I overlooked (rather forgot) about this additional
place in the code where we observed the commit timestamp. As far as I can tell
we don't read this field anywhere ever. Furthermore we know that the the table
descriptor in question to which we are referring must be alive and equal to
the provided value at the timestamp at which it was read due to
serializability. In short, this minor change continues to populate the field
with a sensible value and will permit TRUNCATE to be pushed.

Fixes #41566.

Release note (bug fix): Long running transactions which attempt to TRUNCATE
can now be pushed and will commit in cases where they previously could fail
or retry forever.
  • Loading branch information
ajwerner committed Nov 25, 2019
1 parent 68553f3 commit 3003a79
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 38 deletions.
80 changes: 43 additions & 37 deletions pkg/sql/sqlbase/structured.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/sql/sqlbase/structured.proto
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,12 @@ message TableDescriptor {
message Replacement {
option (gogoproto.equal) = true;
optional uint32 id = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"];
// Time is just used for debugging purposes. It is not used in business
// logic. It is an HLC rather than just wall time only for historical
// reasons. Prior to 20.1 it was populated with the commit timestamp of the
// transaction which created this replacement. In 20.1 and after it is
// populated with the read timestamp at which the descriptor being
// replaced was read.
optional util.hlc.Timestamp time = 2 [(gogoproto.nullable) = false];
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ func (p *planner) truncateTable(
tableDesc.DropJobID = dropJobID
newTableDesc := sqlbase.NewMutableCreatedTableDescriptor(tableDesc.TableDescriptor)
newTableDesc.ReplacementOf = sqlbase.TableDescriptor_Replacement{
ID: id, Time: p.txn.CommitTimestamp(),
ID: id,
// NB: Time is just used for debugging purposes. See the comment on the
// field for more details.
Time: p.txn.ReadTimestamp(),
}
newTableDesc.SetID(0)
newTableDesc.Version = 1
Expand Down

0 comments on commit 3003a79

Please sign in to comment.