You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2022/01/10 14:30:06 UTC
[ignite-3] branch main updated: IGNITE-16208 .NET: Add Transactions API (#535)
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 8555619 IGNITE-16208 .NET: Add Transactions API (#535)
8555619 is described below
commit 8555619c206b283ba7593927592599d3719f2f53
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Mon Jan 10 17:29:01 2022 +0300
IGNITE-16208 .NET: Add Transactions API (#535)
* Extract `RecordBinaryView` from `Table` to match Java API.
* Add `transaction` parameter to all table methods.
* Use tx owner socket for transactional operations.
* Implement tuple equality.
* Add pooled buffer leak detection to all tests, fix leak on request error.
---
.../internal/client/tx/ClientTransaction.java | 6 +-
.../Table/TupleGetBenchmarks.cs | 8 +-
.../dotnet/Apache.Ignite.Tests/IgniteTestsBase.cs | 24 +-
.../Apache.Ignite.Tests/Table/IgniteTupleTests.cs | 28 +
.../dotnet/Apache.Ignite.Tests/Table/TableTests.cs | 208 ++++---
.../Apache.Ignite.Tests/TestEventListener.cs | 62 ++
.../Transactions/TransactionsTests.cs | 197 +++++++
.../platforms/dotnet/Apache.Ignite.sln.DotSettings | 5 +
modules/platforms/dotnet/Apache.Ignite/IIgnite.cs | 9 +-
.../dotnet/Apache.Ignite/IIgniteClient.cs | 4 +-
.../Apache.Ignite/Internal/ClientFailoverSocket.cs | 2 +-
.../dotnet/Apache.Ignite/Internal/ClientSocket.cs | 3 +-
.../Apache.Ignite/Internal/IgniteClientInternal.cs | 5 +
.../Apache.Ignite/Internal/Proto/ClientOp.cs | 9 +
.../Table/{Table.cs => RecordBinaryView.cs} | 267 +++++----
.../dotnet/Apache.Ignite/Internal/Table/Table.cs | 630 +--------------------
.../Internal/Transactions/Transaction.cs | 155 +++++
.../Transactions.cs} | 33 +-
.../dotnet/Apache.Ignite/Table/IIgniteTuple.cs | 73 +++
.../Table/{ITableView.cs => IRecordView.cs} | 52 +-
.../platforms/dotnet/Apache.Ignite/Table/ITable.cs | 7 +-
.../dotnet/Apache.Ignite/Table/IgniteTuple.cs | 21 +-
.../{IIgnite.cs => Transactions/ITransaction.cs} | 24 +-
.../ITransactions.cs} | 15 +-
24 files changed, 930 insertions(+), 917 deletions(-)
diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientTransaction.java b/modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientTransaction.java
index db90c8a..5d162e8 100644
--- a/modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientTransaction.java
+++ b/modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientTransaction.java
@@ -106,11 +106,13 @@ public class ClientTransaction implements Transaction {
}
private void setState(int state) {
- if (this.state.compareAndSet(STATE_OPEN, state)) {
+ int oldState = this.state.compareAndExchange(STATE_OPEN, state);
+
+ if (oldState == STATE_OPEN) {
return;
}
- String message = this.state.get() == STATE_COMMITTED
+ String message = oldState == STATE_COMMITTED
? "Transaction is already committed."
: "Transaction is already rolled back.";
diff --git a/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Table/TupleGetBenchmarks.cs b/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Table/TupleGetBenchmarks.cs
index 4a34bca..1ccd788 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Table/TupleGetBenchmarks.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Benchmarks/Table/TupleGetBenchmarks.cs
@@ -32,7 +32,7 @@ namespace Apache.Ignite.Benchmarks.Table
{
private JavaServer? _javaServer;
private IIgniteClient? _client;
- private ITable _table = null!;
+ private IRecordView<IIgniteTuple> _table = null!;
private IgniteTuple _keyTuple = null!;
[GlobalSetup]
@@ -40,7 +40,7 @@ namespace Apache.Ignite.Benchmarks.Table
{
_javaServer = await JavaServer.StartAsync();
_client = await IgniteClient.StartAsync(new IgniteClientConfiguration("127.0.0.1:" + _javaServer.Port));
- _table = (await _client.Tables.GetTableAsync("PUB.tbl1"))!;
+ _table = (await _client.Tables.GetTableAsync("PUB.tbl1"))!.RecordView;
var tuple = new IgniteTuple
{
@@ -48,7 +48,7 @@ namespace Apache.Ignite.Benchmarks.Table
["val"] = "foo"
};
- await _table.UpsertAsync(tuple);
+ await _table.UpsertAsync(null, tuple);
_keyTuple = new IgniteTuple
{
@@ -66,7 +66,7 @@ namespace Apache.Ignite.Benchmarks.Table
[Benchmark]
public async Task Get()
{
- await _table.GetAsync(_keyTuple);
+ await _table.GetAsync(null, _keyTuple);
}
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteTestsBase.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteTestsBase.cs
index 6734485..366af1b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteTestsBase.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/IgniteTestsBase.cs
@@ -17,6 +17,7 @@
namespace Apache.Ignite.Tests
{
+ using System.Linq;
using System.Threading.Tasks;
using Ignite.Table;
using NUnit.Framework;
@@ -34,18 +35,22 @@ namespace Apache.Ignite.Tests
private JavaServer? _serverNode;
+ private TestEventListener _eventListener = null!;
+
protected int ServerPort => _serverNode?.Port ?? 0;
protected IIgniteClient Client { get; private set; } = null!;
- protected ITable Table { get; private set; } = null!;
+ protected IRecordView<IIgniteTuple> Table { get; private set; } = null!;
[OneTimeSetUp]
public async Task OneTimeSetUp()
{
+ _eventListener = new TestEventListener();
+
_serverNode = await JavaServer.StartAsync();
Client = await IgniteClient.StartAsync(GetConfig());
- Table = (await Client.Tables.GetTableAsync(TableName))!;
+ Table = (await Client.Tables.GetTableAsync(TableName))!.RecordView;
}
[OneTimeTearDown]
@@ -54,8 +59,23 @@ namespace Apache.Ignite.Tests
// ReSharper disable once ConstantConditionalAccessQualifier
Client?.Dispose();
_serverNode?.Dispose();
+
+ Assert.Greater(_eventListener.BuffersRented, 0);
+ Assert.AreEqual(_eventListener.BuffersReturned, _eventListener.BuffersRented);
+ _eventListener.Dispose();
+ }
+
+ [TearDown]
+ public async Task TearDown()
+ {
+ await Table.DeleteAllAsync(null, Enumerable.Range(1, 10).Select(x => GetTuple(x)));
+
+ Assert.AreEqual(_eventListener.BuffersReturned, _eventListener.BuffersRented);
}
+ protected static IIgniteTuple GetTuple(long id, string? val = null) =>
+ new IgniteTuple { [KeyCol] = id, [ValCol] = val };
+
protected IgniteClientConfiguration GetConfig() => new()
{
Endpoints = { "127.0.0.1:" + _serverNode?.Port }
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/IgniteTupleTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/IgniteTupleTests.cs
index e299ae1..b399aac 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/IgniteTupleTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/IgniteTupleTests.cs
@@ -84,5 +84,33 @@ namespace Apache.Ignite.Tests.Table
Assert.AreEqual("IgniteTuple [foo=1, b=abcd]", tuple.ToString());
}
+
+ [Test]
+ public void TestEquality()
+ {
+ var t1 = new IgniteTuple(2) { ["k"] = 1, ["v"] = "2" };
+ var t2 = new IgniteTuple(3) { ["k"] = 1, ["v"] = "2" };
+ var t3 = new IgniteTuple(4) { ["k"] = 1, ["v"] = null };
+
+ Assert.AreEqual(t1, t2);
+ Assert.AreEqual(t2, t1);
+ Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode());
+
+ Assert.AreNotEqual(t1, t3);
+ Assert.AreNotEqual(t1.GetHashCode(), t3.GetHashCode());
+
+ Assert.AreNotEqual(t2, t3);
+ Assert.AreNotEqual(t2.GetHashCode(), t3.GetHashCode());
+ }
+
+ [Test]
+ public void TestCustomTupleEquality()
+ {
+ var tuple = new IgniteTuple { ["key"] = 42, ["val"] = "Val1" };
+ var customTuple = new CustomTestIgniteTuple();
+
+ Assert.IsTrue(IIgniteTuple.Equals(tuple, customTuple));
+ Assert.AreEqual(IIgniteTuple.GetHashCode(tuple), IIgniteTuple.GetHashCode(customTuple));
+ }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TableTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TableTests.cs
index 26d6f35..e615f55 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TableTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TableTests.cs
@@ -30,20 +30,13 @@ namespace Apache.Ignite.Tests.Table
/// </summary>
public class TableTests : IgniteTestsBase
{
- [SetUp]
- public async Task SetUp()
- {
- // Clean up test data.
- await Table.DeleteAllAsync(Enumerable.Range(0, 100).Select(x => GetTuple(x)));
- }
-
[Test]
public async Task TestUpsertGet()
{
- await Table.UpsertAsync(GetTuple(1, "foo"));
+ await Table.UpsertAsync(null, GetTuple(1, "foo"));
var keyTuple = GetTuple(1);
- var resTuple = (await Table.GetAsync(keyTuple))!;
+ var resTuple = (await Table.GetAsync(null, keyTuple))!;
Assert.IsNotNull(resTuple);
Assert.AreEqual(2, resTuple.FieldCount);
@@ -56,19 +49,19 @@ namespace Apache.Ignite.Tests.Table
{
var key = GetTuple(1);
- await Table.UpsertAsync(GetTuple(1, "foo"));
- Assert.AreEqual("foo", (await Table.GetAsync(key))![1]);
+ await Table.UpsertAsync(null, GetTuple(1, "foo"));
+ Assert.AreEqual("foo", (await Table.GetAsync(null, key))![1]);
- await Table.UpsertAsync(GetTuple(1, "bar"));
- Assert.AreEqual("bar", (await Table.GetAsync(key))![1]);
+ await Table.UpsertAsync(null, GetTuple(1, "bar"));
+ Assert.AreEqual("bar", (await Table.GetAsync(null, key))![1]);
}
[Test]
public async Task TestUpsertAllowsCustomTupleImplementation()
{
- await Table.UpsertAsync(new CustomTestIgniteTuple());
+ await Table.UpsertAsync(null, new CustomTestIgniteTuple());
- var res = await Table.GetAsync(GetTuple(CustomTestIgniteTuple.Key));
+ var res = await Table.GetAsync(null, GetTuple(CustomTestIgniteTuple.Key));
Assert.IsNotNull(res);
Assert.AreEqual(CustomTestIgniteTuple.Value, res![1]);
@@ -77,7 +70,7 @@ namespace Apache.Ignite.Tests.Table
[Test]
public void TestUpsertEmptyTupleThrowsException()
{
- var ex = Assert.ThrowsAsync<IgniteClientException>(async () => await Table.UpsertAsync(new IgniteTuple()));
+ var ex = Assert.ThrowsAsync<IgniteClientException>(async () => await Table.UpsertAsync(null, new IgniteTuple()));
Assert.AreEqual(
"Missed key column: key",
@@ -87,170 +80,170 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestGetAndUpsertNonExistentRecordReturnsNull()
{
- IIgniteTuple? res = await Table.GetAndUpsertAsync(GetTuple(2, "2"));
+ IIgniteTuple? res = await Table.GetAndUpsertAsync(null, GetTuple(2, "2"));
Assert.IsNull(res);
- Assert.AreEqual("2", (await Table.GetAsync(GetTuple(2)))![1]);
+ Assert.AreEqual("2", (await Table.GetAsync(null, GetTuple(2)))![1]);
}
[Test]
public async Task TestGetAndUpsertExistingRecordOverwritesAndReturns()
{
- await Table.UpsertAsync(GetTuple(2, "2"));
- IIgniteTuple? res = await Table.GetAndUpsertAsync(GetTuple(2, "22"));
+ await Table.UpsertAsync(null, GetTuple(2, "2"));
+ IIgniteTuple? res = await Table.GetAndUpsertAsync(null, GetTuple(2, "22"));
Assert.IsNotNull(res);
Assert.AreEqual(2, res![0]);
Assert.AreEqual("2", res[1]);
- Assert.AreEqual("22", (await Table.GetAsync(GetTuple(2)))![1]);
+ Assert.AreEqual("22", (await Table.GetAsync(null, GetTuple(2)))![1]);
}
[Test]
public async Task TestGetAndDeleteNonExistentRecordReturnsNull()
{
- IIgniteTuple? res = await Table.GetAndDeleteAsync(GetTuple(2, "2"));
+ IIgniteTuple? res = await Table.GetAndDeleteAsync(null, GetTuple(2, "2"));
Assert.IsNull(res);
- Assert.IsNull(await Table.GetAsync(GetTuple(2)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(2)));
}
[Test]
public async Task TestGetAndDeleteExistingRecordRemovesAndReturns()
{
- await Table.UpsertAsync(GetTuple(2, "2"));
- IIgniteTuple? res = await Table.GetAndDeleteAsync(GetTuple(2));
+ await Table.UpsertAsync(null, GetTuple(2, "2"));
+ IIgniteTuple? res = await Table.GetAndDeleteAsync(null, GetTuple(2));
Assert.IsNotNull(res);
Assert.AreEqual(2, res![0]);
Assert.AreEqual("2", res[1]);
- Assert.IsNull(await Table.GetAsync(GetTuple(2)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(2)));
}
[Test]
public async Task TestInsertNonExistentKeyCreatesRecordReturnsTrue()
{
- var res = await Table.InsertAsync(GetTuple(1, "1"));
+ var res = await Table.InsertAsync(null, GetTuple(1, "1"));
Assert.IsTrue(res);
- Assert.IsTrue(await Table.GetAsync(GetTuple(1)) != null);
+ Assert.IsTrue(await Table.GetAsync(null, GetTuple(1)) != null);
}
[Test]
public async Task TestInsertExistingKeyDoesNotOverwriteReturnsFalse()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
- var res = await Table.InsertAsync(GetTuple(1, "2"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+ var res = await Table.InsertAsync(null, GetTuple(1, "2"));
Assert.IsFalse(res);
- Assert.AreEqual("1", (await Table.GetAsync(GetTuple(1)))![1]);
+ Assert.AreEqual("1", (await Table.GetAsync(null, GetTuple(1)))![1]);
}
[Test]
public async Task TestDeleteNonExistentRecordReturnFalse()
{
- Assert.IsFalse(await Table.DeleteAsync(GetTuple(-1)));
+ Assert.IsFalse(await Table.DeleteAsync(null, GetTuple(-1)));
}
[Test]
public async Task TestDeleteExistingRecordReturnsTrue()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
- Assert.IsTrue(await Table.DeleteAsync(GetTuple(1)));
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
+ Assert.IsTrue(await Table.DeleteAsync(null, GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
}
[Test]
public async Task TestDeleteExactNonExistentRecordReturnsFalse()
{
- Assert.IsFalse(await Table.DeleteExactAsync(GetTuple(-1)));
+ Assert.IsFalse(await Table.DeleteExactAsync(null, GetTuple(-1)));
}
[Test]
public async Task TestDeleteExactExistingKeyDifferentValueReturnsFalseDoesNotDelete()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
- Assert.IsFalse(await Table.DeleteExactAsync(GetTuple(1)));
- Assert.IsFalse(await Table.DeleteExactAsync(GetTuple(1, "2")));
- Assert.IsNotNull(await Table.GetAsync(GetTuple(1)));
+ Assert.IsFalse(await Table.DeleteExactAsync(null, GetTuple(1)));
+ Assert.IsFalse(await Table.DeleteExactAsync(null, GetTuple(1, "2")));
+ Assert.IsNotNull(await Table.GetAsync(null, GetTuple(1)));
}
[Test]
public async Task TestDeleteExactSameKeyAndValueReturnsTrueDeletesRecord()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
- Assert.IsTrue(await Table.DeleteExactAsync(GetTuple(1, "1")));
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
+ Assert.IsTrue(await Table.DeleteExactAsync(null, GetTuple(1, "1")));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
}
[Test]
public async Task TestReplaceNonExistentRecordReturnsFalseDoesNotCreateRecord()
{
- bool res = await Table.ReplaceAsync(GetTuple(1, "1"));
+ bool res = await Table.ReplaceAsync(null, GetTuple(1, "1"));
Assert.IsFalse(res);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
}
[Test]
public async Task TestReplaceExistingRecordReturnsTrueOverwrites()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
- bool res = await Table.ReplaceAsync(GetTuple(1, "2"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+ bool res = await Table.ReplaceAsync(null, GetTuple(1, "2"));
Assert.IsTrue(res);
- Assert.AreEqual("2", (await Table.GetAsync(GetTuple(1)))![1]);
+ Assert.AreEqual("2", (await Table.GetAsync(null, GetTuple(1)))![1]);
}
[Test]
public async Task TestGetAndReplaceNonExistentRecordReturnsNullDoesNotCreateRecord()
{
- IIgniteTuple? res = await Table.GetAndReplaceAsync(GetTuple(1, "1"));
+ IIgniteTuple? res = await Table.GetAndReplaceAsync(null, GetTuple(1, "1"));
Assert.IsNull(res);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
}
[Test]
public async Task TestGetAndReplaceExistingRecordReturnsOldOverwrites()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
- IIgniteTuple? res = await Table.GetAndReplaceAsync(GetTuple(1, "2"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+ IIgniteTuple? res = await Table.GetAndReplaceAsync(null, GetTuple(1, "2"));
Assert.IsNotNull(res);
Assert.AreEqual("1", res![1]);
- Assert.AreEqual("2", (await Table.GetAsync(GetTuple(1)))![1]);
+ Assert.AreEqual("2", (await Table.GetAsync(null, GetTuple(1)))![1]);
}
[Test]
public async Task TestReplaceExactNonExistentRecordReturnsFalseDoesNotCreateRecord()
{
- bool res = await Table.ReplaceAsync(GetTuple(1, "1"), GetTuple(1, "2"));
+ bool res = await Table.ReplaceAsync(null, GetTuple(1, "1"), GetTuple(1, "2"));
Assert.IsFalse(res);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
}
[Test]
public async Task TestReplaceExactExistingRecordWithDifferentValueReturnsFalseDoesNotReplace()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
- bool res = await Table.ReplaceAsync(GetTuple(1, "11"), GetTuple(1, "22"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+ bool res = await Table.ReplaceAsync(null, GetTuple(1, "11"), GetTuple(1, "22"));
Assert.IsFalse(res);
- Assert.AreEqual("1", (await Table.GetAsync(GetTuple(1)))![1]);
+ Assert.AreEqual("1", (await Table.GetAsync(null, GetTuple(1)))![1]);
}
[Test]
public async Task TestReplaceExactExistingRecordWithSameValueReturnsTrueReplacesOld()
{
- await Table.UpsertAsync(GetTuple(1, "1"));
- bool res = await Table.ReplaceAsync(GetTuple(1, "1"), GetTuple(1, "22"));
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+ bool res = await Table.ReplaceAsync(null, GetTuple(1, "1"), GetTuple(1, "22"));
Assert.IsTrue(res);
- Assert.AreEqual("22", (await Table.GetAsync(GetTuple(1)))![1]);
+ Assert.AreEqual("22", (await Table.GetAsync(null, GetTuple(1)))![1]);
}
[Test]
@@ -259,11 +252,11 @@ namespace Apache.Ignite.Tests.Table
var ids = Enumerable.Range(1, 10).ToList();
var records = ids.Select(x => GetTuple(x, x.ToString(CultureInfo.InvariantCulture)));
- await Table.UpsertAllAsync(records);
+ await Table.UpsertAllAsync(null, records);
foreach (var id in ids)
{
- var res = await Table.GetAsync(GetTuple(id));
+ var res = await Table.GetAsync(null, GetTuple(id));
Assert.AreEqual(id.ToString(CultureInfo.InvariantCulture), res![1]);
}
}
@@ -271,17 +264,17 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestUpsertAllOverwritesExistingData()
{
- await Table.InsertAsync(GetTuple(2, "x"));
- await Table.InsertAsync(GetTuple(4, "y"));
+ await Table.InsertAsync(null, GetTuple(2, "x"));
+ await Table.InsertAsync(null, GetTuple(4, "y"));
var ids = Enumerable.Range(1, 10).ToList();
var records = ids.Select(x => GetTuple(x, x.ToString(CultureInfo.InvariantCulture)));
- await Table.UpsertAllAsync(records);
+ await Table.UpsertAllAsync(null, records);
foreach (var id in ids)
{
- var res = await Table.GetAsync(GetTuple(id));
+ var res = await Table.GetAsync(null, GetTuple(id));
Assert.AreEqual(id.ToString(CultureInfo.InvariantCulture), res![1]);
}
}
@@ -292,13 +285,13 @@ namespace Apache.Ignite.Tests.Table
var ids = Enumerable.Range(1, 10).ToList();
var records = ids.Select(x => GetTuple(x, x.ToString(CultureInfo.InvariantCulture)));
- IList<IIgniteTuple> skipped = await Table.InsertAllAsync(records);
+ IList<IIgniteTuple> skipped = await Table.InsertAllAsync(null, records);
CollectionAssert.IsEmpty(skipped);
foreach (var id in ids)
{
- var res = await Table.GetAsync(GetTuple(id));
+ var res = await Table.GetAsync(null, GetTuple(id));
Assert.AreEqual(id.ToString(CultureInfo.InvariantCulture), res![1]);
}
}
@@ -307,12 +300,12 @@ namespace Apache.Ignite.Tests.Table
public async Task TestInsertAllDoesNotOverwriteExistingDataReturnsSkippedTuples()
{
var existing = new[] { GetTuple(2, "x"), GetTuple(4, "y") }.ToDictionary(x => x[0]);
- await Table.InsertAllAsync(existing.Values);
+ await Table.InsertAllAsync(null, existing.Values);
var ids = Enumerable.Range(1, 10).ToList();
var records = ids.Select(x => GetTuple(x, x.ToString(CultureInfo.InvariantCulture)));
- IList<IIgniteTuple> skipped = await Table.InsertAllAsync(records);
+ IList<IIgniteTuple> skipped = await Table.InsertAllAsync(null, records);
var skippedArr = skipped.OrderBy(x => x[0]).ToArray();
Assert.AreEqual(2, skippedArr.Length);
@@ -324,7 +317,7 @@ namespace Apache.Ignite.Tests.Table
foreach (var id in ids)
{
- var res = await Table.GetAsync(GetTuple(id));
+ var res = await Table.GetAsync(null, GetTuple(id));
if (existing.TryGetValue(res![0], out var old))
{
@@ -340,14 +333,14 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestInsertAllEmptyCollectionDoesNothingReturnsEmptyList()
{
- var res = await Table.InsertAllAsync(Array.Empty<IIgniteTuple>());
+ var res = await Table.InsertAllAsync(null, Array.Empty<IIgniteTuple>());
CollectionAssert.IsEmpty(res);
}
[Test]
public async Task TestUpsertAllEmptyCollectionDoesNothing()
{
- await Table.UpsertAllAsync(Array.Empty<IIgniteTuple>());
+ await Table.UpsertAllAsync(null, Array.Empty<IIgniteTuple>());
}
[Test]
@@ -357,10 +350,10 @@ namespace Apache.Ignite.Tests.Table
.Range(1, 10)
.Select(x => GetTuple(x, x.ToString(CultureInfo.InvariantCulture)));
- await Table.UpsertAllAsync(records);
+ await Table.UpsertAllAsync(null, records);
// TODO: Key order should be preserved by the server (IGNITE-16004).
- var res = await Table.GetAllAsync(Enumerable.Range(9, 4).Select(x => GetTuple(x)));
+ var res = await Table.GetAllAsync(null, Enumerable.Range(9, 4).Select(x => GetTuple(x)));
var resArr = res.OrderBy(x => x?[0]).ToArray();
Assert.AreEqual(2, res.Count);
@@ -375,7 +368,7 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestGetAllNonExistentKeysReturnsEmptyList()
{
- var res = await Table.GetAllAsync(new[] { GetTuple(-100) });
+ var res = await Table.GetAllAsync(null, new[] { GetTuple(-100) });
Assert.AreEqual(0, res.Count);
}
@@ -383,7 +376,7 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestGetAllEmptyKeysReturnsEmptyList()
{
- var res = await Table.GetAllAsync(Array.Empty<IIgniteTuple>());
+ var res = await Table.GetAllAsync(null, Array.Empty<IIgniteTuple>());
Assert.AreEqual(0, res.Count);
}
@@ -391,7 +384,7 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestDeleteAllEmptyKeysReturnsEmptyList()
{
- var skipped = await Table.DeleteAllAsync(Array.Empty<IIgniteTuple>());
+ var skipped = await Table.DeleteAllAsync(null, Array.Empty<IIgniteTuple>());
Assert.AreEqual(0, skipped.Count);
}
@@ -399,7 +392,7 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestDeleteAllNonExistentKeysReturnsAllKeys()
{
- var skipped = await Table.DeleteAllAsync(new[] { GetTuple(1), GetTuple(2) });
+ var skipped = await Table.DeleteAllAsync(null, new[] { GetTuple(1), GetTuple(2) });
Assert.AreEqual(2, skipped.Count);
}
@@ -407,31 +400,31 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestDeleteAllExistingKeysReturnsEmptyListRemovesRecords()
{
- await Table.UpsertAllAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2") });
- var skipped = await Table.DeleteAllAsync(new[] { GetTuple(1), GetTuple(2) });
+ await Table.UpsertAllAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2") });
+ var skipped = await Table.DeleteAllAsync(null, new[] { GetTuple(1), GetTuple(2) });
Assert.AreEqual(0, skipped.Count);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
- Assert.IsNull(await Table.GetAsync(GetTuple(2)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(2)));
}
[Test]
public async Task TestDeleteAllRemovesExistingRecordsReturnsNonExistentKeys()
{
- await Table.UpsertAllAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2"), GetTuple(3, "3") });
- var skipped = await Table.DeleteAllAsync(new[] { GetTuple(1), GetTuple(2), GetTuple(4) });
+ await Table.UpsertAllAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2"), GetTuple(3, "3") });
+ var skipped = await Table.DeleteAllAsync(null, new[] { GetTuple(1), GetTuple(2), GetTuple(4) });
Assert.AreEqual(1, skipped.Count);
Assert.AreEqual(4, skipped[0][0]);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
- Assert.IsNull(await Table.GetAsync(GetTuple(2)));
- Assert.IsNotNull(await Table.GetAsync(GetTuple(3)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(2)));
+ Assert.IsNotNull(await Table.GetAsync(null, GetTuple(3)));
}
[Test]
public async Task TestDeleteAllExactNonExistentKeysReturnsAllKeys()
{
- var skipped = await Table.DeleteAllExactAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2") });
+ var skipped = await Table.DeleteAllExactAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2") });
Assert.AreEqual(2, skipped.Count);
CollectionAssert.AreEquivalent(new long[] { 1, 2 }, skipped.Select(x => (long)x[0]!).ToArray());
@@ -440,8 +433,8 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestDeleteAllExactExistingKeysDifferentValuesReturnsAllKeysDoesNotRemove()
{
- await Table.UpsertAllAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2") });
- var skipped = await Table.DeleteAllExactAsync(new[] { GetTuple(1, "11"), GetTuple(2, "x") });
+ await Table.UpsertAllAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2") });
+ var skipped = await Table.DeleteAllExactAsync(null, new[] { GetTuple(1, "11"), GetTuple(2, "x") });
Assert.AreEqual(2, skipped.Count);
}
@@ -449,31 +442,31 @@ namespace Apache.Ignite.Tests.Table
[Test]
public async Task TestDeleteAllExactExistingKeysReturnsEmptyListRemovesRecords()
{
- await Table.UpsertAllAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2") });
- var skipped = await Table.DeleteAllExactAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2") });
+ await Table.UpsertAllAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2") });
+ var skipped = await Table.DeleteAllExactAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2") });
Assert.AreEqual(0, skipped.Count);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
- Assert.IsNull(await Table.GetAsync(GetTuple(2)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(2)));
}
[Test]
public async Task TestDeleteAllExactRemovesExistingRecordsReturnsNonExistentKeys()
{
- await Table.UpsertAllAsync(new[] { GetTuple(1, "1"), GetTuple(2, "2"), GetTuple(3, "3") });
- var skipped = await Table.DeleteAllExactAsync(new[] { GetTuple(1, "1"), GetTuple(2, "22") });
+ await Table.UpsertAllAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "2"), GetTuple(3, "3") });
+ var skipped = await Table.DeleteAllExactAsync(null, new[] { GetTuple(1, "1"), GetTuple(2, "22") });
Assert.AreEqual(1, skipped.Count);
- Assert.IsNull(await Table.GetAsync(GetTuple(1)));
- Assert.IsNotNull(await Table.GetAsync(GetTuple(2)));
- Assert.IsNotNull(await Table.GetAsync(GetTuple(3)));
+ Assert.IsNull(await Table.GetAsync(null, GetTuple(1)));
+ Assert.IsNotNull(await Table.GetAsync(null, GetTuple(2)));
+ Assert.IsNotNull(await Table.GetAsync(null, GetTuple(3)));
}
[Test]
public void TestUpsertAllThrowsArgumentExceptionOnNullCollectionElement()
{
var ex = Assert.ThrowsAsync<ArgumentException>(
- async () => await Table.UpsertAllAsync(new[] { GetTuple(1, "1"), null! }));
+ async () => await Table.UpsertAllAsync(null, new[] { GetTuple(1, "1"), null! }));
Assert.AreEqual("Tuple collection can't contain null elements.", ex!.Message);
}
@@ -482,7 +475,7 @@ namespace Apache.Ignite.Tests.Table
public void TestGetAllThrowsArgumentExceptionOnNullCollectionElement()
{
var ex = Assert.ThrowsAsync<ArgumentException>(
- async () => await Table.GetAllAsync(new[] { GetTuple(1, "1"), null! }));
+ async () => await Table.GetAllAsync(null, new[] { GetTuple(1, "1"), null! }));
Assert.AreEqual("Tuple collection can't contain null elements.", ex!.Message);
}
@@ -491,7 +484,7 @@ namespace Apache.Ignite.Tests.Table
public void TestDeleteAllThrowsArgumentExceptionOnNullCollectionElement()
{
var ex = Assert.ThrowsAsync<ArgumentException>(
- async () => await Table.DeleteAllAsync(new[] { GetTuple(1, "1"), null! }));
+ async () => await Table.DeleteAllAsync(null, new[] { GetTuple(1, "1"), null! }));
Assert.AreEqual("Tuple collection can't contain null elements.", ex!.Message);
}
@@ -526,18 +519,15 @@ namespace Apache.Ignite.Tests.Table
{
var val = key.ToString(CultureInfo.InvariantCulture);
var tuple = new IgniteTuple { [KeyCol] = key, [ValCol] = val };
- await Table.UpsertAsync(tuple);
+ await Table.UpsertAsync(null, tuple);
var keyTuple = new IgniteTuple { [KeyCol] = key };
- var resTuple = (await Table.GetAsync(keyTuple))!;
+ var resTuple = (await Table.GetAsync(null, keyTuple))!;
Assert.IsNotNull(resTuple);
Assert.AreEqual(2, resTuple.FieldCount);
Assert.AreEqual(key, resTuple["key"]);
Assert.AreEqual(val, resTuple["val"]);
}
-
- private static IIgniteTuple GetTuple(int id, string? val = null) =>
- new IgniteTuple { [KeyCol] = id, [ValCol] = val };
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/TestEventListener.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/TestEventListener.cs
new file mode 100644
index 0000000..1d64f62
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/TestEventListener.cs
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Tests
+{
+ using System.Diagnostics.Tracing;
+ using System.Threading;
+
+ /// <summary>
+ /// Diagnostic event listener for tests.
+ /// </summary>
+ internal class TestEventListener : EventListener
+ {
+ private int _buffersRented;
+
+ private int _buffersReturned;
+
+ public int BuffersRented => Interlocked.CompareExchange(ref _buffersRented, -1, -1);
+
+ public int BuffersReturned => Interlocked.CompareExchange(ref _buffersRented, -1, -1);
+
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ base.OnEventSourceCreated(eventSource);
+
+ if (eventSource.Name == "System.Buffers.ArrayPoolEventSource")
+ {
+ EnableEvents(eventSource, EventLevel.Verbose);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ switch (eventData.EventName)
+ {
+ case "BufferRented":
+ Interlocked.Increment(ref _buffersRented);
+ break;
+
+ case "BufferReturned":
+ Interlocked.Increment(ref _buffersReturned);
+ break;
+ }
+
+ base.OnEventWritten(eventData);
+ }
+ }
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
new file mode 100644
index 0000000..3da2409
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Transactions/TransactionsTests.cs
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Tests.Transactions
+{
+ using System.Linq;
+ using System.Threading.Tasks;
+ using System.Transactions;
+ using Ignite.Transactions;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests for <see cref="ITransactions"/> and <see cref="ITransaction"/>.
+ /// </summary>
+ public class TransactionsTests : IgniteTestsBase
+ {
+ [Test]
+ public async Task TestRecordViewBinaryOperations()
+ {
+ var key = GetTuple(1);
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+
+ await using var tx = await Client.Transactions.BeginAsync();
+ await Table.UpsertAsync(tx, GetTuple(1, "22"));
+
+ Assert.IsFalse(await Table.DeleteExactAsync(tx, GetTuple(1, "1")));
+
+ Assert.IsFalse(await Table.InsertAsync(tx, GetTuple(1, "111")));
+ Assert.AreEqual(GetTuple(1, "22"), await Table.GetAsync(tx, key));
+ Assert.AreEqual(GetTuple(1, "22"), await Table.GetAndUpsertAsync(tx, GetTuple(1, "33")));
+ Assert.AreEqual(GetTuple(1, "33"), await Table.GetAndReplaceAsync(tx, GetTuple(1, "44")));
+ Assert.IsTrue(await Table.ReplaceAsync(tx, GetTuple(1, "55")));
+ Assert.AreEqual(GetTuple(1, "55"), await Table.GetAndDeleteAsync(tx, key));
+ Assert.IsFalse(await Table.DeleteAsync(tx, key));
+
+ await Table.UpsertAllAsync(tx, new[] { GetTuple(1, "6"), GetTuple(2, "7") });
+ Assert.AreEqual(2, (await Table.GetAllAsync(tx, new[] { key, GetTuple(2), GetTuple(3) })).Count);
+
+ var insertAllRes = await Table.InsertAllAsync(tx, new[] { GetTuple(1, "8"), GetTuple(3, "9") });
+ Assert.AreEqual(GetTuple(1, "6"), await Table.GetAsync(tx, key));
+ Assert.AreEqual(GetTuple(1, "8"), insertAllRes.Single());
+
+ Assert.IsFalse(await Table.ReplaceAsync(tx, GetTuple(-1)));
+ Assert.IsTrue(await Table.ReplaceAsync(tx, GetTuple(1, "10")));
+ Assert.AreEqual(GetTuple(1, "10"), await Table.GetAsync(tx, key));
+
+ Assert.IsFalse(await Table.ReplaceAsync(tx, GetTuple(1, "1"), GetTuple(1, "11")));
+ Assert.IsTrue(await Table.ReplaceAsync(tx, GetTuple(1, "10"), GetTuple(1, "12")));
+ Assert.AreEqual(GetTuple(1, "12"), await Table.GetAsync(tx, key));
+
+ var deleteAllRes = await Table.DeleteAllAsync(tx, new[] { GetTuple(3), GetTuple(4) });
+ Assert.AreEqual(4, deleteAllRes.Single()[0]);
+ Assert.IsNull(await Table.GetAsync(tx, GetTuple(3)));
+
+ var deleteAllExactRes = await Table.DeleteAllAsync(tx, new[] { GetTuple(1, "12"), GetTuple(5) });
+ Assert.AreEqual(5, deleteAllExactRes.Single()[0]);
+ Assert.IsNull(await Table.GetAsync(tx, key));
+
+ await tx.RollbackAsync();
+ Assert.AreEqual(GetTuple(1, "1"), await Table.GetAsync(null, key));
+ }
+
+ [Test]
+ public async Task TestCommitUpdatesData()
+ {
+ await using var tx = await Client.Transactions.BeginAsync();
+ await Table.UpsertAsync(tx, GetTuple(1, "2"));
+ await tx.CommitAsync();
+
+ var res = await Table.GetAsync(null, GetTuple(1));
+ Assert.AreEqual("2", res![ValCol]);
+ }
+
+ [Test]
+ public async Task TestRollbackDoesNotUpdateData()
+ {
+ await using var tx = await Client.Transactions.BeginAsync();
+ await Table.UpsertAsync(tx, GetTuple(1, "2"));
+ await tx.RollbackAsync();
+
+ var res = await Table.GetAsync(null, GetTuple(1));
+ Assert.IsNull(res);
+ }
+
+ [Test]
+ public async Task TestDisposeDoesNotUpdateData()
+ {
+ await using (var tx = await Client.Transactions.BeginAsync())
+ {
+ await Table.UpsertAsync(tx, GetTuple(1, "2"));
+ await tx.RollbackAsync();
+ }
+
+ var res = await Table.GetAsync(null, GetTuple(1));
+ Assert.IsNull(res);
+ }
+
+ [Test]
+ public async Task TestCommitRollbackSameTxThrows()
+ {
+ await using var tx = await Client.Transactions.BeginAsync();
+ await tx.CommitAsync();
+
+ var ex = Assert.ThrowsAsync<TransactionException>(async () => await tx.RollbackAsync());
+ Assert.AreEqual("Transaction is already committed.", ex?.Message);
+ }
+
+ [Test]
+ public async Task TestRollbackCommitSameTxThrows()
+ {
+ await using var tx = await Client.Transactions.BeginAsync();
+ await tx.RollbackAsync();
+
+ var ex = Assert.ThrowsAsync<TransactionException>(async () => await tx.CommitAsync());
+ Assert.AreEqual("Transaction is already rolled back.", ex?.Message);
+ }
+
+ [Test]
+ public async Task TestMultipleDisposeIsAllowed()
+ {
+ var tx = await Client.Transactions.BeginAsync();
+
+ await tx.DisposeAsync();
+ await tx.DisposeAsync();
+
+ var ex = Assert.ThrowsAsync<TransactionException>(async () => await tx.CommitAsync());
+ Assert.AreEqual("Transaction is already rolled back.", ex?.Message);
+ }
+
+ [Test]
+ public void TestCustomTransactionInterfaceThrows()
+ {
+ var ex = Assert.ThrowsAsync<TransactionException>(
+ async () => await Table.UpsertAsync(new CustomTx(), GetTuple(1, "2")));
+
+ StringAssert.StartsWith("Unsupported transaction implementation", ex?.Message);
+ }
+
+ [Test]
+ public async Task TestClientDisconnectClosesActiveTransactions()
+ {
+ await Table.UpsertAsync(null, GetTuple(1, "1"));
+
+ using (var client2 = await IgniteClient.StartAsync(GetConfig()))
+ {
+ var table = await client2.Tables.GetTableAsync(TableName);
+ var tx = await client2.Transactions.BeginAsync();
+
+ await table!.RecordView.UpsertAsync(tx, GetTuple(1, "2"));
+ }
+
+ Assert.AreEqual("1", (await Table.GetAsync(null, GetTuple(1)))![ValCol]);
+ }
+
+ [Test]
+ public async Task TestTransactionFromAnotherClientThrows()
+ {
+ using var client2 = await IgniteClient.StartAsync(GetConfig());
+ await using var tx = await client2.Transactions.BeginAsync();
+
+ var ex = Assert.ThrowsAsync<IgniteClientException>(async () => await Table.UpsertAsync(tx, GetTuple(1, "2")));
+ Assert.AreEqual("Specified transaction belongs to a different IgniteClient instance.", ex!.Message);
+ }
+
+ private class CustomTx : ITransaction
+ {
+ public ValueTask DisposeAsync()
+ {
+ return new ValueTask(Task.CompletedTask);
+ }
+
+ public Task CommitAsync()
+ {
+ return Task.CompletedTask;
+ }
+
+ public Task RollbackAsync()
+ {
+ return Task.CompletedTask;
+ }
+ }
+ }
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite.sln.DotSettings b/modules/platforms/dotnet/Apache.Ignite.sln.DotSettings
index 2d165fe..b8e79e9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.sln.DotSettings
+++ b/modules/platforms/dotnet/Apache.Ignite.sln.DotSettings
@@ -16,5 +16,10 @@
-->
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+ <s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">140</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=failover/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
diff --git a/modules/platforms/dotnet/Apache.Ignite/IIgnite.cs b/modules/platforms/dotnet/Apache.Ignite/IIgnite.cs
index 185168b..9590258 100644
--- a/modules/platforms/dotnet/Apache.Ignite/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/IIgnite.cs
@@ -17,8 +17,8 @@
namespace Apache.Ignite
{
- using System;
using Table;
+ using Transactions;
/// <summary>
/// Ignite API entry point.
@@ -26,11 +26,16 @@ namespace Apache.Ignite
/// Implementation can be a thin client (see <see cref="IIgniteClient"/> and <see cref="IgniteClient.StartAsync"/>),
/// or a direct IPC connection for server-side functionality like compute.
/// </summary>
- public interface IIgnite : IDisposable
+ public interface IIgnite
{
/// <summary>
/// Gets the tables API.
/// </summary>
ITables Tables { get; }
+
+ /// <summary>
+ /// Gets the transactions API.
+ /// </summary>
+ ITransactions Transactions { get; }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs b/modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs
index ae5c09b..83b3020 100644
--- a/modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs
@@ -17,12 +17,14 @@
namespace Apache.Ignite
{
+ using System;
+
/// <summary>
/// Ignite client.
/// <para />
/// Extends <see cref="IIgnite"/> with client-specific functionality.
/// </summary>
- public interface IIgniteClient : IIgnite
+ public interface IIgniteClient : IIgnite, IDisposable
{
/// <summary>
/// Gets the configuration.
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs
index d5300e0..ec025a8 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientFailoverSocket.cs
@@ -129,7 +129,7 @@ namespace Apache.Ignite.Internal
/// Gets the primary socket. Reconnects if necessary.
/// </summary>
/// <returns>Client socket.</returns>
- private async ValueTask<ClientSocket> GetSocketAsync()
+ public async ValueTask<ClientSocket> GetSocketAsync()
{
await _socketLock.WaitAsync().ConfigureAwait(false);
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
index 7fdbea3..9d497e6 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/ClientSocket.cs
@@ -139,7 +139,7 @@ namespace Apache.Ignite.Internal
/// <param name="clientOp">Client op code.</param>
/// <param name="request">Request data.</param>
/// <returns>Response data.</returns>
- public Task<PooledBuffer> DoOutInOpAsync(ClientOp clientOp, PooledArrayBufferWriter? request)
+ public Task<PooledBuffer> DoOutInOpAsync(ClientOp clientOp, PooledArrayBufferWriter? request = null)
{
if (_disposeTokenSource.IsCancellationRequested)
{
@@ -399,6 +399,7 @@ namespace Apache.Ignite.Internal
if (exception != null)
{
+ response.Dispose();
taskCompletionSource.SetException(exception);
}
else
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs
index ab9ccdd..a59b0c2 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs
@@ -18,6 +18,7 @@
namespace Apache.Ignite.Internal
{
using Ignite.Table;
+ using Ignite.Transactions;
using Table;
/// <summary>
@@ -36,6 +37,7 @@ namespace Apache.Ignite.Internal
{
_socket = socket;
Tables = new Tables(socket);
+ Transactions = new Transactions.Transactions(socket);
}
/// <inheritdoc/>
@@ -46,6 +48,9 @@ namespace Apache.Ignite.Internal
public ITables Tables { get; }
/// <inheritdoc/>
+ public ITransactions Transactions { get; }
+
+ /// <inheritdoc/>
public void Dispose()
{
_socket.Dispose();
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Proto/ClientOp.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Proto/ClientOp.cs
index f4960ac..9998af6 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Proto/ClientOp.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Proto/ClientOp.cs
@@ -81,5 +81,14 @@ namespace Apache.Ignite.Internal.Proto
/** Get and delete tuple. */
TupleGetAndDelete = 32,
+
+ /** Begin transaction. */
+ TxBegin = 43,
+
+ /** Commit transaction. */
+ TxCommit = 44,
+
+ /** Rollback transaction. */
+ TxRollback = 45
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordBinaryView.cs
similarity index 65%
copy from modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs
copy to modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordBinaryView.cs
index 690a1aa..9b6c36f 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/RecordBinaryView.cs
@@ -22,19 +22,21 @@ namespace Apache.Ignite.Internal.Table
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
+ using System.Transactions;
using Buffers;
using Common;
using Ignite.Table;
+ using Ignite.Transactions;
using MessagePack;
using Proto;
/// <summary>
/// Table API.
/// </summary>
- internal class Table : ITable
+ internal class RecordBinaryView : IRecordView<IIgniteTuple>
{
- /** Socket. */
- private readonly ClientFailoverSocket _socket;
+ /** Table. */
+ private readonly Table _table;
/** Schemas. */
private readonly ConcurrentDictionary<int, Schema> _schemas = new();
@@ -46,44 +48,27 @@ namespace Apache.Ignite.Internal.Table
private volatile int _latestSchemaVersion = -1;
/// <summary>
- /// Initializes a new instance of the <see cref="Table"/> class.
+ /// Initializes a new instance of the <see cref="RecordBinaryView"/> class.
/// </summary>
- /// <param name="name">Table name.</param>
- /// <param name="id">Table id.</param>
- /// <param name="socket">Socket.</param>
- public Table(string name, IgniteUuid id, ClientFailoverSocket socket)
+ /// <param name="table">Table.</param>
+ public RecordBinaryView(Table table)
{
- _socket = socket;
- Name = name;
- Id = id;
+ _table = table;
}
/// <inheritdoc/>
- public string Name { get; }
-
- /// <summary>
- /// Gets the id.
- /// </summary>
- public IgniteUuid Id { get; }
-
- /// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAsync(IIgniteTuple key)
+ public async Task<IIgniteTuple?> GetAsync(ITransaction? transaction, IIgniteTuple key)
{
IgniteArgumentCheck.NotNull(key, nameof(key));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, key, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGet, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleGet, transaction, key, keyOnly: true).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
return ReadValueTuple(resBuf, resSchema, key);
}
/// <inheritdoc/>
- public async Task<IList<IIgniteTuple?>> GetAllAsync(IEnumerable<IIgniteTuple> keys)
+ public async Task<IList<IIgniteTuple?>> GetAllAsync(ITransaction? transaction, IEnumerable<IIgniteTuple> keys)
{
IgniteArgumentCheck.NotNull(keys, nameof(keys));
@@ -95,32 +80,28 @@ namespace Apache.Ignite.Internal.Table
}
var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator, keyOnly: true);
+ WriteTuples(writer, tx, schema, iterator, keyOnly: true);
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAll, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoOutInOpAsync(ClientOp.TupleGetAll, tx, writer).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
// TODO: Read value parts only (IGNITE-16022).
return ReadTuplesNullable(resBuf, resSchema);
}
/// <inheritdoc/>
- public async Task UpsertAsync(IIgniteTuple record)
+ public async Task UpsertAsync(ITransaction? transaction, IIgniteTuple record)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleUpsert, writer).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleUpsert, transaction, record).ConfigureAwait(false);
}
/// <inheritdoc/>
- public async Task UpsertAllAsync(IEnumerable<IIgniteTuple> records)
+ public async Task UpsertAllAsync(ITransaction? transaction, IEnumerable<IIgniteTuple> records)
{
IgniteArgumentCheck.NotNull(records, nameof(records));
@@ -132,45 +113,36 @@ namespace Apache.Ignite.Internal.Table
}
var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator);
+ WriteTuples(writer, tx, schema, iterator);
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleUpsertAll, writer).ConfigureAwait(false);
+ using var resBuf = await DoOutInOpAsync(ClientOp.TupleUpsertAll, tx, writer).ConfigureAwait(false);
}
/// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAndUpsertAsync(IIgniteTuple record)
+ public async Task<IIgniteTuple?> GetAndUpsertAsync(ITransaction? transaction, IIgniteTuple record)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAndUpsert, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleGetAndUpsert, transaction, record).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
return ReadValueTuple(resBuf, resSchema, record);
}
/// <inheritdoc/>
- public async Task<bool> InsertAsync(IIgniteTuple record)
+ public async Task<bool> InsertAsync(ITransaction? transaction, IIgniteTuple record)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleInsert, writer).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleInsert, transaction, record).ConfigureAwait(false);
return resBuf.GetReader().ReadBoolean();
}
/// <inheritdoc/>
- public async Task<IList<IIgniteTuple>> InsertAllAsync(IEnumerable<IIgniteTuple> records)
+ public async Task<IList<IIgniteTuple>> InsertAllAsync(ITransaction? transaction, IEnumerable<IIgniteTuple> records)
{
IgniteArgumentCheck.NotNull(records, nameof(records));
@@ -182,107 +154,84 @@ namespace Apache.Ignite.Internal.Table
}
var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator);
+ WriteTuples(writer, tx, schema, iterator);
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleInsertAll, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoOutInOpAsync(ClientOp.TupleInsertAll, tx, writer).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
// TODO: Read value parts only (IGNITE-16022).
return ReadTuples(resBuf, resSchema);
}
/// <inheritdoc/>
- public async Task<bool> ReplaceAsync(IIgniteTuple record)
+ public async Task<bool> ReplaceAsync(ITransaction? transaction, IIgniteTuple record)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleReplace, writer).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleReplace, transaction, record).ConfigureAwait(false);
return resBuf.GetReader().ReadBoolean();
}
/// <inheritdoc/>
- public async Task<bool> ReplaceAsync(IIgniteTuple record, IIgniteTuple newRecord)
+ public async Task<bool> ReplaceAsync(ITransaction? transaction, IIgniteTuple record, IIgniteTuple newRecord)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, record, newRecord);
+ WriteTuples(writer, tx, schema, record, newRecord);
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleReplaceExact, writer).ConfigureAwait(false);
+ using var resBuf = await DoOutInOpAsync(ClientOp.TupleReplaceExact, tx, writer).ConfigureAwait(false);
return resBuf.GetReader().ReadBoolean();
}
/// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAndReplaceAsync(IIgniteTuple record)
+ public async Task<IIgniteTuple?> GetAndReplaceAsync(ITransaction? transaction, IIgniteTuple record)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAndReplace, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleGetAndReplace, transaction, record).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
return ReadValueTuple(resBuf, resSchema, record);
}
/// <inheritdoc/>
- public async Task<bool> DeleteAsync(IIgniteTuple key)
+ public async Task<bool> DeleteAsync(ITransaction? transaction, IIgniteTuple key)
{
IgniteArgumentCheck.NotNull(key, nameof(key));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, key, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDelete, writer).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleDelete, transaction, key, keyOnly: true).ConfigureAwait(false);
return resBuf.GetReader().ReadBoolean();
}
/// <inheritdoc/>
- public async Task<bool> DeleteExactAsync(IIgniteTuple record)
+ public async Task<bool> DeleteExactAsync(ITransaction? transaction, IIgniteTuple record)
{
IgniteArgumentCheck.NotNull(record, nameof(record));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDeleteExact, writer).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleDeleteExact, transaction, record).ConfigureAwait(false);
return resBuf.GetReader().ReadBoolean();
}
/// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAndDeleteAsync(IIgniteTuple key)
+ public async Task<IIgniteTuple?> GetAndDeleteAsync(ITransaction? transaction, IIgniteTuple key)
{
IgniteArgumentCheck.NotNull(key, nameof(key));
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, key, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAndDelete, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoTupleOutOpAsync(ClientOp.TupleGetAndDelete, transaction, key, keyOnly: true).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
return ReadValueTuple(resBuf, resSchema, key);
}
/// <inheritdoc/>
- public async Task<IList<IIgniteTuple>> DeleteAllAsync(IEnumerable<IIgniteTuple> keys)
+ public async Task<IList<IIgniteTuple>> DeleteAllAsync(ITransaction? transaction, IEnumerable<IIgniteTuple> keys)
{
IgniteArgumentCheck.NotNull(keys, nameof(keys));
@@ -294,19 +243,20 @@ namespace Apache.Ignite.Internal.Table
}
var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator, keyOnly: true);
+ WriteTuples(writer, tx, schema, iterator, keyOnly: true);
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDeleteAll, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoOutInOpAsync(ClientOp.TupleDeleteAll, tx, writer).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
// TODO: Read value parts only (IGNITE-16022).
return ReadTuples(resBuf, resSchema, keyOnly: true);
}
/// <inheritdoc/>
- public async Task<IList<IIgniteTuple>> DeleteAllExactAsync(IEnumerable<IIgniteTuple> records)
+ public async Task<IList<IIgniteTuple>> DeleteAllExactAsync(ITransaction? transaction, IEnumerable<IIgniteTuple> records)
{
IgniteArgumentCheck.NotNull(records, nameof(records));
@@ -318,12 +268,13 @@ namespace Apache.Ignite.Internal.Table
}
var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator);
+ WriteTuples(writer, tx, schema, iterator);
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDeleteAllExact, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
+ using var resBuf = await DoOutInOpAsync(ClientOp.TupleDeleteAllExact, tx, writer).ConfigureAwait(false);
+ var resSchema = await ReadSchemaAsync(resBuf).ConfigureAwait(false);
return ReadTuples(resBuf, resSchema);
}
@@ -462,18 +413,40 @@ namespace Apache.Ignite.Internal.Table
}
}
- private async ValueTask<Schema?> ReadSchemaAsync(PooledBuffer buf, Schema currentSchema)
+ private static Transactions.Transaction? GetTx(ITransaction? tx)
{
- var ver = ReadSchemaVersion(buf);
-
- if (ver == null)
+ if (tx == null)
{
return null;
}
- if (currentSchema.Version == ver.Value)
+ if (tx is Transactions.Transaction t)
{
- return currentSchema;
+ return t;
+ }
+
+ throw new TransactionException("Unsupported transaction implementation: " + tx.GetType());
+ }
+
+ private static void WriteTx(ref MessagePackWriter w, Transactions.Transaction? tx)
+ {
+ if (tx == null)
+ {
+ w.WriteNil();
+ }
+ else
+ {
+ w.WriteInt64(tx.Id);
+ }
+ }
+
+ private async ValueTask<Schema?> ReadSchemaAsync(PooledBuffer buf)
+ {
+ var ver = ReadSchemaVersion(buf);
+
+ if (ver == null)
+ {
+ return null;
}
if (_schemas.TryGetValue(ver.Value, out var res))
@@ -501,13 +474,13 @@ namespace Apache.Ignite.Internal.Table
using var writer = new PooledArrayBufferWriter();
Write();
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.SchemasGet, writer).ConfigureAwait(false);
+ using var resBuf = await _table.Socket.DoOutInOpAsync(ClientOp.SchemasGet, writer).ConfigureAwait(false);
return Read();
void Write()
{
var w = writer.GetMessageWriter();
- w.Write(Id);
+ w.Write(_table.Id);
if (version == null)
{
@@ -592,17 +565,23 @@ namespace Apache.Ignite.Internal.Table
return schema;
}
- private void WriteTuple(PooledArrayBufferWriter buf, Schema schema, IIgniteTuple tuple, bool keyOnly = false)
+ private void WriteTuple(
+ PooledArrayBufferWriter buf,
+ Transactions.Transaction? tx,
+ Schema schema,
+ IIgniteTuple tuple,
+ bool keyOnly = false)
{
var w = buf.GetMessageWriter();
- WriteTupleWithHeader(ref w, schema, tuple, keyOnly);
+ WriteTupleWithHeader(ref w, tx, schema, tuple, keyOnly);
w.Flush();
}
private void WriteTuples(
PooledArrayBufferWriter buf,
+ Transactions.Transaction? tx,
Schema schema,
IIgniteTuple t,
IIgniteTuple t2,
@@ -610,7 +589,7 @@ namespace Apache.Ignite.Internal.Table
{
var w = buf.GetMessageWriter();
- WriteTupleWithHeader(ref w, schema, t, keyOnly);
+ WriteTupleWithHeader(ref w, tx, schema, t, keyOnly);
WriteTuple(ref w, schema, t2, keyOnly);
w.Flush();
@@ -618,14 +597,15 @@ namespace Apache.Ignite.Internal.Table
private void WriteTuples(
PooledArrayBufferWriter buf,
+ Transactions.Transaction? tx,
Schema schema,
IEnumerator<IIgniteTuple> tuples,
bool keyOnly = false)
{
var w = buf.GetMessageWriter();
- w.Write(Id);
- w.WriteNil(); // Transaction ID (TODO: IGNITE-16208).
+ w.Write(_table.Id);
+ WriteTx(ref w, tx);
w.Write(schema.Version);
w.Flush();
@@ -653,15 +633,56 @@ namespace Apache.Ignite.Internal.Table
private void WriteTupleWithHeader(
ref MessagePackWriter w,
+ Transactions.Transaction? tx,
Schema schema,
IIgniteTuple tuple,
bool keyOnly = false)
{
- w.Write(Id);
- w.WriteNil(); // Transaction ID (TODO: IGNITE-16208).
+ w.Write(_table.Id);
+ WriteTx(ref w, tx);
w.Write(schema.Version);
WriteTuple(ref w, schema, tuple, keyOnly);
}
+
+ private ValueTask<ClientSocket> GetSocket(Transactions.Transaction? tx)
+ {
+ if (tx == null)
+ {
+ return _table.Socket.GetSocketAsync();
+ }
+
+ if (tx.FailoverSocket != _table.Socket)
+ {
+ throw new IgniteClientException("Specified transaction belongs to a different IgniteClient instance.");
+ }
+
+ return new ValueTask<ClientSocket>(tx.Socket);
+ }
+
+ private async Task<PooledBuffer> DoOutInOpAsync(
+ ClientOp clientOp,
+ Transactions.Transaction? tx,
+ PooledArrayBufferWriter? request = null)
+ {
+ var socket = await GetSocket(tx).ConfigureAwait(false);
+
+ return await socket.DoOutInOpAsync(clientOp, request).ConfigureAwait(false);
+ }
+
+ private async Task<PooledBuffer> DoTupleOutOpAsync(
+ ClientOp op,
+ ITransaction? transaction,
+ IIgniteTuple tuple,
+ bool keyOnly = false)
+ {
+ var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
+ var tx = GetTx(transaction);
+
+ using var writer = new PooledArrayBufferWriter();
+ WriteTuple(writer, tx, schema, tuple, keyOnly);
+
+ return await DoOutInOpAsync(op, tx, writer).ConfigureAwait(false);
+ }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs
index 690a1aa..83770a8 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Table.cs
@@ -17,15 +17,7 @@
namespace Apache.Ignite.Internal.Table
{
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Threading.Tasks;
- using Buffers;
- using Common;
using Ignite.Table;
- using MessagePack;
using Proto;
/// <summary>
@@ -33,18 +25,6 @@ namespace Apache.Ignite.Internal.Table
/// </summary>
internal class Table : ITable
{
- /** Socket. */
- private readonly ClientFailoverSocket _socket;
-
- /** Schemas. */
- private readonly ConcurrentDictionary<int, Schema> _schemas = new();
-
- /** */
- private readonly object _latestSchemaLock = new();
-
- /** */
- private volatile int _latestSchemaVersion = -1;
-
/// <summary>
/// Initializes a new instance of the <see cref="Table"/> class.
/// </summary>
@@ -53,615 +33,27 @@ namespace Apache.Ignite.Internal.Table
/// <param name="socket">Socket.</param>
public Table(string name, IgniteUuid id, ClientFailoverSocket socket)
{
- _socket = socket;
+ Socket = socket;
Name = name;
Id = id;
+
+ RecordView = new RecordBinaryView(this);
}
/// <inheritdoc/>
public string Name { get; }
+ /// <inheritdoc/>
+ public IRecordView<IIgniteTuple> RecordView { get; }
+
/// <summary>
/// Gets the id.
/// </summary>
- public IgniteUuid Id { get; }
-
- /// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAsync(IIgniteTuple key)
- {
- IgniteArgumentCheck.NotNull(key, nameof(key));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, key, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGet, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- return ReadValueTuple(resBuf, resSchema, key);
- }
-
- /// <inheritdoc/>
- public async Task<IList<IIgniteTuple?>> GetAllAsync(IEnumerable<IIgniteTuple> keys)
- {
- IgniteArgumentCheck.NotNull(keys, nameof(keys));
-
- using var iterator = keys.GetEnumerator();
-
- if (!iterator.MoveNext())
- {
- return Array.Empty<IIgniteTuple>();
- }
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAll, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- // TODO: Read value parts only (IGNITE-16022).
- return ReadTuplesNullable(resBuf, resSchema);
- }
-
- /// <inheritdoc/>
- public async Task UpsertAsync(IIgniteTuple record)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleUpsert, writer).ConfigureAwait(false);
- }
-
- /// <inheritdoc/>
- public async Task UpsertAllAsync(IEnumerable<IIgniteTuple> records)
- {
- IgniteArgumentCheck.NotNull(records, nameof(records));
-
- using var iterator = records.GetEnumerator();
-
- if (!iterator.MoveNext())
- {
- return;
- }
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleUpsertAll, writer).ConfigureAwait(false);
- }
-
- /// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAndUpsertAsync(IIgniteTuple record)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAndUpsert, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- return ReadValueTuple(resBuf, resSchema, record);
- }
-
- /// <inheritdoc/>
- public async Task<bool> InsertAsync(IIgniteTuple record)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleInsert, writer).ConfigureAwait(false);
- return resBuf.GetReader().ReadBoolean();
- }
-
- /// <inheritdoc/>
- public async Task<IList<IIgniteTuple>> InsertAllAsync(IEnumerable<IIgniteTuple> records)
- {
- IgniteArgumentCheck.NotNull(records, nameof(records));
-
- using var iterator = records.GetEnumerator();
-
- if (!iterator.MoveNext())
- {
- return Array.Empty<IIgniteTuple>();
- }
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleInsertAll, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- // TODO: Read value parts only (IGNITE-16022).
- return ReadTuples(resBuf, resSchema);
- }
-
- /// <inheritdoc/>
- public async Task<bool> ReplaceAsync(IIgniteTuple record)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleReplace, writer).ConfigureAwait(false);
- return resBuf.GetReader().ReadBoolean();
- }
-
- /// <inheritdoc/>
- public async Task<bool> ReplaceAsync(IIgniteTuple record, IIgniteTuple newRecord)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, record, newRecord);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleReplaceExact, writer).ConfigureAwait(false);
- return resBuf.GetReader().ReadBoolean();
- }
-
- /// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAndReplaceAsync(IIgniteTuple record)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAndReplace, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- return ReadValueTuple(resBuf, resSchema, record);
- }
-
- /// <inheritdoc/>
- public async Task<bool> DeleteAsync(IIgniteTuple key)
- {
- IgniteArgumentCheck.NotNull(key, nameof(key));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, key, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDelete, writer).ConfigureAwait(false);
- return resBuf.GetReader().ReadBoolean();
- }
-
- /// <inheritdoc/>
- public async Task<bool> DeleteExactAsync(IIgniteTuple record)
- {
- IgniteArgumentCheck.NotNull(record, nameof(record));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, record);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDeleteExact, writer).ConfigureAwait(false);
- return resBuf.GetReader().ReadBoolean();
- }
-
- /// <inheritdoc/>
- public async Task<IIgniteTuple?> GetAndDeleteAsync(IIgniteTuple key)
- {
- IgniteArgumentCheck.NotNull(key, nameof(key));
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuple(writer, schema, key, keyOnly: true);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleGetAndDelete, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- return ReadValueTuple(resBuf, resSchema, key);
- }
-
- /// <inheritdoc/>
- public async Task<IList<IIgniteTuple>> DeleteAllAsync(IEnumerable<IIgniteTuple> keys)
- {
- IgniteArgumentCheck.NotNull(keys, nameof(keys));
-
- using var iterator = keys.GetEnumerator();
-
- if (!iterator.MoveNext())
- {
- return Array.Empty<IIgniteTuple>();
- }
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator, keyOnly: true);
+ internal IgniteUuid Id { get; }
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDeleteAll, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- // TODO: Read value parts only (IGNITE-16022).
- return ReadTuples(resBuf, resSchema, keyOnly: true);
- }
-
- /// <inheritdoc/>
- public async Task<IList<IIgniteTuple>> DeleteAllExactAsync(IEnumerable<IIgniteTuple> records)
- {
- IgniteArgumentCheck.NotNull(records, nameof(records));
-
- using var iterator = records.GetEnumerator();
-
- if (!iterator.MoveNext())
- {
- return Array.Empty<IIgniteTuple>();
- }
-
- var schema = await GetLatestSchemaAsync().ConfigureAwait(false);
-
- using var writer = new PooledArrayBufferWriter();
- WriteTuples(writer, schema, iterator);
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.TupleDeleteAllExact, writer).ConfigureAwait(false);
- var resSchema = await ReadSchemaAsync(resBuf, schema).ConfigureAwait(false);
-
- return ReadTuples(resBuf, resSchema);
- }
-
- private static IIgniteTuple? ReadValueTuple(PooledBuffer buf, Schema? schema, IIgniteTuple key)
- {
- if (schema == null)
- {
- return null;
- }
-
- // Skip schema version.
- var r = buf.GetReader();
- r.Skip();
-
- var columns = schema.Columns;
- var tuple = new IgniteTuple(columns.Count);
-
- for (var i = 0; i < columns.Count; i++)
- {
- var column = columns[i];
-
- if (i < schema.KeyColumnCount)
- {
- tuple[column.Name] = key[column.Name];
- }
- else
- {
- if (r.TryReadNoValue())
- {
- continue;
- }
-
- tuple[column.Name] = r.ReadObject(column.Type);
- }
- }
-
- return tuple;
- }
-
- private static IIgniteTuple ReadTuple(ref MessagePackReader r, Schema schema, bool keyOnly = false)
- {
- var columns = schema.Columns;
- var count = keyOnly ? schema.KeyColumnCount : columns.Count;
- var tuple = new IgniteTuple(count);
-
- for (var index = 0; index < count; index++)
- {
- if (r.TryReadNoValue())
- {
- continue;
- }
-
- var column = columns[index];
- tuple[column.Name] = r.ReadObject(column.Type);
- }
-
- return tuple;
- }
-
- private static IList<IIgniteTuple> ReadTuples(PooledBuffer buf, Schema? schema, bool keyOnly = false)
- {
- if (schema == null)
- {
- return Array.Empty<IIgniteTuple>();
- }
-
- // Skip schema version.
- var r = buf.GetReader();
- r.Skip();
-
- var count = r.ReadInt32();
- var res = new List<IIgniteTuple>(count);
-
- for (var i = 0; i < count; i++)
- {
- res.Add(ReadTuple(ref r, schema, keyOnly));
- }
-
- return res;
- }
-
- private static IList<IIgniteTuple?> ReadTuplesNullable(PooledBuffer buf, Schema? schema, bool keyOnly = false)
- {
- if (schema == null)
- {
- return Array.Empty<IIgniteTuple?>();
- }
-
- // Skip schema version.
- var r = buf.GetReader();
- r.Skip();
-
- var count = r.ReadInt32();
- var res = new List<IIgniteTuple?>(count);
-
- for (var i = 0; i < count; i++)
- {
- var hasValue = r.ReadBoolean();
-
- res.Add(hasValue ? ReadTuple(ref r, schema, keyOnly) : null);
- }
-
- return res;
- }
-
- private static int? ReadSchemaVersion(PooledBuffer buf)
- {
- var reader = buf.GetReader();
-
- return reader.ReadInt32Nullable();
- }
-
- private static void WriteTuple(
- ref MessagePackWriter w,
- Schema schema,
- IIgniteTuple tuple,
- bool keyOnly = false)
- {
- var columns = schema.Columns;
- var count = keyOnly ? schema.KeyColumnCount : columns.Count;
-
- for (var index = 0; index < count; index++)
- {
- var col = columns[index];
- var colIdx = tuple.GetOrdinal(col.Name);
-
- if (colIdx < 0)
- {
- w.WriteNoValue();
- }
- else
- {
- w.WriteObject(tuple[colIdx]);
- }
- }
- }
-
- private async ValueTask<Schema?> ReadSchemaAsync(PooledBuffer buf, Schema currentSchema)
- {
- var ver = ReadSchemaVersion(buf);
-
- if (ver == null)
- {
- return null;
- }
-
- if (currentSchema.Version == ver.Value)
- {
- return currentSchema;
- }
-
- if (_schemas.TryGetValue(ver.Value, out var res))
- {
- return res;
- }
-
- return await LoadSchemaAsync(ver).ConfigureAwait(false);
- }
-
- private async ValueTask<Schema> GetLatestSchemaAsync()
- {
- var latestSchemaVersion = _latestSchemaVersion;
-
- if (latestSchemaVersion >= 0)
- {
- return _schemas[latestSchemaVersion];
- }
-
- return await LoadSchemaAsync(null).ConfigureAwait(false);
- }
-
- private async Task<Schema> LoadSchemaAsync(int? version)
- {
- using var writer = new PooledArrayBufferWriter();
- Write();
-
- using var resBuf = await _socket.DoOutInOpAsync(ClientOp.SchemasGet, writer).ConfigureAwait(false);
- return Read();
-
- void Write()
- {
- var w = writer.GetMessageWriter();
- w.Write(Id);
-
- if (version == null)
- {
- w.WriteNil();
- }
- else
- {
- w.WriteArrayHeader(1);
- w.Write(version.Value);
- }
-
- w.Flush();
- }
-
- Schema Read()
- {
- var r = resBuf.GetReader();
- var schemaCount = r.ReadMapHeader();
-
- if (schemaCount == 0)
- {
- throw new IgniteClientException("Schema not found: " + version);
- }
-
- Schema last = null!;
-
- for (var i = 0; i < schemaCount; i++)
- {
- last = ReadSchema(ref r);
- }
-
- // Store all schemas in the map, and return last.
- return last;
- }
- }
-
- private Schema ReadSchema(ref MessagePackReader r)
- {
- var schemaVersion = r.ReadInt32();
- var columnCount = r.ReadArrayHeader();
- var keyColumnCount = 0;
-
- var columns = new Column[columnCount];
- var columnsMap = new Dictionary<string, Column>(columnCount);
-
- for (var i = 0; i < columnCount; i++)
- {
- var propertyCount = r.ReadArrayHeader();
-
- Debug.Assert(propertyCount >= 4, "propertyCount >= 4");
-
- var name = r.ReadString();
- var type = r.ReadInt32();
- var isKey = r.ReadBoolean();
- var isNullable = r.ReadBoolean();
-
- r.Skip(propertyCount - 4);
-
- var column = new Column(name, (ClientDataType)type, isNullable, isKey, i);
-
- columns[i] = column;
- columnsMap[column.Name] = column;
-
- if (isKey)
- {
- keyColumnCount++;
- }
- }
-
- var schema = new Schema(schemaVersion, keyColumnCount, columns, columnsMap);
-
- _schemas[schemaVersion] = schema;
-
- lock (_latestSchemaLock)
- {
- if (schemaVersion > _latestSchemaVersion)
- {
- _latestSchemaVersion = schemaVersion;
- }
- }
-
- return schema;
- }
-
- private void WriteTuple(PooledArrayBufferWriter buf, Schema schema, IIgniteTuple tuple, bool keyOnly = false)
- {
- var w = buf.GetMessageWriter();
-
- WriteTupleWithHeader(ref w, schema, tuple, keyOnly);
-
- w.Flush();
- }
-
- private void WriteTuples(
- PooledArrayBufferWriter buf,
- Schema schema,
- IIgniteTuple t,
- IIgniteTuple t2,
- bool keyOnly = false)
- {
- var w = buf.GetMessageWriter();
-
- WriteTupleWithHeader(ref w, schema, t, keyOnly);
- WriteTuple(ref w, schema, t2, keyOnly);
-
- w.Flush();
- }
-
- private void WriteTuples(
- PooledArrayBufferWriter buf,
- Schema schema,
- IEnumerator<IIgniteTuple> tuples,
- bool keyOnly = false)
- {
- var w = buf.GetMessageWriter();
-
- w.Write(Id);
- w.WriteNil(); // Transaction ID (TODO: IGNITE-16208).
- w.Write(schema.Version);
- w.Flush();
-
- var count = 0;
- var countPos = buf.ReserveInt32();
-
- do
- {
- var tuple = tuples.Current;
-
- if (tuple == null)
- {
- throw new ArgumentException("Tuple collection can't contain null elements.");
- }
-
- WriteTuple(ref w, schema, tuple, keyOnly);
- count++;
- }
- while (tuples.MoveNext()); // First MoveNext is called outside to check for empty IEnumerable.
-
- buf.WriteInt32(countPos, count);
-
- w.Flush();
- }
-
- private void WriteTupleWithHeader(
- ref MessagePackWriter w,
- Schema schema,
- IIgniteTuple tuple,
- bool keyOnly = false)
- {
- w.Write(Id);
- w.WriteNil(); // Transaction ID (TODO: IGNITE-16208).
- w.Write(schema.Version);
-
- WriteTuple(ref w, schema, tuple, keyOnly);
- }
+ /// <summary>
+ /// Gets the socket.
+ /// </summary>
+ internal ClientFailoverSocket Socket { get; }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs
new file mode 100644
index 0000000..f06d150
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transaction.cs
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Internal.Transactions
+{
+ using System.Threading;
+ using System.Threading.Tasks;
+ using System.Transactions;
+ using Buffers;
+ using Ignite.Transactions;
+ using MessagePack;
+ using Proto;
+
+ /// <summary>
+ /// Ignite transaction.
+ /// </summary>
+ internal class Transaction : ITransaction
+ {
+ /** Open state. */
+ private const int StateOpen = 0;
+
+ /** Committed state. */
+ private const int StateCommitted = 1;
+
+ /** Rolled back state. */
+ private const int StateRolledBack = 2;
+
+ /** State. */
+ private int _state = StateOpen;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Transaction"/> class.
+ /// </summary>
+ /// <param name="id">Transaction id.</param>
+ /// <param name="socket">Associated connection.</param>
+ /// <param name="failoverSocket">Associated connection multiplexer.</param>
+ public Transaction(long id, ClientSocket socket, ClientFailoverSocket failoverSocket)
+ {
+ Id = id;
+ Socket = socket;
+ FailoverSocket = failoverSocket;
+ }
+
+ /// <summary>
+ /// Gets the owner socket.
+ /// </summary>
+ public ClientSocket Socket { get; }
+
+ /// <summary>
+ /// Gets the owner multiplexer socket.
+ /// </summary>
+ public ClientFailoverSocket FailoverSocket { get; }
+
+ /// <summary>
+ /// Gets the transaction id.
+ /// </summary>
+ public long Id { get; }
+
+ /// <inheritdoc/>
+ public async Task CommitAsync()
+ {
+ SetState(StateCommitted);
+
+ using var writer = new PooledArrayBufferWriter();
+ Write(writer.GetMessageWriter());
+
+ await Socket.DoOutInOpAsync(ClientOp.TxCommit, writer).ConfigureAwait(false);
+ }
+
+ /// <inheritdoc/>
+ public async Task RollbackAsync()
+ {
+ SetState(StateRolledBack);
+
+ await RollbackAsyncInternal().ConfigureAwait(false);
+ }
+
+ /// <inheritdoc/>
+ public async ValueTask DisposeAsync()
+ {
+ // Roll back if the transaction is still open, otherwise do nothing.
+ if (TrySetState(StateRolledBack))
+ {
+ await RollbackAsyncInternal().ConfigureAwait(false);
+ }
+ }
+
+ /// <summary>
+ /// Rolls back the transaction without state check.
+ /// </summary>
+ private async Task RollbackAsyncInternal()
+ {
+ using var writer = new PooledArrayBufferWriter();
+ Write(writer.GetMessageWriter());
+
+ await Socket.DoOutInOpAsync(ClientOp.TxRollback, writer).ConfigureAwait(false);
+ }
+
+ /// <summary>
+ /// Attempts to set the specified state.
+ /// </summary>
+ /// <param name="state">State to set.</param>
+ /// <returns>True when specified state was set successfully; false otherwise.</returns>
+ private bool TrySetState(int state)
+ {
+ return Interlocked.CompareExchange(ref _state, state, StateOpen) == StateOpen;
+ }
+
+ /// <summary>
+ /// Sets the specified state. Throws <see cref="TransactionException"/> when current state is different from
+ /// <see cref="StateOpen"/>.
+ /// </summary>
+ /// <param name="state">State to set.</param>
+ /// <exception cref="TransactionException">When current state is not <see cref="StateOpen"/>.</exception>
+ private void SetState(int state)
+ {
+ var oldState = Interlocked.CompareExchange(ref _state, state, StateOpen);
+
+ if (oldState == StateOpen)
+ {
+ return;
+ }
+
+ var message = oldState == StateCommitted
+ ? "Transaction is already committed."
+ : "Transaction is already rolled back.";
+
+ throw new TransactionException(message);
+ }
+
+ /// <summary>
+ /// Writes the transaction.
+ /// </summary>
+ /// <param name="writer">Writer.</param>
+ private void Write(MessagePackWriter writer)
+ {
+ writer.Write(Id);
+ writer.Flush();
+ }
+ }
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
similarity index 57%
copy from modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs
copy to modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
index ab9ccdd..c6cb1c2 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/IgniteClientInternal.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Transactions/Transactions.cs
@@ -15,40 +15,41 @@
* limitations under the License.
*/
-namespace Apache.Ignite.Internal
+namespace Apache.Ignite.Internal.Transactions
{
- using Ignite.Table;
- using Table;
+ using System.Threading.Tasks;
+ using Ignite.Transactions;
+ using Proto;
/// <summary>
- /// Ignite client implementation.
+ /// Transactions API.
/// </summary>
- internal sealed class IgniteClientInternal : IIgniteClient
+ internal class Transactions : ITransactions
{
/** Underlying connection. */
private readonly ClientFailoverSocket _socket;
/// <summary>
- /// Initializes a new instance of the <see cref="IgniteClientInternal"/> class.
+ /// Initializes a new instance of the <see cref="Transactions"/> class.
/// </summary>
/// <param name="socket">Socket.</param>
- public IgniteClientInternal(ClientFailoverSocket socket)
+ public Transactions(ClientFailoverSocket socket)
{
_socket = socket;
- Tables = new Tables(socket);
}
/// <inheritdoc/>
- public IgniteClientConfiguration Configuration =>
- new(_socket.Configuration); // Defensive copy.
+ public async Task<ITransaction> BeginAsync()
+ {
+ // Get a specific connection.
+ // Transaction and all corresponding operations must be performed using the same connection.
+ var socket = await _socket.GetSocketAsync().ConfigureAwait(false);
- /// <inheritdoc/>
- public ITables Tables { get; }
+ using var resBuf = await socket.DoOutInOpAsync(ClientOp.TxBegin).ConfigureAwait(false);
- /// <inheritdoc/>
- public void Dispose()
- {
- _socket.Dispose();
+ var txId = resBuf.GetReader().ReadInt64();
+
+ return new Transaction(txId, socket, _socket);
}
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/IIgniteTuple.cs b/modules/platforms/dotnet/Apache.Ignite/Table/IIgniteTuple.cs
index 67d68e5..fcb3381 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/IIgniteTuple.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/IIgniteTuple.cs
@@ -17,6 +17,9 @@
namespace Apache.Ignite.Table
{
+ using System;
+ using Internal.Common;
+
/// <summary>
/// Ignite Tuple.
/// <para />
@@ -55,5 +58,75 @@ namespace Apache.Ignite.Table
/// <param name="name">Column name.</param>
/// <returns>Column ordinal, or -1 when the column with the given name does not exist.</returns>
int GetOrdinal(string name);
+
+ /// <summary>
+ /// Gets a hash code for the current tuple according to column names and values.
+ /// </summary>
+ /// <param name="tuple">Tuple.</param>
+ /// <returns>A hash code for the specified tuple.</returns>
+ public static int GetHashCode(IIgniteTuple tuple)
+ {
+ IgniteArgumentCheck.NotNull(tuple, nameof(tuple));
+
+ var hash = default(HashCode);
+
+ for (int i = 0; i < tuple.FieldCount; i++)
+ {
+ var name = tuple.GetName(i);
+ var val = tuple[i];
+
+ hash.Add(name);
+ hash.Add(val);
+ }
+
+ return hash.ToHashCode();
+ }
+
+ /// <summary>
+ /// Determines whether the specified object instances are considered equal.
+ /// </summary>
+ /// <param name="tuple1">The first tuple to compare.</param>
+ /// <param name="tuple2">The second tuple to compare.</param>
+ /// <returns>
+ /// <see langword="true" /> if the tuples are considered equal; otherwise, <see langword="false" />.
+ /// If both <paramref name="tuple1" /> and <paramref name="tuple1" /> are null, the method returns <see langword="true" />.
+ /// </returns>
+ public static bool Equals(IIgniteTuple? tuple1, IIgniteTuple? tuple2)
+ {
+ if (tuple1 == null)
+ {
+ return tuple2 == null;
+ }
+
+ if (tuple2 == null)
+ {
+ return false;
+ }
+
+ if (ReferenceEquals(tuple1, tuple2))
+ {
+ return true;
+ }
+
+ if (tuple1.FieldCount != tuple2.FieldCount)
+ {
+ return false;
+ }
+
+ for (int i = 0; i < tuple1.FieldCount; i++)
+ {
+ if (tuple1.GetName(i) != tuple2.GetName(i))
+ {
+ return false;
+ }
+
+ if (!Equals(tuple1[i], tuple2[i]))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/ITableView.cs b/modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
similarity index 73%
rename from modules/platforms/dotnet/Apache.Ignite/Table/ITableView.cs
rename to modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
index 2dc2610..b81d177 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/ITableView.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/IRecordView.cs
@@ -19,29 +19,30 @@ namespace Apache.Ignite.Table
{
using System.Collections.Generic;
using System.Threading.Tasks;
+ using Transactions;
/// <summary>
- /// Table view interface provides methods to access table records.
- /// <para />
- /// TODO: All APIs (IGNITE-15430).
+ /// Record view interface provides methods to access table records.
/// </summary>
/// <typeparam name="T">Record type.</typeparam>
- public interface ITableView<T>
+ public interface IRecordView<T>
where T : class
{
/// <summary>
/// Gets a record by key.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="key">A record with key columns set.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains a record with all columns.
/// </returns>
- Task<T?> GetAsync(T key);
+ Task<T?> GetAsync(ITransaction? transaction, T key);
/// <summary>
/// Gets multiple records by keys.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="keys">Collection of records with key columns set.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
@@ -49,134 +50,147 @@ namespace Apache.Ignite.Table
/// elements is guaranteed to be the same as the order of <paramref name="keys"/>. If a record does not exist,
/// the element at the corresponding index of the resulting collection will be <c>null</c>.
/// </returns>
- Task<IList<T?>> GetAllAsync(IEnumerable<T> keys);
+ Task<IList<T?>> GetAllAsync(ITransaction? transaction, IEnumerable<T> keys);
/// <summary>
/// Inserts a record into the table if it does not exist or replaces the existing one.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">Record to upsert.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
- Task UpsertAsync(T record);
+ Task UpsertAsync(ITransaction? transaction, T record);
/// <summary>
/// Inserts multiple records into the table, replacing existing ones.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="records">Records to upsert.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
- Task UpsertAllAsync(IEnumerable<T> records);
+ Task UpsertAllAsync(ITransaction? transaction, IEnumerable<T> records);
/// <summary>
/// Inserts a record into the table if it does not exist or replaces the existing one.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">Record to upsert.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains replaced record or null if it did not exist.
/// </returns>
- Task<T?> GetAndUpsertAsync(T record);
+ Task<T?> GetAndUpsertAsync(ITransaction? transaction, T record);
/// <summary>
/// Inserts a record into the table if it does not exist.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">Record to insert.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains a value indicating whether the record was inserted. Returns <c>false</c> if a
/// record with the same key already exists.
/// </returns>
- Task<bool> InsertAsync(T record);
+ Task<bool> InsertAsync(ITransaction? transaction, T record);
/// <summary>
/// Inserts multiple records into the table, skipping existing ones.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="records">Records to insert.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains skipped records.
/// </returns>
- Task<IList<T>> InsertAllAsync(IEnumerable<T> records);
+ Task<IList<T>> InsertAllAsync(ITransaction? transaction, IEnumerable<T> records);
/// <summary>
/// Replaces a record with the same key columns if it exists, otherwise does nothing.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">Record to insert.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains a value indicating whether a record with the specified key was replaced.
/// </returns>
- Task<bool> ReplaceAsync(T record);
+ Task<bool> ReplaceAsync(ITransaction? transaction, T record);
/// <summary>
/// Replaces a record with a new one only if all existing columns have the same values
/// as the specified <paramref name="record"/>.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">Record to replace.</param>
/// <param name="newRecord">Record to replace with.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains a value indicating whether a record was replaced.
/// </returns>
- Task<bool> ReplaceAsync(T record, T newRecord);
+ Task<bool> ReplaceAsync(ITransaction? transaction, T record, T newRecord);
/// <summary>
/// Replaces a record with the same key columns if it exists.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">Record to insert.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains the previous value for the given key, or <c>null</c> if it did not exist.
/// </returns>
- Task<T?> GetAndReplaceAsync(T record);
+ Task<T?> GetAndReplaceAsync(ITransaction? transaction, T record);
/// <summary>
/// Deletes a record with the specified key.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="key">A record with key columns set.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains a value indicating whether a record with the specified key was deleted.
/// </returns>
- Task<bool> DeleteAsync(T key);
+ Task<bool> DeleteAsync(ITransaction? transaction, T key);
/// <summary>
/// Deletes a record only if all existing columns have the same values as the specified <paramref name="record"/>.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="record">A record with all columns set.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains a value indicating whether a record was deleted.
/// </returns>
- Task<bool> DeleteExactAsync(T record);
+ Task<bool> DeleteExactAsync(ITransaction? transaction, T record);
/// <summary>
/// Gets and deletes a record with the specified key.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="key">A record with key columns set.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains deleted record or <c>null</c> if it did not exist.
/// </returns>
- Task<T?> GetAndDeleteAsync(T key);
+ Task<T?> GetAndDeleteAsync(ITransaction? transaction, T key);
/// <summary>
/// Deletes multiple records. If one or more keys do not exist, other records are still deleted.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="keys">Record keys to delete.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains records from <paramref name="keys"/> that did not exist.
/// </returns>
- Task<IList<T>> DeleteAllAsync(IEnumerable<T> keys);
+ Task<IList<T>> DeleteAllAsync(ITransaction? transaction, IEnumerable<T> keys);
/// <summary>
/// Deletes multiple exactly matching records. If one or more records do not exist,
/// other records are still deleted.
/// </summary>
+ /// <param name="transaction">The transaction or <c>null</c> to auto commit.</param>
/// <param name="records">Records to delete.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains records from <paramref name="records"/> that did not exist.
/// </returns>
- Task<IList<T>> DeleteAllExactAsync(IEnumerable<T> records);
+ Task<IList<T>> DeleteAllExactAsync(ITransaction? transaction, IEnumerable<T> records);
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/ITable.cs b/modules/platforms/dotnet/Apache.Ignite/Table/ITable.cs
index b83f740..f710f1e 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/ITable.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/ITable.cs
@@ -20,11 +20,16 @@ namespace Apache.Ignite.Table
/// <summary>
/// Table view.
/// </summary>
- public interface ITable : ITableView<IIgniteTuple>
+ public interface ITable
{
/// <summary>
/// Gets the table name.
/// </summary>
public string Name { get; }
+
+ /// <summary>
+ /// Gets the record view.
+ /// </summary>
+ public IRecordView<IIgniteTuple> RecordView { get; }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs b/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs
index 9e7134e..ed893fd 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Table/IgniteTuple.cs
@@ -17,13 +17,14 @@
namespace Apache.Ignite.Table
{
+ using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// Ignite tuple.
/// </summary>
- public sealed class IgniteTuple : IIgniteTuple
+ public sealed class IgniteTuple : IIgniteTuple, IEquatable<IgniteTuple>
{
/** Key-value pairs. */
private readonly List<(string Key, object? Value)> _pairs;
@@ -99,5 +100,23 @@ namespace Apache.Ignite.Table
return sb.ToString();
}
+
+ /// <inheritdoc />
+ public bool Equals(IgniteTuple other)
+ {
+ return IIgniteTuple.Equals(this, other);
+ }
+
+ /// <inheritdoc />
+ public override bool Equals(object? obj)
+ {
+ return obj is IgniteTuple other && Equals(other);
+ }
+
+ /// <inheritdoc />
+ public override int GetHashCode()
+ {
+ return IIgniteTuple.GetHashCode(this);
+ }
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/IIgnite.cs b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
similarity index 60%
copy from modules/platforms/dotnet/Apache.Ignite/IIgnite.cs
copy to modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
index 185168b..e5c4cea 100644
--- a/modules/platforms/dotnet/Apache.Ignite/IIgnite.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransaction.cs
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -15,22 +15,28 @@
* limitations under the License.
*/
-namespace Apache.Ignite
+namespace Apache.Ignite.Transactions
{
using System;
- using Table;
+ using System.Threading.Tasks;
/// <summary>
- /// Ignite API entry point.
+ /// Ignite transaction.
/// <para />
- /// Implementation can be a thin client (see <see cref="IIgniteClient"/> and <see cref="IgniteClient.StartAsync"/>),
- /// or a direct IPC connection for server-side functionality like compute.
+ /// Use <see cref="ITransactions.BeginAsync"/> to start a new transaction.
/// </summary>
- public interface IIgnite : IDisposable
+ public interface ITransaction : IAsyncDisposable
{
/// <summary>
- /// Gets the tables API.
+ /// Commits the transaction.
/// </summary>
- ITables Tables { get; }
+ /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
+ Task CommitAsync();
+
+ /// <summary>
+ /// Rolls back the transaction.
+ /// </summary>
+ /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
+ Task RollbackAsync();
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransactions.cs
similarity index 74%
copy from modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs
copy to modules/platforms/dotnet/Apache.Ignite/Transactions/ITransactions.cs
index ae5c09b..f2904e7 100644
--- a/modules/platforms/dotnet/Apache.Ignite/IIgniteClient.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Transactions/ITransactions.cs
@@ -15,18 +15,19 @@
* limitations under the License.
*/
-namespace Apache.Ignite
+namespace Apache.Ignite.Transactions
{
+ using System.Threading.Tasks;
+
/// <summary>
- /// Ignite client.
- /// <para />
- /// Extends <see cref="IIgnite"/> with client-specific functionality.
+ /// Ignite transactions API.
/// </summary>
- public interface IIgniteClient : IIgnite
+ public interface ITransactions
{
/// <summary>
- /// Gets the configuration.
+ /// Starts a new transaction.
/// </summary>
- IgniteClientConfiguration Configuration { get; }
+ /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
+ Task<ITransaction> BeginAsync();
}
}