Skip to content

Commit b147c3a

Browse files
committed
Merge branch 'master' into ignite-28607
2 parents 8c7fa81 + d40158d commit b147c3a

36 files changed

Lines changed: 635 additions & 32 deletions

File tree

docs/_docs/SQL/schemas.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CREATE TABLE City (
8585
) WITH "backups=1, CACHE_NAME=City";
8686
----
8787

88-
See the link:sql-reference/ddl#create-table[CREATE TABLE] page for more details.
88+
See the link:sql-reference/ddl#create-table[CREATE TABLE] page for more details, including creating a table on an existing cache.
8989

9090
If you do not use this parameter, the cache name is defined in the following format (in capital letters):
9191

@@ -140,4 +140,4 @@ cache.put(2, invalidPerson); // CacheException wrapping IgniteSQLException when
140140

141141
With the default configuration (validation disabled for non-indexed columns), the `put` above succeeds even though the stored `BinaryObject` does not match the SQL schema. Turning on validation causes Ignite to reject the update, protecting the table from malformed records.
142142

143-
Enable the option when you need stronger guarantees that dynamic or user-provided data cannot break the table definition, and keep it disabled when the overhead of additional checks outweighs the risk of incorrect data.
143+
Enable the option when you need stronger guarantees that dynamic or user-provided data cannot break the table definition, and keep it disabled when the overhead of additional checks outweighs the risk of incorrect data.

docs/_docs/sql-reference/ddl.adoc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ This page encompasses all data definition language (DDL) commands supported by I
2121

2222
== CREATE TABLE
2323

24-
The command creates a new Ignite cache and defines a SQL table on top of it. The underlying cache stores the data in
25-
the form of key-value pairs while the table allows processing the data with SQL queries.
24+
The command defines a SQL table on top of an Ignite cache. The underlying cache stores the data in the form of
25+
key-value pairs while the table allows processing the data with SQL queries. By default, Ignite creates a new cache for
26+
the table. If `CACHE_NAME` points to an existing cache, Ignite defines the SQL table on top of that cache.
2627

2728
The table will reside in the link:SQL/schemas[Schema] specified in the connection parameters. If no schema is specified,
2829
the `PUBLIC` will be used as a default.
@@ -57,8 +58,9 @@ Parameters:
5758
sets the write synchronization mode for the underlying cache. If neither this nor the `TEMPLATE` parameter is set, then the cache is created with `FULL_SYNC` mode enabled.
5859
** `CACHE_GROUP=<group name>` - specifies the link:configuring-caches/cache-groups[group name] the underlying cache belongs to.
5960
** `AFFINITY_KEY=<affinity key column name>` - specifies an link:data-modeling/affinity-collocation[affinity key] name which is a column of the `PRIMARY KEY` constraint.
60-
** `CACHE_NAME=<custom name of the new cache>` - the name of the underlying cache created by the command,
61-
or the `SQL_{SCHEMA_NAME}_{TABLE}` format will be used if the parameter not specified.
61+
** `CACHE_NAME=<cache name>` - the name of the underlying cache. If the cache does not exist, it is created by the command.
62+
If the cache already exists, Ignite tries to define the table on top of it.
63+
If the parameter is not specified, the `SQL_{SCHEMA_NAME}_{TABLE}` format is used for the new cache name.
6264
** `DATA_REGION=<existing data region name>` - name of the link:memory-configuration/data-regions[data region] where table entries should be stored. By default, Ignite stores all the data in a default region.
6365
** `PARALLELISM=<number of SQL execution threads>` - SQL queries are executed by a single thread on each node by default, but certain scenarios can benefit from multi-threaded execution, see link:perf-and-troubleshooting/sql-tuning#query-parallelism[Query Parallelism] for details.
6466
** `KEY_TYPE=<custom name of the key type>` - sets the name of the custom key type that is used from the key-value APIs in Ignite. The name should correspond to a Java, .NET, or C++ class, or it can be a random one if link:data-modeling/data-modeling#binary-object-format[BinaryObjects] is used instead of a custom class. The number of fields and their types in the custom key type has to correspond to the `PRIMARY KEY`. Refer to the <<Use non-SQL API>> section below for more details.
@@ -118,6 +120,26 @@ CREATE TABLE IF NOT EXISTS Person (
118120
) WITH "template=partitioned,backups=1,affinity_key=city_id,CACHE_NAME=Person,KEY_TYPE=PersonKey,VALUE_TYPE=PersonValue";
119121
----
120122

