Cache Configuration
This is a legacy Apache Ignite documentation
The new documentation is hosted here: https://ignite.apache.org/docs/latest/
Operation Codes
Upon successful handshake with an Ignite server node, a client can start performing various cahe configuration operations by sending a request (see request/response structure below) with a specific operation code:
Operation | OP_CODE |
---|---|
OP_CACHE_GET_NAMES | 1050 |
OP_CACHE_CREATE_WITH_NAME | 1051 |
OP_CACHE_GET_OR_CREATE_WITH_NAME | 1052 |
OP_CACHE_CREATE_WITH_CONFIGURATION | 1053 |
OP_CACHE_GET_OR_CREATE_WITH_CONFIGURATION | 1054 |
OP_CACHE_GET_CONFIGURATION | 1055 |
OP_CACHE_DESTROY | 1056 |
Note that the above mentioned op_codes are part of the request header, as explained here.
Customs Methods Used in Sample Code Snippets Implementation
Some of the code snippets below use
readDataObject(...)
introduced in this section and little-endian versions of methods for reading and writing multiple-byte values that are covered in this example.
OP_CACHE_CREATE_WITH_NAME
Creates a cache with a given name. Cache template can be applied if there is a '*' in the cache name. Throws exception if a cache with specified name already exists.
Request Type | Description |
---|---|
Header | Request header. |
String | Cache name. |
Response Type | Description |
---|---|
Header | Response header. |
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
String cacheName = "myNewCache";
int nameLength = cacheName.getBytes("UTF-8").length;
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// Request header
writeRequestHeader(5 + nameLength, OP_CACHE_CREATE_WITH_NAME, 1, out);
// Cache name
writeString(cacheName, out);
// Send request
out.flush();
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
readResponseHeader(in);
OP_CACHE_GET_OR_CREATE_WITH_NAME
Creates a cache with a given name. Cache template can be applied if there is a '*' in the cache name. Does nothing if the cache exists.
Request Type | Description |
---|---|
Header | Request header. |
String | Cache name. |
Response Type | Description |
---|---|
Header | Response header. |
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
String cacheName = "myNewCache";
int nameLength = cacheName.getBytes("UTF-8").length;
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// Request header
writeRequestHeader(5 + nameLength, OP_CACHE_GET_OR_CREATE_WITH_NAME, 1, out);
// Cache name
writeString(cacheName, out);
// Send request
out.flush();
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
readResponseHeader(in);
OP_CACHE_GET_NAMES
Gets existing cache names.
Request Type | Description |
---|---|
Header | Request header. |
Response Type | Description |
---|---|
Header | Response header. |
int | Cache count. |
String | Cache name. Repeat for as many times as the cache count that is obtained in the previous parameter. |
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// Request header
writeRequestHeader(5, OP_CACHE_GET_NAMES, 1, out);
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
readResponseHeader(in);
// Cache count
int cacheCount = readIntLittleEndian(in);
// Cache names
for (int i = 0; i < cacheCount; i++) {
int type = readByteLittleEndian(in); // type code
int strLen = readIntLittleEndian(in); // length
byte[] buf = new byte[strLen];
readFully(in, buf, 0, strLen);
String s = new String(buf); // cache name
System.out.println(s);
}
OP_CACHE_GET_CONFIGURATION
Gets configuration for the given cache.
Request Type | Description |
---|---|
Header | Request header. |
int | Cache ID: Java-style hash code of the cache name. |
byte | Flag. |
Response Type | Description |
---|---|
Header | Response header. |
int | Length of the configuration in bytes (all the configuration parameters). |
CacheConfiguration | Structure of Cache configuration (See below). |
Cache Configuration
Type | Description |
---|---|
int | Number of backups. |
int | CacheMode: |
bool | CopyOnRead |
String | DataRegionName |
bool | EagerTTL |
bool | StatisticsEnabled |
String | GroupName |
bool | Invalidate |
long | DefaultLockTimeout (milliseconds) |
int | MaxQueryIterators |
String | Name |
bool | IsOnheapCacheEnabled |
int | PartitionLossPolicy: |
int | QueryDetailMetricsSize |
int | QueryParellelism |
bool | ReadFromBackup |
int | RebalanceBatchSize |
long | RebalanceBatchesPrefetchCount |
long | RebalanceDelay (milliseconds) |
int | RebalanceMode: |
int | RebalanceOrder |
long | RebalanceThrottle (milliseconds) |
long | RebalanceTimeout (milliseconds) |
bool | SqlEscapeAll |
int | SqlIndexInlineMaxSize |
String | SqlSchema |
int | WriteSynchronizationMode: |
int | CacheKeyConfiguration count. |
CacheKeyConfiguration | Structure of CacheKeyConfiguration:
Repeat for as many times as the CacheKeyConfiguration count that is obtained in the previous parameter. |
int | QueryEntity count. |
QueryEntity * count | Structure of QueryEntity (see below). |
QueryEntity
Type | Description |
---|---|
String | Key type name. |
String | Value type name. |
String | Table name. |
String | Key field name. |
String | Value field name. |
int | QueryField count |
QueryField * count | Structure of QueryField:
Repeat for as many times as the QueryField count that is obtained in the previous parameter. |
int | Alias count |
(String + String) * count | Field name aliases. |
int | QueryIndex count |
QueryIndex * count | Structure of QueryIndex:
|
String cacheName = "myCache";
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// Request header
writeRequestHeader(5, OP_CACHE_GET_CONFIGURATION, 1, out);
// Cache id
writeIntLittleEndian(cacheName.hashCode(), out);
// Flags = none
writeByteLittleEndian(0, out);
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
readResponseHeader(in);
// Config length
int configLen = readIntLittleEndian(in);
// CacheAtomicityMode
int cacheAtomicityMode = readIntLittleEndian(in);
// Backups
int backups = readIntLittleEndian(in);
// CacheMode
int cacheMode = readIntLittleEndian(in);
// CopyOnRead
boolean copyOnRead = readBooleanLittleEndian(in);
// Other configurations
OP_CACHE_CREATE_WITH_CONFIGURATION
Creates cache with provided configuration. An exception is thrown if the name is already in use.
Request Type | Description |
---|---|
Header | Request header. |
int | Length of the configuration in bytes (all the used configuration parameters). |
short | Number of configuration parameters. |
short + property type | Configuration Property data. Repeat for as many times as the number of configuration parameters. |
Any number of configuration parameters can be provided. Note that Name is required.
Cache configuration data is specified in key-value form, where key is short
property id and value is property-specific data. Table below describes all available parameters.
Property Code | Property Type | Description |
---|---|---|
2 | int | CacheAtomicityMode: |
3 | int | Backups |
1 | int | CacheMode: |
5 | boolean | CopyOnRead |
100 | String | DataRegionName |
405 | boolean | EagerTtl |
406 | boolean | StatisticsEnabled |
400 | String | GroupName |
402 | long | DefaultLockTimeout (milliseconds) |
403 | int | MaxConcurrentAsyncOperations |
206 | int | MaxQueryIterators |
0 | String | Name |
101 | bool | IsOnheapcacheEnabled |
404 | int | PartitionLossPolicy: |
202 | int | QueryDetailMetricsSize |
201 | int | QueryParallelism |
6 | bool | ReadFromBackup |
303 | int | RebalanceBatchSize |
304 | long | RebalanceBatchesPrefetchCount |
301 | long | RebalanceDelay (milliseconds) |
300 | int | RebalanceMode: SYNC = 0, ASYNC = 1, NONE = 2 |
305 | int | RebalanceOrder |
306 | long | RebalanceThrottle (milliseconds) |
302 | long | RebalanceTimeout (milliseconds) |
205 | bool | SqlEscapeAll |
204 | int | SqlIndexInlineMaxSize |
203 | String | SqlSchema |
4 | int | WriteSynchronizationMode: FULL_SYNC = 0, FULL_ASYNC = 1, PRIMARY_SYNC = 2 |
401 | int + CacheKeyConfiguration * count | CacheKeyConfiguration count + CacheKeyConfiguration Structure of CacheKeyConfiguration:
|
200 | int + QueryEntity * count | QueryEntity count + QueryEntity Structure of QueryEntity: (see below) |
QueryEntity
Type | Description |
---|---|
String | Key type name. |
String | Value type name. |
String | Table name. |
String | Key field name. |
String | Value field name. |
int | QueryField count |
QueryField | Structure of QueryField:
Repeat for as many times as the QueryField count. |
int | Alias count |
String + String | Field name alias. Repeat for as many times as the alias count. |
int | QueryIndex count |
QueryIndex | Structure of QueryIndex:
Repeat for as many times as the QueryIndex count. |
Response Type | Description |
---|---|
Header | Response header. |
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// Request header
writeRequestHeader(30, OP_CACHE_CREATE_WITH_CONFIGURATION, 1, out);
// Config length in bytes
writeIntLittleEndian(16, out);
// Number of properties
writeShortLittleEndian(2, out);
// Backups opcode
writeShortLittleEndian(3, out);
// Backups: 2
writeIntLittleEndian(2, out);
// Name opcode
writeShortLittleEndian(0, out);
// Name
writeString("myNewCache", out);
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
// Response header
readResponseHeader(in);
OP_CACHE_GET_OR_CREATE_WITH_CONFIGURATION
Creates cache with provided configuration. Does nothing if the name is already in use.
Request Type | Description |
---|---|
Header | Request header. |
CacheConfiguration | Cache configuration (see format above). |
Response Type | Description |
---|---|
Header | Response header. |
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
writeRequestHeader(30, OP_CACHE_GET_OR_CREATE_WITH_CONFIGURATION, 1, out);
// Config length in bytes
writeIntLittleEndian(16, out);
// Number of properties
writeShortLittleEndian(2, out);
// Backups opcode
writeShortLittleEndian(3, out);
// Backups: 2
writeIntLittleEndian(2, out);
// Name opcode
writeShortLittleEndian(0, out);
// Name
writeString("myNewCache", out);
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
// Response header
readResponseHeader(in);
OP_CACHE_DESTROY
Destroys cache with a given name.
Request Type | Description |
---|---|
Header | Request header. |
int | Cache ID: Java-style hash code of the cache name. |
Response Type | Description |
---|---|
Header | Response header. |
String cacheName = "myCache";
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
// Request header
writeRequestHeader(4, OP_CACHE_DESTROY, 1, out);
// Cache id
writeIntLittleEndian(cacheName.hashCode(), out);
// Send request
out.flush();
// Read result
DataInputStream in = new DataInputStream(socket.getInputStream());
readResponseHeader(in);
Updated 2 months ago