Skip to content

Commit 567d0f9

Browse files
committed
NCBC-3974 FIT test issues
Motivation ========== Green tests are best. This greens them a bit, more coming... Modification ============ * Fixed small issue in handling CasMismatch during staging inserts, where we were not adding it to the staged mutations when we are only resolving ambiguity. This involved allowing an empty mutation token in this case. * Raising proper error (TransactionFailedPostCommit) when a document was changed during unstaging. * Properly encoding the durabilityLevel for transactional queries. Also needed to correct the multiple places it was being set unnecessarily. Results ======= Test fails down to 26 locally for me (from 32-ish) out of 3242. Change-Id: Id52c89e171ef45b527b485bd655e5e2b29612047 Change-Id: I682ee665fd940a3f00746c33d074094ac351cea9 Reviewed-on: https://review.couchbase.org/c/couchbase-net-client/+/226161 Reviewed-by: Emilien Bevierre <emilien.bevierre@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 86cb132 commit 567d0f9

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/Couchbase/Client/Transactions/AttemptContext.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,10 @@ await ForwardCompatibility.Check(this,
792792
"update cas as we are only resolving ambiguity");
793793
docAlreadyExistsResult =
794794
docWithMeta.GetPostTransactionResult();
795-
docAlreadyExistsResult.Cas = docWithMeta!.Cas;
795+
var stagedMutation =
796+
new StagedMutation(docAlreadyExistsResult,
797+
content, StagedMutationType.Insert);
798+
_stagedMutations.Add(stagedMutation);
796799
return (RepeatAction.NoRepeat,
797800
RepeatAction.NoRepeat);
798801
}
@@ -1445,6 +1448,7 @@ await RepeatUntilSuccessOrThrow(async () =>
14451448
.DoNotRollbackAttempt()
14461449
.Cause(new AttemptExpiredException(this,
14471450
"Commit expired in HandleDocChangedDuringCommit"))
1451+
.RaiseException(TransactionOperationFailedException.FinalError.TransactionFailedPostCommit)
14481452
.Build();
14491453
}
14501454
try
@@ -2392,12 +2396,28 @@ private async Task<IQueryResult<T>> QueryWrapperLocked<T>(
23922396
}
23932397
}
23942398

2399+
private static string DurabilityLevelToString(DurabilityLevel durabilityLevel)
2400+
{
2401+
return durabilityLevel switch
2402+
{
2403+
DurabilityLevel.None => "NONE",
2404+
DurabilityLevel.Majority => "MAJORITY",
2405+
DurabilityLevel.MajorityAndPersistToActive => "MAJORITY_AND_PERSIST_TO_ACTIVE",
2406+
DurabilityLevel.PersistToMajority => "PERSIST_TO_MAJORITY",
2407+
_ => durabilityLevel.ToString()
2408+
};
2409+
}
2410+
23952411
private QueryTxData CreateBeginWorkTxData()
23962412
{
2397-
var state = new TxDataState((long)_overallContext.RemainingUntilExpiration.TotalMilliseconds);
2398-
var txConfig = new TxDataReportedConfig((long?)_config?.KeyValueTimeout?.TotalMilliseconds ?? 10_000, AtrIds.NumAtrs, _effectiveDurabilityLevel.ToString().ToUpperInvariant());
2413+
var state =
2414+
new TxDataState((long)_overallContext.RemainingUntilExpiration.TotalMilliseconds);
2415+
var txConfig = new TxDataReportedConfig(
2416+
(long?)_config?.KeyValueTimeout?.TotalMilliseconds ?? 10_000, AtrIds.NumAtrs,
2417+
DurabilityLevelToString(_effectiveDurabilityLevel));
23992418

2400-
var mutations = _stagedMutations?.ToList().Select(sm => sm.AsTxData()) ?? Array.Empty<TxDataMutation>();
2419+
var mutations = _stagedMutations?.ToList().Select(sm => sm.AsTxData()) ??
2420+
Array.Empty<TxDataMutation>();
24012421
var txid = new CompositeId()
24022422
{
24032423
Transactionid = _overallContext.TransactionId,
@@ -2628,14 +2648,6 @@ private QueryOptions InitializeBeginWorkQueryOptions(QueryOptions queryOptions)
26282648
{
26292649
queryOptions
26302650
.ScanConsistency(_config.ScanConsistency ?? QueryScanConsistency.RequestPlus)
2631-
.Raw("durability_level", _effectiveDurabilityLevel switch
2632-
{
2633-
DurabilityLevel.None => "none",
2634-
DurabilityLevel.Majority => "majority",
2635-
DurabilityLevel.MajorityAndPersistToActive => "majorityAndPersistActive",
2636-
DurabilityLevel.PersistToMajority => "persistToMajority",
2637-
_ => _effectiveDurabilityLevel.ToString()
2638-
})
26392651
.Raw("txtimeout", $"{_overallContext.RemainingUntilExpiration.TotalMilliseconds}ms");
26402652

26412653
if (_config.MetadataCollection != null)

src/Couchbase/Client/Transactions/Components/StagedMutation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ internal class StagedMutation
1414
public StagedMutationType Type { get; }
1515
public MutationToken MutationToken { get; }
1616

17-
public StagedMutation(TransactionGetResult doc, object? content, StagedMutationType type, MutationToken mutationToken)
17+
public StagedMutation(TransactionGetResult doc, object? content, StagedMutationType type, MutationToken? mutationToken = null)
1818
{
1919
Doc = doc;
2020
Content = content;
2121
Type = type;
22-
MutationToken = mutationToken;
22+
MutationToken = mutationToken ?? MutationToken.Empty;
2323
}
2424

2525
public JObject ForAtr() => new JObject(

src/Couchbase/Client/Transactions/Error/Attempts/ErrorTriage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ internal void ThrowIfCommitWithPreviousErrors(IEnumerable<TransactionOperationFa
191191
var previousErrors = previousErrorOperations.ToList();
192192
var retryTransaction = previousErrors.All(ex => ex.RetryTransaction);
193193
var rollback = previousErrors.All(ex => ex.AutoRollbackAttempt);
194-
var cause = new PreviousOperationFailedException(previousErrors);
195-
var builder = CreateError(_ctx, FailOther, cause);
194+
var builder = CreateError(_ctx, FailOther);
196195
if (retryTransaction)
197196
{
198197
builder.RetryTransaction();

0 commit comments

Comments
 (0)