Description
When you use a template for your table, it takes the affinityMapper field from this template, which was set at the moment of creating a context for a different type without any keyConfigurations. This leads to the problem with accessing data from SQL if it was inserted using Key-value API
Here is a code to reproduce the issue:
Ignition.setClientMode(true); Ignite ignite = Ignition.start("examples/config/example-ignite.xml"); ignite.cluster().active(true); IgniteCache cache = ignite.getOrCreateCache("test"); cache.query(new SqlFieldsQuery("CREATE TABLE IF NOT EXISTS TEST\n" + "(\n" + " TEST_ID NUMBER(15) NOT NULL,\n" + " TEST_FIELD VARCHAR2(100),\n" + " PRIMARY KEY (TEST_ID)\n" + ") with \"TEMPLATE=TEST_TEMPLATE,KEY_TYPE=TEST_KEY ,CACHE_NAME=TEST_CACHE , VALUE_TYPE=TEST_VALUE,ATOMICITY=TRANSACTIONAL\";").setSchema("PUBLIC")); for (int i = 0; i < 100; i++) { BinaryObjectBuilder keyBuilder = ignite.binary().builder("TEST_KEY"); keyBuilder.setField("TEST_ID", new BigDecimal(111111111111111l + i)); BinaryObjectBuilder valueBuilder = ignite.binary().builder("TEST_VALUE"); valueBuilder.setField("TEST_FIELD", "123123" + i); ignite.cache("TEST_CACHE").withKeepBinary().put(keyBuilder.build(), valueBuilder.build()); } //returns 100 rows as we expect System.out.println("FOUND:" + ignite.cache("TEST_CACHE").query(new SqlFieldsQuery("Select * from TEST")).getAll().size()); //returns 0 rows - should return 1 System.out.println("FOUND:" + ignite.cache("TEST_CACHE").query(new SqlFieldsQuery("Select TEST_FIELD from TEST where TEST_ID = 111111111111111")).getAll()); for (int i = 0; i < 100; i++) //returns 0 rows - should return 1 System.out.println("FOUND:" + ignite.cache("TEST_CACHE").query(new SqlFieldsQuery("Select TEST_FIELD from TEST where TEST_ID = " + (111111111111111l + i))).getAll());
Here is a test template:
<bean class="org.apache.ignite.configuration.CacheConfiguration"> <property name="name" value="TEST_TEMPLATE*"/> </bean>
Steps to reproduce:
1. Start a server node, for example, using ExampleNodeStartup.
2. Start a client node using the code provided above with the template in configuration.
It will show that it can't find these rows in the cache.
Possible quickfix:
set affinityMapper to cfgTemplate in GridCacheProcessor.getConfigFromTemplate:
cfgTemplate.setAffinityMapper(null)
Also, interesting thing - if you replace = with IS, then everything works.
Attachments
Issue Links
- links to