123+
=== Create Table on an Existing Cache
124+
125+
If `CACHE_NAME` points to an existing cache, Ignite adds only SQL metadata to that cache. This is allowed only when the
126+
cache does not already have query entities, for example from `CacheConfiguration.setQueryEntities(...)` or
127+
`CacheConfiguration.setIndexedTypes(...)`.
128+
129+
When the existing cache has a SQL schema configured, the table must be created in the same schema. If the schema does not
130+
match, the command fails with an `Invalid schema` error.
131+
132+
[source,sql]
133+
----
134+
CREATE TABLE my_schema.Person (
135+
id INT PRIMARY KEY,
136+
name VARCHAR
137+
) WITH "CACHE_NAME=PersonCache";
138+
----
139+
140+
Cache creation parameters such as `TEMPLATE`, `BACKUPS`, `CACHE_GROUP`, `DATA_REGION`, `ATOMICITY`,
141+
`WRITE_SYNCHRONIZATION_MODE`, and other cache configuration options are not applied to an existing cache.
142+
121143

122144
=== Use non-Upper Case Columns
123145

modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.ignite.util.GridCommandHandlerIndexingTest;
3535
import org.apache.ignite.util.GridCommandHandlerIndexingWithSSLTest;
3636
import org.apache.ignite.util.GridCommandHandlerLegacyClientTest;
37+
import org.apache.ignite.util.GridCommandHandlerManagementPoolTest;
3738
import org.apache.ignite.util.GridCommandHandlerMetadataTest;
3839
import org.apache.ignite.util.GridCommandHandlerSslTest;
3940
import org.apache.ignite.util.GridCommandHandlerTest;
@@ -80,7 +81,8 @@
8081
BaselineEventsRemoteTest.class,
8182

8283
GridCommandHandlerWalTest.class,
83-
GridCommandHandlerCheckpointTest.class
84+
GridCommandHandlerCheckpointTest.class,
85+
GridCommandHandlerManagementPoolTest.class,
8486
})
8587
public class IgniteControlUtilityTestSuite {
8688
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.util;
19+
20+
import java.util.concurrent.CountDownLatch;
21+
import java.util.concurrent.TimeUnit;
22+
import org.apache.ignite.Ignite;
23+
import org.apache.ignite.cache.query.SqlFieldsQuery;
24+
import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
25+
import org.apache.ignite.client.IgniteClient;
26+
import org.apache.ignite.cluster.ClusterState;
27+
import org.apache.ignite.configuration.CacheConfiguration;
28+
import org.apache.ignite.configuration.ClientConfiguration;
29+
import org.apache.ignite.configuration.ClientConnectorConfiguration;
30+
import org.apache.ignite.internal.IgniteInternalFuture;
31+
import org.apache.ignite.internal.processors.query.QueryUtils;
32+
import org.apache.ignite.testframework.GridTestUtils;
33+
import org.junit.Test;
34+
35+
import static org.apache.ignite.Ignition.startClient;
36+
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
37+
38+
/**
39+
* Tests management pool usage for management tasks.
40+
*/
41+
public class GridCommandHandlerManagementPoolTest extends GridCommandHandlerClusterPerMethodAbstractTest {
42+
/** */
43+
private static final long TIMEOUT = 10_000L;
44+
45+
/** */
46+
@Test
47+
public void testManagementTasksWorksWhenClientPoolBlocked() throws Exception {
48+
Ignite ignite = startGrid(0);
49+
50+
assertEquals(EXIT_CODE_OK, execute("--set-state", ClusterState.ACTIVE.name()));
51+
52+
ignite.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
53+
.setSqlSchema(QueryUtils.DFLT_SCHEMA)
54+
.setSqlFunctionClasses(TestSqlFunctions.class)
55+
.setIndexedTypes(Integer.class, String.class)
56+
);
57+
58+
TestSqlFunctions.latch = new CountDownLatch(1);
59+
60+
try (IgniteClient client = startClient(new ClientConfiguration().setAddresses("127.0.0.1:10800"))) {
61+
// Block client pool by SQL queries.
62+
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(
63+
() -> client.query(new SqlFieldsQuery("SELECT wait_latch()")).getAll(),
64+
ClientConnectorConfiguration.DFLT_THREAD_POOL_SIZE, "client-thread");
65+
66+
// Check that management tasks still can be processed.
67+
assertEquals(EXIT_CODE_OK, execute("--state")); // Native command.
68+
assertEquals(EXIT_CODE_OK, execute("--checkpoint")); // Multi-node task command.
69+
70+
TestSqlFunctions.latch.countDown();
71+
72+
fut.get(TIMEOUT, TimeUnit.MILLISECONDS);
73+
}
74+
}
75+
76+
/** */
77+
public static class TestSqlFunctions {
78+
/** */
79+
private static CountDownLatch latch;
80+
81+
/** */
82+
@QuerySqlFunction
83+
public static boolean wait_latch() {
84+
try {
85+
latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
86+
}
87+
catch (InterruptedException ignored) {
88+
return false;
89+
}
90+
91+
return true;
92+
}
93+
}
94+
}

