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

roachpb: split Intent proto message into Intent and LockUpdate messages #45235

Merged

Conversation

nvanbenschoten
Copy link
Member

The Intent message type has been a frequent source of complexity and confusion. @knz found this out first-hand in #42152/#42582 when he tried to add an IgnoredSeqNums field to the message type. This led to a series of questions that were not easily answered by simply reading about the message type, like:

  • why would an Intent ever have a non-PENDING status?
  • why would an Intent ever span multiple keys?
  • where are Intents created?
  • is this Intent message containing the authoritative state of the txn?
  • does this Intent message have a populated IgnoredSeqNums slice?

The root problem was that the message type was serving two roles, as was documented in its comment. It both referenced on-disk write intents and served as a way to talk about updates that should be made to these write intents.

This commit addresses this issue by splitting Intent into two (wire-compatible) messages with distinct purposes - Intent and LockUpdate. Intent's new sole purpose is now to reference persistent on-disk write intents on return paths of MVCC operations. They are only ever created when on-disk intents are encountered. LockUpdate's sole purpose is to represent updates that are intended for all locks held by the transaction within its span. They are only ever created after their transaction's record has been consulted, either after an EndTxn or a PushTxn request. This split simplifies the use of each of these types and helps make the questions above easier to answer or impossible to even ask (e.g. Intent no longer has a Status field).

While here, the commit adds a durability field to LockUpdate. This is used to inform the message's recipient about the durability of the lock(s) it is being instructed to update. This will be important soon when #44976 formally introduces unreplicated locks to the key-value layer.

I would suggest that reviewers start with the proto changes in pkg/roachpb and fan-out from there. Everything else is essentially fallout from the typing change. This is still a bit of a WIP as there is more renaming necessary before this could be merged, but I want to get people's opinions on this sooner rather than later because it's partly on the critical path for #44976 and I'm feeling a little pressed for time with that change and the impending stability period.

@nvanbenschoten nvanbenschoten requested a review from a team as a code owner February 20, 2020 04:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

:lgtm: given how this PR sprays, I'd say go ahead and merge this. You can address my comments after.

Reviewed 42 of 42 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/roachpb/api.go, line 1284 at r1 (raw file):

		Status:         rir.Status,
		IgnoredSeqNums: rir.IgnoredSeqNums,
		Durability:     lock.Replicated,

Will we ever allow making a replicated lock unreplicated? Just curious.


pkg/roachpb/data.go, line 1786 at r1 (raw file):

}

// MakePendingIntent makes an intent in the pending state with the

The reference here to the pending state confused me until I realized that you want to drive the point home that an Intent always describes a pending intent (i.e. there is no status on, it but it's implicitly PENDING). Are you really trying to rename Intent to PendingIntent? If this is not appropriate, I wonder if we should drop the Pending and rely on the comment in data.proto to drive that point home.


pkg/roachpb/data.proto, line 555 at r1 (raw file):

  // NB: now that LockUpdate is split away from this message type, this span
  // field always contains a single-key. We could migrate it, but doing so
  // doesn't seem worth it.

Can we replace span below with the wire-compatible

// SingleKeySpan preseves wire compatibility with an earlier version of this proto which
// used a roachpb.Span.xxxxx
message SingleKeySpan {
  option (gogoproto.equal) = true;

  option (gogoproto.goproto_stringer) = false;
  option (gogoproto.populate) = true;

  reserved 1, 2, 4;
  // The start key of the key range.
  bytes key = 3 [(gogoproto.casttype) = "Key"];
}
SingleKeySpan span = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];

and avoid any kind of real migration? I think that might be worth it, to avoid having an EndKey around which will invite some of the confusion you're generally eliminating here.

Copy link
Member Author

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Thanks for the quick review!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @tbg)


pkg/roachpb/api.go, line 1284 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Will we ever allow making a replicated lock unreplicated? Just curious.

I think this would be possible if you roll back a replicated lock and then replace it with an unreplicated lock. But I don't think we'll ever need to support it for a single sequence number.


pkg/roachpb/data.go, line 1786 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

The reference here to the pending state confused me until I realized that you want to drive the point home that an Intent always describes a pending intent (i.e. there is no status on, it but it's implicitly PENDING). Are you really trying to rename Intent to PendingIntent? If this is not appropriate, I wonder if we should drop the Pending and rely on the comment in data.proto to drive that point home.

Done.


pkg/roachpb/data.proto, line 555 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Can we replace span below with the wire-compatible

// SingleKeySpan preseves wire compatibility with an earlier version of this proto which
// used a roachpb.Span.xxxxx
message SingleKeySpan {
  option (gogoproto.equal) = true;

  option (gogoproto.goproto_stringer) = false;
  option (gogoproto.populate) = true;

  reserved 1, 2, 4;
  // The start key of the key range.
  bytes key = 3 [(gogoproto.casttype) = "Key"];
}
SingleKeySpan span = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];

and avoid any kind of real migration? I think that might be worth it, to avoid having an EndKey around which will invite some of the confusion you're generally eliminating here.

Done.

@nvanbenschoten
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 20, 2020

Merge conflict (retrying...)

2 similar comments
@craig
Copy link
Contributor

craig bot commented Feb 20, 2020

Merge conflict (retrying...)

@craig
Copy link
Contributor

craig bot commented Feb 20, 2020

Merge conflict (retrying...)

@craig
Copy link
Contributor

craig bot commented Feb 20, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Feb 20, 2020

Merge conflict

The Intent message type has been a frequent source of complexity and
confusion. cockroachdb#42152/cockroachdb#42582 found this out first hand when it tried to
add an IgnoredSeqNums field to the message type. This led to a series
of questions that were not easily answered by simply reading about
the message type, like:
- why would an Intent ever have a non-PENDING status?
- why would an Intent ever span multiple keys?
- where are Intents created?
- is this Intent message containing the authoritative state of the txn?
- does this Intent message have a populated IgnoredSeqNums slice?

The root problem was that the message type was serving two roles, as was
documented in its comment. It both referenced on-disk write intents and
served as a way to talk about updates that should be made to these write
intents.

This commit addresses this issue by splitting Intent into two
(wire-compatible) messages with distinct purposes - Intent and LockUpdate.
Intent's new sole purpose is now to reference persistent on-disk write
intents on return paths of MVCC operations. They are only ever created
when on-disk intents are encountered. LockUpdate's sole purpose is to
represent updates that are intended for all locks held by the transaction
within its span. They are only ever created after their transaction's
record has been consulted, either after an EndTxn or a PushTxn request.
This split simplifies the use of each of these types and helps make
the questions above easier to answer or impossible to even ask (e.g.
Intent no longer has a Status field).

While here, the commit adds a `durability` field to LockUpdate. This is
used to inform the message's recipient about the durability of the
lock(s) it is being instructed to update. This will be important soon
when cockroachdb#44976 formally introduces unreplicated locks to the key-value
layer.

I would suggest that reviewers start with the proto changes in `pkg/roachpb`
and fan out from there. Everything else is essentially fallout from the
typing change. This is still a bit of a WIP as there is more renaming
necessary before this could be merged, but I want to get people's opinions
on this sooner rather than later because it's partly on the critical path
for cockroachdb#44976 and I'm feeling a little pressed for time with that change and
the impending stability period.
@nvanbenschoten
Copy link
Member Author

bors r+

@nvanbenschoten
Copy link
Member Author

Cancelled

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 21, 2020

Build succeeded

@craig craig bot merged commit 79f2de7 into cockroachdb:master Feb 21, 2020
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/intentLockUpdate branch February 25, 2020 07:26
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.

3 participants