For the complete documentation index, see llms.txt. This page is also available as Markdown.

.NET Client

Connect to a GridGain 9 cluster with the .NET client, covering configuration, authentication, the SQL and table APIs, transactions, data streaming, metrics, logging, and object mapping.

GridGain 9 clients connect to the cluster via a standard socket connection. Unlike GridGain 2.x, there is no separate Thin and Thick clients in GridGain 9. All clients are 'thin'.

Clients do not become a part of the cluster topology, never hold any data, and are not used as a destination for compute calculations.

Getting Started

Prerequisites

To use C# client, .NET 8.0 or newer is required.

Installation

C# client is available via NuGet. To add it, use the add package command:

dotnet add package GridGain.Ignite --version 9.1

Connecting to Cluster

To initialize a client, use the IgniteClient class, and provide it with the configuration:

.NET
var clientCfg = new IgniteClientConfiguration
{
  Endpoints = { "127.0.0.1" }
};
using var client = await IgniteClient.StartAsync(clientCfg);

Cluster API

The cluster API lets you inspect the cluster topology, access it through the IIgnite.Cluster property:

  • Cluster.GetNodesAsync() returns all nodes that are part of the logical topology.

  • Cluster.LocalNode returns the local cluster node. On the client side it is null; it is populated only when accessed from server-side code inside a compute job (IJobExecutionContext.Ignite) or a data streamer receiver (IDataStreamerReceiverContext.Ignite), where it identifies the node executing that code.

Each IClusterNode exposes its Id (a Guid that changes after a node restart), Name (the consistent ID, stable across restarts), and Address.

The older IIgnite.GetClusterNodesAsync() method is obsolete. Use Cluster.GetNodesAsync() instead.

Client Configuration

SQL Partition Awareness

The .NET client supports SQL partition awareness, which improves query performance by routing requests directly to the nodes that hold the relevant data. This feature is controlled by the SqlPartitionAwarenessMetadataCacheSize configuration property.

Property
Description

SqlPartitionAwarenessMetadataCacheSize

Maximum number of SQL partition awareness metadata entries to cache. Default is 1024. Set to 0 to disable SQL partition awareness.

The client builds a metadata cache during the initial query execution and uses this cache to optimize subsequent queries. Metadata is available for queries with equality predicates over all colocation columns.

Authentication

To pass authentication information, pass it to IgniteClient builder:

Limitations

There are limitations to user types that can be used for such a mapping. Some limitations are common, and others are platform-specific due to the programming language used.

  • Only flat field structure is supported, meaning no nesting user objects. This is because Ignite tables, and therefore tuples have flat structure themselves;

  • Fields should be mapped to Ignite types;

  • All fields in user type should either be mapped to Table column or explicitly excluded;

  • All columns from Table should be mapped to some field in the user type;

  • .NET only: Any type (class, struct, record) is supported as long as all fields can be mapped to Ignite types;

Usage Examples

SQL API

GridGain 9 is focused on SQL, and SQL API is the primary way to work with the data. You can read more about supported SQL statements in the SQL Reference section. Here is how you can send SQL requests:

You can also use an explicit IMapper<T> interface to enable strongly typed SQL results without relying on tuple-based or reflection-based mapping:

Batch SQL Execution

You can execute the specified DML statement once for each set of arguments and return the number of affected rows for each execution.

Only INSERT, UPDATE, DELETE statements are supported.

To run a batch execution, you need to implement ExecuteBatchAsync() method with the following parameters:

Parameters

  • transaction - The optional transaction in which to execute the batch.

  • statement - The SQL statement to execute for each entry in args.

  • args - A collection of argument lists. The statement will be executed once per inner collection. Must not be empty or contain empty rows.

  • cancellationToken - Token for cancelling the operation.

Example

In this example we return an array of update counts. Each element corresponds to the number of rows affected by the statement execution for the matching entry in args. The length of the returned array equals the number of argument sets.

Error Handling

If a batch execution fails, a SqlBatchException is thrown. The UpdateCounters property contains the number of rows affected by each statement that executed successfully before the failure, in the same order as the batch commands. Use it to determine which operations completed before the error occurred.

SQL Scripts

The default API executes SQL statements one at a time. If you want to execute large SQL statements, pass them to the executeScript() method. These statements will be executed in order.

Execution of each statement is considered complete when the first page is ready to be returned. As a result, when working with large data sets, SELECT statement may be affected by later statements in the same script.

SQL Partition Awareness Configuration

SQL partition awareness optimizes query performance by routing SQL queries directly to the server nodes that hold the relevant data. This feature is enabled by default and can be configured using the SqlPartitionAwarenessMetadataCacheSize property.

To configure the partition awareness cache size:

To disable SQL partition awareness, set the cache size to zero:

The cache is keyed by (schema, query) pairs. Each unique query pattern requires a separate cache entry. Queries with different parameter values but the same structure share the same cache entry.

Transactions

All table operations in GridGain 9 are transactional. You can provide an explicit transaction as a first argument of any Table and SQL API call. If you do not provide an explicit transaction, an implicit one will be created for every call.

