-
Notifications
You must be signed in to change notification settings - Fork 243
NCBC-4261: Use the staged txn.aux.uf user flags when committing #149
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
Draft
davidkelly
wants to merge
1
commit into
master
Choose a base branch
from
dk/ncbc-4261
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Couchbase/Client/Transactions/Internal/FixedFlagsTranscoder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #nullable enable | ||
| using System; | ||
| using System.IO; | ||
| using Couchbase.Core.IO.Operations; | ||
| using Couchbase.Core.IO.Serializers; | ||
| using Couchbase.Core.IO.Transcoders; | ||
|
|
||
| namespace Couchbase.Client.Transactions.Internal | ||
| { | ||
| /// <summary> | ||
| /// A transcoder decorator that pins the flags written to the document, delegating the actual | ||
| /// byte encoding/decoding to an inner transcoder. | ||
| /// <para> | ||
| /// On a .NET mutation the persisted flags are always <c>Transcoder.GetFormat(content)</c> | ||
| /// (see <c>OperationBase<T>.WriteExtras</c>) — there is no per-operation flags override, | ||
| /// which is why <c>InsertOptions</c> exposes none. When committing content we did not stage | ||
| /// (lost-transaction cleanup) or via the legacy insert path, we must persist the user flags | ||
| /// recorded at staging time (<c>txn.aux.uf</c>) rather than flags re-derived from the content. | ||
| /// This wrapper makes <see cref="GetFormat{T}"/> report those staged flags so they land on the | ||
| /// document, while <see cref="Encode{T}"/>/<see cref="Decode{T}"/> behave exactly as the inner | ||
| /// transcoder. It is the .NET analogue of Java passing <c>stagedUserFlags</c> straight to the | ||
| /// insert request. | ||
| /// </para> | ||
| /// </summary> | ||
| internal sealed class FixedFlagsTranscoder : ITypeTranscoder | ||
| { | ||
| private readonly ITypeTranscoder _inner; | ||
| private readonly Flags _flags; | ||
|
|
||
| public FixedFlagsTranscoder(ITypeTranscoder inner, Flags flags) | ||
| { | ||
| _inner = inner ?? throw new ArgumentNullException(nameof(inner)); | ||
| _flags = flags; | ||
| } | ||
|
|
||
| /// <summary>Always reports the fixed (staged) flags, ignoring the content's runtime type.</summary> | ||
| public Flags GetFormat<T>(T value) => _flags; | ||
|
|
||
| public void Encode<T>(Stream stream, T value, Flags flags, OpCode opcode) => | ||
| _inner.Encode(stream, value, flags, opcode); | ||
|
|
||
| public T? Decode<T>(ReadOnlyMemory<byte> buffer, Flags flags, OpCode opcode) => | ||
| _inner.Decode<T>(buffer, flags, opcode); | ||
|
|
||
| public ITypeSerializer? Serializer | ||
| { | ||
| get => _inner.Serializer; | ||
| set => _inner.Serializer = value; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
True! But also all other sdks wrote it in the big-endian. We must match other sdk, so we have to change it. the only risk is if we are cleaning a txn written by us from before this change. The much, much bigger risk is we don't change and therefore remain broken with respect to all other sdks, and cannot interoperate.
A better debate than making the fix would be when to make it. Do we put this in now, or do we wait for a minor and call it out. The reality is that this only really burns us if there are lost transactions (or concurrently transactions from an older sdk) that we need to commit, and this is really rare.
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.
Perhaps create a Jira ticket do this in a minor release?