-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathATransaction.cs
710 lines (652 loc) · 23.8 KB
/
ATransaction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
using Aerospike.Client;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using LPU = LINQPad.Util;
namespace Aerospike.Database.LINQPadDriver.Extensions
{
[Flags]
public enum TransactionStates
{
/// <summary>
/// The Initial stat of the transaction
/// </summary>
NotInitized = 0x0000000,
/// <summary>
/// The transaction is ready for use or is actively being utilized.
/// </summary>
Active = 0x0000001,
/// <summary>
/// The commit method was called and the commit is in progress.
/// </summary>
CommitRequested = 0x00000010,
/// <summary>
/// The commit is in progress but is in some retry state where some of the actions have been actually committed to the DB.
/// </summary>
PartiallyCommitted = CommitRequested | 0x0000100,
/// <summary>
/// The commit completed and all the actions were rolled forward.
/// </summary>
Committed = 0x0001000,
/// <summary>
/// The abort method was called and the abort is in progress.
/// </summary>
AbortRequested = 0x0010000,
/// <summary>
/// The aborted was completed and the actions where rolled back.
/// </summary>
Aborted = 0x0100000,
/// <summary>
/// A Failure occurred during processing of a <see cref="ATransaction.Commit"/> or <see cref="ATransaction.Abort"/>
/// </summary>
Failed = 0x1000000
}
[Flags]
public enum CommitResults
{
None = 0,
Completed = 0x0001,
/// <summary>
/// The transaction was already completed
/// </summary>
AlreadyCommitted = Completed | 0x0010,
/// <summary>
/// The Server will roll forward this transaction
/// </summary>
RollForwardServer = 0x0100,
/// <summary>
/// The Server completed the roll forward of this transaction
/// </summary>
RollForwardServerCompleted = Completed | RollForwardServer,
/// <summary>
/// The commit completed via retries.
/// </summary>
CompletedRetry = 0x1000 | Completed,
/// <summary>
/// The Commit Failed.
/// </summary>
Failed = 0x00010000,
/// <summary>
/// The Transaction was previously aborted.
/// </summary>
PreviouslyAborted = 0x00100000 | Failed
}
[Flags]
public enum AbortResults
{
None = 0,
Completed = 0x0001,
/// <summary>
/// The transaction was already aborted
/// </summary>
AlreadyAborted = Completed | 0x0010,
/// <summary>
/// The Server will roll back this transaction
/// </summary>
RollBackServer = 0x0100,
/// <summary>
/// The Server completed the roll back of this transaction
/// </summary>
RollBackServerCompleted = Completed | RollBackServer,
/// <summary>
/// The Abort Failed.
/// </summary>
Failed = 0x00010000,
/// <summary>
/// The Transaction was previously committed.
/// </summary>
PreviouslyCommitted = 0x00100000 | Failed
}
/// <summary>
/// Transaction State of a Record when it is part of an Aerospike Multiple Record Transaction (MRT)
/// </summary>
[Flags]
public enum TransactionRecordStates
{
/// <summary>
/// The record was NOT part of an Aerospike Multiple Record Transaction (MRT)
/// </summary>
NA = 0x0000,
/// <summary>
/// The record was read from an Aerospike Multiple Record Transaction (MRT)
/// </summary>
Read = 0x0001,
/// <summary>
/// The record was updated (delete, put, etc.) and is pending a commit or abort for an Aerospike Multiple Record Transaction (MRT)
/// </summary>
Update = 0x0010,
/// <summary>
/// The record is part of an Aerospike Multiple Record Transaction (MRT)
/// Can be either a <see cref="Read"/> or <see cref="Update"/>
/// </summary>
MRT = Read | Update
}
/// <summary>
/// Interface Used to create an Aerospike Multi-Record Transaction.
/// It wraps an <see cref="ANamespaceAccess"/> object which creates a set of new set of <see cref="Policy"/> that use <see cref="Txn"/> object.
/// </summary>
public interface IATransaction
{
/// <summary>
/// Gets the aerospike <see cref="Aerospike.Client.Txn"/> instance or null to indicate that it is not within a transaction.
/// </summary>
/// <value>The aerospike <see cref="Aerospike.Client.Txn"/> instance or null</value>
Txn Txn { get; }
/// <summary>
/// Gets or sets the commit retries on certain commit exceptions/errors.
/// It can be set up to the time of the <see cref="Commit"/>.
///
/// If this value is 0, no retries are allowed and an <see cref="RetryException"/> occurred.
/// </summary>
int CommitRetries { get; set; }
/// <summary>
/// Gets or sets the retry sleep in milliseconds.
/// The sleep occurs between retries.
///
/// If zero, no sleep occurs.
/// </summary>
/// <value>The retry sleep ms.</value>
int RetrySleepMS { get; set; }
/// <summary>
/// MRT timeout in seconds. The timer starts when the MRT monitor record is created.
/// This occurs when the first command in the MRT is executed. If the timeout is reached before
/// a commit or abort is called, the server will expire and rollback the MRT.
/// Defaults to 10 seconds.
/// </summary>
/// <value>The MRT timeout secs.</value>
int MRTTimeoutSecs { get; }
/// <summary>
/// Returns the transaction identifier.
/// </summary>
long TransactionId { get; }
/// <summary>
/// The parent (Namespace instance, <see cref="ANamespaceAccess"/>) of this transaction.
/// Could be a <see cref="ATransaction"/>.
/// </summary>
/// <value>The associated Namespace or Transaction instance</value>
ANamespaceAccess Parent { get; }
/// <summary>
/// Returns the current state of the transaction.
/// </summary>
TransactionStates State { get; }
/// <summary>
/// Returns the status of the last <see cref="Commit"/> action.
/// </summary>
CommitResults CommitStatus { get; }
/// <summary>
/// Returns the status of the last <see cref="Abort"/> action.
/// </summary>
AbortResults AbortStatus { get; }
/// <summary>
/// Attempt to commit the given multi-record transaction. First, the expected record versions are
/// sent to the server nodes for verification.If all nodes return success, the command is
/// committed. Otherwise, the transaction is retried based on <see cref="CommitRetries"/>.
/// <p>
/// Requires server version 8.0+
/// </p>
/// </summary>
/// <seealso cref="ATransaction.CreateTransaction(int, int, int)"/>
/// <seealso cref="Abort()"/>
/// <seealso cref="CommitRetries"/>
/// <seealso cref="RetrySleepMS"/>
/// <exception cref="AerospikeException"></exception>
/// <exception cref="Exception"></exception>
/// <exception cref="RetryException">Thrown when Commit <see cref="CommitRetries"/> is exceeded.</exception>
CommitResults Commit();
/// <summary>
/// Abort and rollback the given multi-record transaction.
/// <p>
/// Requires server version 8.0+
/// </p>
/// </summary>
/// <seealso cref="ATransaction.CreateTransaction(int, int, int)"/>
/// <seealso cref="Commit()"/>
AbortResults Abort();
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="key">The record's key used to see if it is part of this transaction</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
(TransactionRecordStates state, long? generation) RecordState([NotNull] Key key);
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="key">The record's key used to see if it is part of this transaction</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
(TransactionRecordStates state, long?) RecordState([NotNull] APrimaryKey key);
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="record">The record used to see if it is part of this transaction</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
(TransactionRecordStates state, long?) RecordState([NotNull] ARecord record);
}
/// <summary>
/// Used to create an Aerospike Multi-Record Transaction (MRT).
/// It wraps an <see cref="ANamespaceAccess"/> object which creates a set of new set of <see cref="Policy"/> that use <see cref="Txn"/> object.
/// </summary>
[DebuggerDisplay("{ToString()}")]
public class ATransaction : ANamespaceAccess, IATransaction
{
#region Constructors
internal ATransaction(ATransaction clone,
Policy readPolicy = null,
WritePolicy writePolicy = null,
QueryPolicy queryPolicy = null,
ScanPolicy scanPolicy = null)
: base(clone,
readPolicy is null
? clone.DefaultReadPolicy
: new(readPolicy)
{
Txn = clone.Txn
},
writePolicy is null
? clone.DefaultWritePolicy
: new(writePolicy)
{
Txn = clone.Txn
},
queryPolicy is null
? clone.DefaultQueryPolicy
: new(queryPolicy)
{
Txn = clone.Txn
},
scanPolicy is null
? clone.DefaultScanPolicy
: new(scanPolicy)
{
Txn = clone.Txn
})
{
this.Txn = clone.Txn;
this.State = clone.State;
this.Parent = clone.Parent;
this.CommitRetries = clone.CommitRetries;
this.RetrySleepMS = clone.RetrySleepMS;
}
/// <summary>
/// Initializes a new instance of <see cref="ATransaction"/> as an Aerospike transactional unit.
/// If <see cref="Commit"/> method is not called the server will abort (rollback) this transaction.
/// </summary>
/// <param name="baseNS">Base Namespace instance</param>
/// <param name="txn">The Aerospike <see cref="Txn"/> instance</param>
/// <param name="commitretries"></param>
/// <param name="retrySleepMS"></param>
/// <exception cref="System.ArgumentNullException">txn</exception>
/// <exception cref="System.ArgumentNullException">clone</exception>
/// <seealso cref="CreateTransaction(int, int, int)"/>
/// <seealso cref="Commit"/>
/// <seealso cref="Abort"/>
public ATransaction(ANamespaceAccess baseNS,
Txn txn,
int commitretries = 1,
int retrySleepMS = 1000)
: base(baseNS,
new(baseNS.DefaultReadPolicy)
{
Txn = txn
},
new(baseNS.DefaultWritePolicy)
{
Txn = txn
},
new(baseNS.DefaultQueryPolicy)
{
Txn = txn
},
new(baseNS.DefaultScanPolicy)
{
Txn = txn
})
{
this.Txn = txn;
this.State = TransactionStates.Active;
this.Parent = baseNS;
this.CommitRetries = commitretries;
this.RetrySleepMS = retrySleepMS;
}
/// <summary>
/// Clones the specified instance providing new policies, if provided.
/// This will used the same transaction id as the original.
/// </summary>
/// <param name="newReadPolicy">The new read policy.</param>
/// <param name="newWritePolicy">The new write policy.</param>
/// <param name="newQueryPolicy">The new query policy.</param>
/// <param name="newScanPolicy">The new scan policy.</param>
/// <returns>New clone of <see cref="ANamespaceAccess"/> instance.</returns>
public override ATransaction Clone(Policy newReadPolicy = null,
WritePolicy newWritePolicy = null,
QueryPolicy newQueryPolicy = null,
ScanPolicy newScanPolicy = null)
=> new ATransaction(this,
newReadPolicy,
newWritePolicy,
newQueryPolicy,
newScanPolicy);
#endregion
/// <summary>
/// Gets the aerospike <see cref="Aerospike.Client.Txn"/> instance
/// </summary>
/// <value>The aerospike <see cref="Aerospike.Client.Txn"/> instance</value>
public Txn Txn { get; }
/// <summary>
/// Gets the aerospike <see cref="Aerospike.Client.Txn"/> instance or Null
/// </summary>
public override Txn GetAerospikeTxn() => this.Txn;
/// <summary>
/// Gets or sets the commit retries on certain commit exceptions/errors.
/// It can be set up to the time of the <see cref="Commit"/>.
///
/// If this value is 0, no retries are allowed and an <see cref="RetryException"/> occurred.
/// </summary>
public int CommitRetries { get; set; }
/// <summary>
/// Gets or sets the retry sleep in milliseconds.
/// The sleep occurs between retries.
///
/// If zero, no sleep occurs.
/// </summary>
/// <value>The retry sleep ms.</value>
public int RetrySleepMS { get; set; }
/// <summary>
/// MRT timeout in seconds. The timer starts when the MRT monitor record is created.
/// This occurs when the first command in the MRT is executed. If the timeout is reached before
/// a commit or abort is called, the server will expire and rollback the MRT.
/// Defaults to 10 seconds.
/// </summary>
/// <value>The MRT timeout secs.</value>
public int MRTTimeoutSecs => this.Txn.Timeout;
/// <summary>
/// Returns the transaction identifier.
/// </summary>
public long TransactionId => this.Txn.Id;
/// <summary>
/// The parent (Namespace instance, <see cref="ANamespaceAccess"/>) of this transaction.
/// Could be a <see cref="ATransaction"/>.
/// </summary>
/// <value>The associated Namespace or Transaction instance</value>
public ANamespaceAccess Parent { get; }
/// <summary>
/// Returns the current state of the transaction.
/// </summary>
public TransactionStates State { get; private set; }
/// <summary>
/// Returns the status of the last <see cref="Commit"/> action.
/// </summary>
public CommitResults CommitStatus { get; private set; }
/// <summary>
/// Returns the status of the last <see cref="Abort"/> action.
/// </summary>
public AbortResults AbortStatus { get; private set; }
/// <summary>
/// Creates an new Aerospike transaction.
/// </summary>
/// <param name="mrtTimeout">
/// MRT timeout in seconds. The timer starts when the MRT monitor record is created.
/// This occurs when the first command in the MRT is executed. If the timeout is reached before
/// a commit or abort is called, the server will expire and rollback the MRT.
/// Defaults to 10 seconds.
/// </param>
/// <param name="commitRetries">
/// See <see cref="CommitRetries"/> property.
/// </param>
/// <param name="retrySleepMS">
/// See <see cref="RetrySleepMS"/> property.
/// </param>
/// <returns>Transaction Namespace instance</returns>
/// <seealso cref="Commit"/>
/// <seealso cref="Abort"/>
public override ATransaction CreateTransaction(int mrtTimeout = 10,
int commitRetries = 1,
int retrySleepMS = 1000)
=> new(this,
new Txn() { Timeout = mrtTimeout },
commitRetries,
retrySleepMS);
/// <summary>
/// Attempt to commit the given multi-record transaction. First, the expected record versions are
/// sent to the server nodes for verification.If all nodes return success, the command is
/// committed. Otherwise, the transaction is retried based on <see cref="CommitRetries"/>.
/// <p>
/// Requires server version 8.0+
/// </p>
/// </summary>
/// <seealso cref="CreateTransaction(int, int, int)"/>
/// <seealso cref="Abort()"/>
/// <seealso cref="CommitRetries"/>
/// <seealso cref="RetrySleepMS"/>
/// <exception cref="AerospikeException"></exception>
/// <exception cref="Exception"></exception>
/// <exception cref="RetryException">Thrown when Commit <see cref="CommitRetries"/> is exceeded.</exception>
public CommitResults Commit()
{
this.State = TransactionStates.CommitRequested;
var result = CommitResults.None;
CommitResults TryCommit(int attemp)
{
try
{
var aeResult = this.AerospikeConnection
.AerospikeClient
.Commit(this.Txn);
switch(aeResult)
{
case Client.CommitStatus.CommitStatusType.OK:
if(attemp == 1)
result = CommitResults.Completed;
else
result = CommitResults.CompletedRetry;
break;
case Client.CommitStatus.CommitStatusType.ALREADY_COMMITTED:
result = CommitResults.AlreadyCommitted;
break;
case Client.CommitStatus.CommitStatusType.ROLL_FORWARD_ABANDONED:
result = CommitResults.RollForwardServer;
break;
case Client.CommitStatus.CommitStatusType.CLOSE_ABANDONED:
result = CommitResults.RollForwardServerCompleted;
break;
default:
throw new NotSupportedException($"Abort Result Code '{aeResult}' is Unknown");
}
this.State = TransactionStates.Committed;
}
catch(AerospikeException ae) when (ae.Result == ResultCode.TXN_ALREADY_ABORTED
|| ae.Result == ResultCode.MRT_ABORTED)
{
this.State = TransactionStates.Aborted;
return this.CommitStatus = CommitResults.PreviouslyAborted;
}
catch(AerospikeException ae) when(ae.Result == ResultCode.TXN_ALREADY_COMMITTED
|| ae.Result == ResultCode.MRT_COMMITTED)
{
this.State = TransactionStates.Committed;
return this.CommitStatus = CommitResults.AlreadyCommitted;
}
catch(AerospikeException ae) when (ae.InDoubt && this.CommitRetries > 0)
{
if(attemp < this.CommitRetries)
{
this.State = TransactionStates.PartiallyCommitted;
if(this.RetrySleepMS > 0)
Thread.Sleep(this.RetrySleepMS);
else
Thread.Sleep(0);
return TryCommit(attemp + 1);
}
this.State = TransactionStates.PartiallyCommitted;
this.CommitStatus = CommitResults.Failed;
throw new RetryException($"Attempted to Retry Commit for Txn Id '{this.TransactionId}' {attemp} times.",
attemp,
this,
ae);
}
catch(Exception)
{
this.State = TransactionStates.Failed;
this.CommitStatus = CommitResults.Failed;
throw;
}
this.CommitStatus = result;
return result;
}
return TryCommit(1);
}
/// <summary>
/// Abort and rollback the given multi-record transaction.
/// <p>
/// Requires server version 8.0+
/// </p>
/// </summary>
/// <seealso cref="CreateTransaction(int, int, int)"/>
/// <seealso cref="Commit()"/>
public AbortResults Abort()
{
this.State = TransactionStates.AbortRequested;
AbortResults result;
try
{
var aeResult = this.AerospikeConnection
.AerospikeClient
.Abort(this.Txn);
result = aeResult switch
{
Client.AbortStatus.AbortStatusType.OK => AbortResults.Completed,
Client.AbortStatus.AbortStatusType.ALREADY_ABORTED => AbortResults.AlreadyAborted,
Client.AbortStatus.AbortStatusType.ROLL_BACK_ABANDONED => AbortResults.RollBackServer,
Client.AbortStatus.AbortStatusType.CLOSE_ABANDONED => AbortResults.RollBackServerCompleted,
_ => throw new NotSupportedException($"Abort Result Code '{aeResult}' is Unknown"),
};
this.State = TransactionStates.Aborted;
}
catch(AerospikeException ae) when (ae.Result == ResultCode.TXN_ALREADY_ABORTED
|| ae.Result == ResultCode.MRT_ABORTED)
{
this.State = TransactionStates.Aborted;
return this.AbortStatus = AbortResults.AlreadyAborted;
}
catch(AerospikeException ae) when(ae.Result == ResultCode.TXN_ALREADY_COMMITTED
|| ae.Result == ResultCode.MRT_COMMITTED)
{
this.State = TransactionStates.Committed;
return this.AbortStatus = AbortResults.PreviouslyCommitted;
}
catch(Exception)
{
this.AbortStatus = AbortResults.Failed;
this.State = TransactionStates.Failed;
throw;
}
this.AbortStatus = result;
return result;
}
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="key">The record's key used to see if it is part of this transaction</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
public (TransactionRecordStates state, long? generation) RecordState([NotNull] Key key)
{
if(this.Txn.Writes.Contains(key))
return (TransactionRecordStates.Update, null);
else if(this.Txn.Reads.ContainsKey(key))
return (TransactionRecordStates.Read, this.Txn.Reads[key]);
return (TransactionRecordStates.NA, null);
}
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="key">The record's key used to see if it is part of this transaction</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
public (TransactionRecordStates state, long?) RecordState([NotNull] APrimaryKey key)
=> this.RecordState(key.AerospikeKey);
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="record">The record used to see if it is part of this transaction</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
public (TransactionRecordStates state, long?) RecordState([NotNull] ARecord record)
=> this.RecordState(record.Aerospike.Key);
/// <summary>
/// Returns the <see cref="TransactionRecordStates"/> of a record's key.
/// This is only valid when the <see cref="State"/> is <see cref="TransactionStates.Active"/>.
/// </summary>
/// <param name="setName">Name of the set or null to indicate the Aerospike Null set.</param>
/// <param name="keyValue">The key's value.</param>
/// <returns>
/// Returns a Value Tuple:
/// state (1st value) -- The <see cref="TransactionRecordStates"/>
/// generation (2nd value) -- The record's generation, if it was read. Otherwise the value will be null.
/// </returns>
public (TransactionRecordStates state, long?) RecordState(string setName, [NotNull] dynamic keyValue)
=> this.RecordState(Helpers.DetermineAerospikeKey(keyValue, this.Namespace, setName));
public override string ToString()
{
if(this.BinNames.Length == 0)
return $"TXN {this.Namespace}";
return $"TXN {this.Namespace}{{{string.Join(',', this.BinNames)}}}";
}
public override object ToDump()
=> LPU.ToExpando(this, include: "Namespace, " +
"DBPlatform, " +
"Txn, CommitRetries, RetrySleepMS, MRTTimeoutSecs, " +
"State, CommitStatus, AbortStatus, " +
"SetNames, " +
"BinNames, " +
"AerospikeConnection, " +
"DefaultReadPolicy, " +
"DefaultQueryPolicy, " +
"DefaultScanPolicy, " +
"DefaultWritePolicy");
}
public class RetryException : Exception
{
private RetryException()
{
}
public RetryException(string message,
int attemps,
ATransaction trans,
Exception innerException)
: base(message, innerException)
{
this.Attemps = attemps;
this.Trans = trans;
}
public int Attemps { get; }
public ATransaction Trans { get; }
}
}