Here is how you can provide a transaction explicitly:

Table API

To execute table operations on a specific table, you need to get a specific view of the table and use one of its methods. You can only create new tables by using SQL API.

When working with tables, you can use built-in IgniteTuple type, which is a set of key-value pairs underneath, or map the data to your own types for a strongly-typed access. Here is how you can work with tables:

Getting a Table Instance

To obtain an instance of a table, use the ITables.GetTableAsync(string name) You can also use ITables.GetTablesAsync method to list all existing tables.

Basic Table Operations

Once you've got a table you need to get a specific view to choose how you want to operate table records.

Tuple Record View

A tuple record view. It can be used to operate table tuples directly.

Record View

A record view mapped to a user type. It can be used to operate table using user objects which are mapped to table tuples.

Key-Value Tuple View

A tuple key-value view. It can be used to operate table using key and value tuples separately.

Key-Value View

A key-value view with user objects. It can be used to operate table using key and value user objects mapped to table tuples.

Partition Management

Using an IMapper<T> to get partitions allows the client to compute the partition deterministically without reflection and is required for POCO keys in AOT and other no-reflection scenarios.

Streaming Data

To stream a large amount of data, use the data streamer. Data streaming provides a quicker and more efficient way to load, organize and optimally distribute your data. Data streamer accepts a stream of data and distributes data entries across the cluster, where the processing takes place. Data streaming is available in all table views.

Data streaming provides at-least-once delivery guarantee.

Using Data Streamer API

Client Metrics

Metrics are exposed by the .NET client through the System.Diagnostics.Metrics API with the Apache.Ignite meter name. For example, here is how you can access GridGain metrics by using the dotnet-counters tool:

You can also get metrics in your code by creating a listener:

Available .NET Metrics

Metric name
Description

connections-active

The number of currently active connections.

connections-established

The number of established connections.

connections-lost

The number of connections lost.

connections-lost-timeout

The number of connections lost due to a timeout.

handshakes-failed

The number of failed handshakes.

handshakes-failed-timeout

The number of handshakes that failed due to a timeout.

requests-active

The number of currently active requests.

requests-sent

The number of requests sent.

requests-completed

The number of completed requests. Requests are completed once a response is received.

requests-retried

The number of request retries.

requests-failed

The number of failed requests.

bytes-sent

The amount of bytes sent.

bytes-received

The amount of bytes received.

streamer-batches-sent

The number of data streamer batches sent.

streamer-items-sent

The number of data streamer items sent.

streamer-batches-active

The number of existing data streamer batches.

streamer-items-queued

The number of queued data streamer items.

Logging

To enable logging, set the IgniteClientConfiguration.LoggerFactory property to an instance of the Microsoft.Extensions.Logging.ILoggerFactory standard API. See Standard logging in .NET to learn more.

Examples

The example below shows how you can configure logging to console with the Microsoft.Extensions.Logging.Console package:

Alternatively, here is how to configure logging with Serilog by using Serilog.Extensions.Logging and Serilog.Sinks.Console packages:

Custom Object Mapping

Ignite provides basic object mapping for table rows and SQL query results in the following APIs:

  • ITable.GetRecordView<T>

  • ITable.GetKeyValueView<TK, TV>()

  • ISql.ExecuteAsync<T>

  • IJobTarget<TKey>.Colocated<TKey>()

  • IPartitionManager.GetPartitionAsync();

Mappers are generated at runtime with the use of reflection and IL emit. Mapped properties and fields can be customized with ColumnAttribute and excluded with NotMappedAttribute.

For advanced mapping scenarios and environments where reflection is limited (such as NativeAOT), you can implement the IMapper<T> interface.

Record View Mapper

For record views, implement the IMapper<T> interface:

Then use the mapper when creating a record view:

Key-Value View Mapper

For key-value views, implement a mapper for KeyValuePair<TK, TV>:

Then use the mapper when creating a key-value view:

Schema-Aware Mapping

The IMapper<T> interface provides two approaches for mapping objects to rows, depending on whether the schema is known at compile time.

Static Schema Mapping

When the exact table schema is known at compile time, you can write columns directly in the correct order. This approach provides the best performance by avoiding column name lookups:

Dynamic Schema Mapping

When the schema may vary or is not known at compile time, you can load the schema at runtime. The compiler optimizes switch statements with hash codes for fast lookups:

Native Ahead-Of-Time Mode Support

GridGain 9 .NET client supports running in Native AOT mode for most public APIs. A small subset of APIs is not compatible with AOT due to reliance on reflection.

The following APIs are not supported in Native AOT mode:

  • Automatic object mapping without IMapper<T>

Workaround: use overloads that explicitly accept IMapper<T>.

  • LINQ-based APIs (IRecordView.AsQueryable, IKeyValueView.AsQueryable)

Workaround: use the SQL API, which supports IMapper<T> and is compatible with AOT.

When compiling an application in Native AOT mode, unsupported APIs produce trimming warnings that indicate the issue and suggest compatible alternatives.

For more details refer to the official Microsoft documentation.

Last updated

Was this helpful?