modules/core/src/main/java/org/apache/ignite/configuration/DataStorageConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.ignite.internal.processors.cache.persistence.file.AsyncFileIOFactory;
2424
import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory;
2525
import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
26+
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
2627
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
2728
import org.apache.ignite.internal.util.typedef.internal.A;
2829
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -301,6 +302,7 @@ public class DataStorageConfiguration implements Serializable {
301302
private boolean alwaysWriteFullPages = DFLT_WAL_ALWAYS_WRITE_FULL_PAGES;
302303

303304
/** Factory to provide I/O interface for data storage files */
305+
@GridToStringExclude
304306
private FileIOFactory fileIOFactory =
305307
IgniteSystemProperties.getBoolean(IGNITE_USE_ASYNC_FILE_IO_FACTORY, DFLT_USE_ASYNC_FILE_IO_FACTORY) ?
306308
new AsyncFileIOFactory() : new RandomAccessFileIOFactory();

modules/core/src/main/java/org/apache/ignite/configuration/EncryptionConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
package org.apache.ignite.configuration;
1919

2020
import java.io.Serializable;
21+
22+
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
2123
import org.apache.ignite.internal.util.typedef.internal.A;
2224

2325
/**
2426
* Encryption configuration.
2527
*/
28+
@GridToStringExclude
2629
public class EncryptionConfiguration implements Serializable {
2730
/** */
2831
private static final long serialVersionUID = 0L;

modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.ignite.failure.FailureHandler;
5050
import org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager;
5151
import org.apache.ignite.internal.processors.odbc.ClientListenerProcessor;
52+
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
5253
import org.apache.ignite.internal.util.typedef.internal.A;
5354
import org.apache.ignite.internal.util.typedef.internal.S;
5455
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -314,6 +315,7 @@ public class IgniteConfiguration implements IgniteConfigurationDefaults {
314315
private String igniteWorkDir;
315316

316317
/** MBean server. */
318+
@GridToStringExclude
317319
private MBeanServer mbeanSrv;
318320

319321
/** Local node ID. */
@@ -398,6 +400,7 @@ public class IgniteConfiguration implements IgniteConfigurationDefaults {
398400
private LoadBalancingSpi[] loadBalancingSpi;
399401

400402
/** Indexing SPI. */
403+
@GridToStringExclude
401404
private IndexingSpi indexingSpi;
402405

403406
/** Address resolver. */

modules/core/src/main/java/org/apache/ignite/configuration/SystemDataRegionConfiguration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.Serializable;
2020
import org.apache.ignite.internal.util.typedef.internal.A;
21+
import org.apache.ignite.internal.util.typedef.internal.S;
2122

2223
/**
2324
* This class allows defining system data region configuration with various parameters for Apache Ignite
@@ -90,4 +91,9 @@ public SystemDataRegionConfiguration setMaxSize(long maxSize) {
9091

9192
return this;
9293
}
94+
95+
/** {@inheritDoc} */
96+
@Override public String toString() {
97+
return S.toString(SystemDataRegionConfiguration.class, this);
98+
}
9399
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ private String taskName() {
767767
@Override public boolean isPrimaryOnly() {
768768
return locOnly && !skipPrimaryCheck;
769769
}
770+
771+
@Override public boolean isLocalOnly() {
772+
return locOnly;
773+
}
770774
};
771775

772776
CacheContinuousQueryManager mgr = manager(ctx);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,7 @@ public void onEntryUpdated(CacheContinuousQueryEvent<K, V> evt, boolean primary,
131131
* @return {@code True} if this listener should be called on events on primary partitions only.
132132
*/
133133
public boolean isPrimaryOnly();
134+
135+
/** @return {@code true} if this listener belongs to a local continuous query. */
136+
public boolean isLocalOnly();
134137
}

0 commit comments

Comments
 (0)