Hi Igor,
Could you check this message from user list? I can't find any reasons why readThrough doesn't work with Cassandra here Thanks, Evgenii ---------- Forwarded message ---------- From: Kenan Dalley <[hidden email]> Date: 2017-08-31 17:14 GMT+03:00 Subject: Re: Cassandra failing to ReadThrough using Cache.get(key) without preloading To: [hidden email] Trying this again... OUTPUT Output From Not Preloading the Cache: >>> Cassandra cache store example started. >>> Cache retrieve example started. >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [{}] >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [null] Cache size: 0 Output From Preloading the Cache: >>> Cassandra cache store example started. Loading cache... Cache size: 16 Entries... Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496833338465'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492599741108'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 144} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496746939945'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492081339596'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492173434330'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496487738766'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492599740168'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492254138310'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1497016098855'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492340538017'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496930018886'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1495969325403'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492430355581'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496590566077'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491999483231'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} >>> Cache retrieve example started. >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [{TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}=TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60}}] >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60}] Cache size: 16 CODE cassandra-ignite.xml <?xml version="1.0" encoding="UTF-8"?> <!-- 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. --> <!-- Ignite configuration with all defaults and enabled p2p deployment and enabled events. --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- Cassandra connection settings --> <import resource="classpath:connection-settings.xml" /> <bean id="testResponseCache_persistence_settings" class="org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings"> <!--<constructor-arg type="org.springframework.core.io.Resource" value="classpath:persistence-settings.xml" />--> <constructor-arg type="org.springframework.core.io.Resource" value="classpath:persistence-settings.full.xml" /> </bean> <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> <!-- Set to true to enable distributed class loading for examples, default is false. --> <property name="peerClassLoadingEnabled" value="true"/> <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. --> <property name="discoverySpi"> <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> <property name="ipFinder"> <!-- Ignite provides several options for automatic discovery that can be used instead os static IP based discovery. For information on all options refer to our documentation: http://apacheignite.readme.io/docs/cluster-config --> <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. --> <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">--> <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> <property name="addresses"> <list> <!-- In distributed environment, replace with actual host IP address. --> <value>127.0.0.1:47500..47509</value> </list> </property> </bean> </property> </bean> </property> <property name="cacheConfiguration"> <list> <bean class="org.apache.ignite.configuration.CacheConfiguration"> <property name="name" value="TestResponse" /> <property name="readThrough" value="true" /> <property name="writeThrough" value="true" /> <!-- <property name="writeBehindEnabled" value="true" /> --> <property name="cacheStoreFactory"> <bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory"> <!-- Datasource configuration bean which is responsible for Cassandra connection details --> <property name="dataSourceBean" value="cassandraDataSource" /> <!-- Persistent settings bean which is responsible for the details of how objects will be persisted to Cassandra --> <property name="persistenceSettingsBean" value="testResponseCache_persistence_settings" /> </bean> </property> </bean> </list> </property> </bean> </beans> persistence-settings.xml <persistence keyspace="dev_keyspace" table="testresponse" ttl="2592000"> <keyPersistence class="examples.cassandra_persistence_store.model.TestResponseKey" strategy="POJO"/> <valuePersistence class="examples.cassandra_persistence_store.model.TestResponse" strategy="POJO"/> </persistence> persistence-settings.full.xml (Tried in case I needed to fully define in the xml) <persistence keyspace="dev_keyspace" table="testresponse" ttl="2592000"> <keyPersistence class="examples.cassandra_persistence_store.model.TestResponseKey" strategy="POJO"> <partitionKey> <field name="col1"/> <field name="col2"/> </partitionKey> <clusterKey> <field name="col3"/> <field name="col4"/> </clusterKey> </keyPersistence> <valuePersistence class="examples.cassandra_persistence_store.model.TestResponse" strategy="POJO"> <field name="col5"/> <field name="col6"/> <field name="col7"/> <field name="col8"/> <field name="col9"/> <field name="col10"/> </valuePersistence> </persistence> connection-settings.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean id="loadBalancingPolicy" class="com.datastax.driver.core.policies.TokenAwarePolicy"> <constructor-arg type="com.datastax.driver.core.policies.LoadBalancingPolicy"> <bean class="com.datastax.driver.core.policies.RoundRobinPolicy"/> </constructor-arg> </bean> <util:list id="contactPoints" value-type="java.lang.String"> <value>hostname.com</value> </util:list> <bean id="cassandraDataSource" class="org.apache.ignite.cache.store.cassandra.datasource.DataSource"> <property name="contactPoints" ref="contactPoints"/> <property name="user" value="dev_keyspace"/> <property name="password" value="dev_keyspace_password"/> <property name="readConsistency" value="ONE"/> <property name="writeConsistency" value="ONE"/> <property name="loadBalancingPolicy" ref="loadBalancingPolicy"/> </bean> </beans> TestResponseKey package examples.cassandra_persistence_store.model; import java.io.Serializable; import org.apache.ignite.cache.affinity.AffinityKeyMapped; public class TestResponseKey implements Serializable { @AffinityKeyMapped private String col1; @AffinityKeyMapped private String col2; private String col3; private long col4; public TestResponseKey() { } public TestResponseKey(final String col1, final String col2, final String col3, final long col4) { this.col1 = col1; this.col2 = col2; this.col3 = col3; this.col4 = col4; } public String getCol1() { return col1; } public void setCol1(String col1) { this.col1 = col1; } public String getCol2() { return col2; } public void setCol2(String col2) { this.col2 = col2; } public String getCol3() { return col3; } public void setCol3(String col3) { this.col3 = col3; } public long getCol4() { return col4; } public void setCol4(long col4) { this.col4 = col4; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!(o instanceof EcuResponse)) { return false; } final TestResponseKey that = (TestResponseKey) o; if (this.col1 != null ? !this.col1.equals(that.col1) : that.col1 != null) { return false; } if (this.col2 != null ? !this.col2.equals(that.col2) : that.col2 != null) { return false; } if (this.col3 != null ? !this.col3.equals(that.col3) : that.col3 != null) { return false; } return (this.col4 != that.col4); } @Override public int hashCode() { int result = this.col1 != null ? this.col1.hashCode() : 0; result = (31 * result) + (this.col2 != null ? this.col2.hashCode() : 0); result = (31 * result) + (this.col3 != null ? this.col3.hashCode() : 0); return (31 * result) + Long.hashCode(this.col4); } @Override public String toString() { return "TestResponseKey: {" + "col1: '" + this.col1 + "'" + ", col2: '" + this.col2 + "'" + ", col3: '" + this.col3 + "'" + ", col4: '" + this.col4 + "'" + "}"; } } TestResponse package examples.cassandra_persistence_store.model; import java.io.Serializable; public class TestResponse implements Serializable { private long col5; private String col6; private String col7; private long col8; private String col9; private long col10; public TestResponse() { } public TestResponse(final Long col5, final String col6, final String col7, final Long col8, final String col9, final Long col10) { this.col5 = col5; this.col6 = col6; this.col7 = col7; this.col8 = col8; this.col9 = col9; this.col10 = col10; } public long getCol5() { return col5; } public void setCol5(long col5) { this.col5 = col5; } public String getCol6() { return col6; } public void setCol6(String col6) { this.col6 = col6; } public String getCol7() { return col7; } public void setCol7(String col7) { this.col7 = col7; } public long getCol8() { return col8; } public void setCol8(long col8) { this.col8 = col8; } public String getCol9() { return col9; } public void setCol9(String col9) { this.col9 = col9; } public long getCol10() { return col10; } public void setCol10(long col10) { this.col10 = col10; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } if (!(o instanceof TestResponse)) { return false; } TestResponse that = (TestResponse) o; if (this.col5 != that.col5) { return false; } if (this.col6 != null ? !this.col6.equals(that.col6) : that.col6 != null) { return false; } if (this.col7 != null ? !this.col7.equals(that.col7) : that.col7 != null) { return false; } if (this.col8 != that.col8) { return false; } if (this.col9 != null ? !this.col9.equals(that.col9) : that.col9 != null) { return false; } return this.col10 != that.col10; } @Override public int hashCode() { int result = Long.hashCode(this.col5); result = (31 * result) + (this.col6 != null ? this.col6.hashCode() : 0); result = (31 * result) + (this.col7 != null ? this.col7.hashCode() : 0); result = (31 * result) + Long.hashCode(this.col8); result = (31 * result) + (this.col9 != null ? this.col9.hashCode() : 0); return (31 * result) + Long.hashCode(this.col10); } @Override public String toString() { return "TestResponse: {" + "col5: " + this.col5 + ", col6: '" + this.col6 + "'" + ", col7: '" + this.col7 + "'" + ", col8: " + this.col8 + ", col9: '" + this.col9 + "'" + ", col10: " + this.col10 + '}'; } } ApplicationConfig package examples.cassandra_persistence_store.config; import org.apache.ignite.Ignite; import org.apache.ignite.Ignition; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class ApplicationConfig { @Bean public Ignite ignite() { return Ignition.start("cassandra-ignite.xml"); } } Application package examples.cassandra_persistence_store; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import javax.cache.Cache; import org.apache.commons.lang3.StringUtils; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheEntry; import org.apache.ignite.configuration.CacheConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.Banner; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; import examples.cassandra_persistence_store.model.TestResponse; import examples.cassandra_persistence_store.model.TestResponseKey; @SpringBootApplication public class Application implements CommandLineRunner { /** * Cache name. */ private static final String TEST_CACHE_NAME = TestResponse.class.getSimpleName(); private static TestResponseKey testKey = new TestResponseKey("text1", "$03", "FLAG", 1491843013376L); @Autowired Ignite ignite; public static void main(String... args) { SpringApplication app = new SpringApplication(Application.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); System.exit(0); } @Override public void run(String... strings) throws Exception { testResponse(); } private void testResponse() { System.out.println(">>> Cassandra cache store example started."); try (IgniteCache<TestResponseKey, TestResponse> cache = this.ignite .getOrCreateCache(new CacheConfiguration<TestResponseKey, TestResponse>( Application.TEST_CACHE_NAME))) { /* uncomment this to Preload Cache System.out.println(StringUtils.EMPTY); System.out.println("Loading cache..."); cache.loadCache(null, "select * from dev_keyspace.test_response " + " where col1 = 'text1' and col2 = '$03';"); System.out.println(StringUtils.EMPTY); System.out.println("Cache size: " + cache.size()); Iterable<Cache.Entry<TestResponseKey, TestResponse>> entries = cache.localEntries(); Iterator<Cache.Entry<TestResponseKey, TestResponse>> it = entries.iterator(); System.out.println(StringUtils.EMPTY); System.out.println("Entries..."); while (it.hasNext()) { Cache.Entry<TestResponseKey, TestResponse> entry = it.next(); System.out.println("Key: " + entry.getKey()+ ", Value: " + entry.getValue()); } */ // Read from C* System.out.println(StringUtils.EMPTY); System.out.println(">>> Cache retrieve example started."); Set<TestResponseKey> keys = new HashSet<>(); keys.add(Application.testKey); final Map<TestResponseKey, TestResponse> value2 = cache.getAll(keys); System.out.println(String.format(">>> Read from C*. Key: [%s], Value: [%s]", Application.testKey, value2)); final TestResponse value3 = cache.get(Application.testKey); System.out.println(String.format(">>> Read from C*. Key: [%s], Value: [%s]", Application.testKey, value3)); System.out.println(StringUtils.EMPTY); System.out.println("Cache size: " + cache.size()); } System.out.println(StringUtils.EMPTY); } } DATA Table Info tableName: test_response columns: col1 (text), col2 (text), col3 (text), col4 (bigint), col5 (bigint), col6 (text), col7 (text), col8 (bigint), col9 (text), col10 (bigint) partition key: col1, col2 cluster key: col3, col4 Inserts INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1491843013376,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1491999483231,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492081339596,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492173434330,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492254138310,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492340538017,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492430355581,60,null,null,'C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492599740168,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492599741108,144,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1495969325403,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496487738766,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496590566077,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496746939945,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496833338465,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496930018886,60,null,null,'03C39A9EFB7E',1,'NA'); INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1497016098855,60,null,null,'03C39A9EFB7E',1,'NA'); ------------------------------ Sent from the Apache Ignite Users mailing list archive <http://apache-ignite-users.70518.x6.nabble.com/> at Nabble.com. |
Hi Evgenii,
Thanks for forwarding this to me. For some reason previous e-mail was redirected to junk folder. I'll look at it on this coming week. Igor On Fri, Sep 8, 2017 at 11:40 AM, Evgenii Zhuravlev <[hidden email] > wrote: > Hi Igor, > > Could you check this message from user list? I can't find any reasons why > readThrough doesn't work with Cassandra here > > Thanks, > Evgenii > > ---------- Forwarded message ---------- > From: Kenan Dalley <[hidden email]> > Date: 2017-08-31 17:14 GMT+03:00 > Subject: Re: Cassandra failing to ReadThrough using Cache.get(key) without > preloading > To: [hidden email] > > > Trying this again... OUTPUT Output From Not Preloading the Cache: > > >>> Cassandra cache store example started. > > >>> Cache retrieve example started. > >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [{}] > >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [null] > > Cache size: 0 > > Output From Preloading the Cache: > > >>> Cassandra cache store example started. > > Loading cache... > > Cache size: 16 > > Entries... > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496833338465'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492599741108'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 144} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496746939945'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492081339596'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492173434330'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496487738766'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492599740168'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492254138310'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1497016098855'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492340538017'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496930018886'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1495969325403'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1492430355581'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1496590566077'}, Value: TestResponse: {col5: 0, col6: 'null', col7: '03C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > Key: TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491999483231'}, Value: TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60} > > >>> Cache retrieve example started. > >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [{TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}=TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60}}] > >>> Read from C*. Key: [TestResponseKey: {col1: 'text1', col2: '$03', col3: 'FLAG', col4: '1491843013376'}], Value: [TestResponse: {col5: 0, col6: 'null', col7: 'C39A9EFB7E', col8: 1, col9: 'NA', col10: 60}] > > Cache size: 16 > > CODE cassandra-ignite.xml > > <?xml version="1.0" encoding="UTF-8"?> > > <!-- > 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. > --> > > <!-- > Ignite configuration with all defaults and enabled p2p deployment and enabled events. > --> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd"> > > <!-- Cassandra connection settings --> > <import resource="classpath:connection-settings.xml" /> > > <bean id="testResponseCache_persistence_settings" class="org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings"> > <!--<constructor-arg type="org.springframework.core.io.Resource" value="classpath:persistence-settings.xml" />--> > <constructor-arg type="org.springframework.core.io.Resource" value="classpath:persistence-settings.full.xml" /> > </bean> > > <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> > <!-- Set to true to enable distributed class loading for examples, default is false. --> > <property name="peerClassLoadingEnabled" value="true"/> > > <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. --> > <property name="discoverySpi"> > <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> > <property name="ipFinder"> > <!-- > Ignite provides several options for automatic discovery that can be used > instead os static IP based discovery. For information on all options refer > to our documentation: http://apacheignite.readme.io/docs/cluster-config > --> > <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. --> > <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">--> > <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> > <property name="addresses"> > <list> > <!-- In distributed environment, replace with actual host IP address. --> > <value>127.0.0.1:47500..47509</value> > </list> > </property> > </bean> > </property> > </bean> > </property> > > <property name="cacheConfiguration"> > <list> > <bean class="org.apache.ignite.configuration.CacheConfiguration"> > <property name="name" value="TestResponse" /> > <property name="readThrough" value="true" /> > <property name="writeThrough" value="true" /> > <!-- <property name="writeBehindEnabled" value="true" /> --> > <property name="cacheStoreFactory"> > <bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory"> > <!-- Datasource configuration bean which is responsible for Cassandra connection details --> > <property name="dataSourceBean" value="cassandraDataSource" /> > <!-- Persistent settings bean which is responsible for the details of how objects will be persisted to Cassandra --> > <property name="persistenceSettingsBean" value="testResponseCache_persistence_settings" /> > </bean> > </property> > </bean> > </list> > </property> > </bean> > </beans> > > persistence-settings.xml > > <persistence keyspace="dev_keyspace" table="testresponse" ttl="2592000"> > <keyPersistence class="examples.cassandra_persistence_store.model.TestResponseKey" strategy="POJO"/> > <valuePersistence class="examples.cassandra_persistence_store.model.TestResponse" strategy="POJO"/> > </persistence> > > persistence-settings.full.xml (Tried in case I needed to fully define in > the xml) > > <persistence keyspace="dev_keyspace" table="testresponse" ttl="2592000"> > <keyPersistence class="examples.cassandra_persistence_store.model.TestResponseKey" strategy="POJO"> > <partitionKey> > <field name="col1"/> > <field name="col2"/> > </partitionKey> > <clusterKey> > <field name="col3"/> > <field name="col4"/> > </clusterKey> > </keyPersistence> > <valuePersistence class="examples.cassandra_persistence_store.model.TestResponse" strategy="POJO"> > <field name="col5"/> > <field name="col6"/> > <field name="col7"/> > <field name="col8"/> > <field name="col9"/> > <field name="col10"/> > </valuePersistence> > </persistence> > > connection-settings.xml > > <?xml version="1.0" encoding="UTF-8"?> > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:util="http://www.springframework.org/schema/util" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd > http://www.springframework.org/schema/util > http://www.springframework.org/schema/util/spring-util.xsd"> > > <bean id="loadBalancingPolicy" class="com.datastax.driver.core.policies.TokenAwarePolicy"> > <constructor-arg type="com.datastax.driver.core.policies.LoadBalancingPolicy"> > <bean class="com.datastax.driver.core.policies.RoundRobinPolicy"/> > </constructor-arg> > </bean> > > <util:list id="contactPoints" value-type="java.lang.String"> > <value>hostname.com</value> > </util:list> > > <bean id="cassandraDataSource" class="org.apache.ignite.cache.store.cassandra.datasource.DataSource"> > <property name="contactPoints" ref="contactPoints"/> > <property name="user" value="dev_keyspace"/> > <property name="password" value="dev_keyspace_password"/> > <property name="readConsistency" value="ONE"/> > <property name="writeConsistency" value="ONE"/> > <property name="loadBalancingPolicy" ref="loadBalancingPolicy"/> > </bean> > </beans> > > TestResponseKey > > package examples.cassandra_persistence_store.model; > > import java.io.Serializable; > import org.apache.ignite.cache.affinity.AffinityKeyMapped; > > public class TestResponseKey implements Serializable { > @AffinityKeyMapped > private String col1; > > @AffinityKeyMapped > private String col2; > > private String col3; > private long col4; > > public TestResponseKey() { } > > public TestResponseKey(final String col1, final String col2, final String col3, final long col4) { > this.col1 = col1; > this.col2 = col2; > this.col3 = col3; > this.col4 = col4; > } > > public String getCol1() { > return col1; > } > > public void setCol1(String col1) { > this.col1 = col1; > } > > public String getCol2() { > return col2; > } > > public void setCol2(String col2) { > this.col2 = col2; > } > > public String getCol3() { > return col3; > } > > public void setCol3(String col3) { > this.col3 = col3; > } > > public long getCol4() { > return col4; > } > > public void setCol4(long col4) { > this.col4 = col4; > } > > @Override > public boolean equals(Object o) { > if (this == o) { > return true; > } > if (o == null || getClass() != o.getClass()) { > return false; > } > > if (!(o instanceof EcuResponse)) { > return false; > } > > final TestResponseKey that = (TestResponseKey) o; > > if (this.col1 != null ? !this.col1.equals(that.col1) : that.col1 != null) { > return false; > } > > if (this.col2 != null ? !this.col2.equals(that.col2) : that.col2 != null) { > return false; > } > > if (this.col3 != null ? !this.col3.equals(that.col3) : that.col3 != null) { > return false; > } > return (this.col4 != that.col4); > } > > @Override > public int hashCode() { > int result = this.col1 != null ? this.col1.hashCode() : 0; > result = (31 * result) + (this.col2 != null ? this.col2.hashCode() : 0); > result = (31 * result) + (this.col3 != null ? this.col3.hashCode() : 0); > return (31 * result) + Long.hashCode(this.col4); > } > > @Override > public String toString() { > return "TestResponseKey: {" + > "col1: '" + this.col1 + "'" + > ", col2: '" + this.col2 + "'" + > ", col3: '" + this.col3 + "'" + > ", col4: '" + this.col4 + "'" + > "}"; > } > } > > TestResponse > > package examples.cassandra_persistence_store.model; > > import java.io.Serializable; > > public class TestResponse implements Serializable { > private long col5; > private String col6; > private String col7; > private long col8; > private String col9; > private long col10; > > public TestResponse() { } > > public TestResponse(final Long col5, final String col6, final String col7, final Long col8, > final String col9, final Long col10) { > this.col5 = col5; > this.col6 = col6; > this.col7 = col7; > this.col8 = col8; > this.col9 = col9; > this.col10 = col10; > } > > public long getCol5() { > return col5; > } > > public void setCol5(long col5) { > this.col5 = col5; > } > > public String getCol6() { > return col6; > } > > public void setCol6(String col6) { > this.col6 = col6; > } > > public String getCol7() { > return col7; > } > > public void setCol7(String col7) { > this.col7 = col7; > } > > public long getCol8() { > return col8; > } > > public void setCol8(long col8) { > this.col8 = col8; > } > > public String getCol9() { > return col9; > } > > public void setCol9(String col9) { > this.col9 = col9; > } > > public long getCol10() { > return col10; > } > > public void setCol10(long col10) { > this.col10 = col10; > } > > @Override > public boolean equals(Object o) { > if (this == o) { > return true; > } > if (o == null || getClass() != o.getClass()) { > return false; > } > > if (!(o instanceof TestResponse)) { > return false; > } > > TestResponse that = (TestResponse) o; > > if (this.col5 != that.col5) { > return false; > } > if (this.col6 != null ? !this.col6.equals(that.col6) : that.col6 != null) { > return false; > } > if (this.col7 != null ? !this.col7.equals(that.col7) : that.col7 != null) { > return false; > } > if (this.col8 != that.col8) { > return false; > } > if (this.col9 != null ? !this.col9.equals(that.col9) : that.col9 != null) { > return false; > } > return this.col10 != that.col10; > } > > @Override > public int hashCode() { > int result = Long.hashCode(this.col5); > result = (31 * result) + (this.col6 != null ? this.col6.hashCode() : 0); > result = (31 * result) + (this.col7 != null ? this.col7.hashCode() : 0); > result = (31 * result) + Long.hashCode(this.col8); > result = (31 * result) + (this.col9 != null ? this.col9.hashCode() : 0); > return (31 * result) + Long.hashCode(this.col10); > } > > @Override > public String toString() { > return "TestResponse: {" + > "col5: " + this.col5 + > ", col6: '" + this.col6 + "'" + > ", col7: '" + this.col7 + "'" + > ", col8: " + this.col8 + > ", col9: '" + this.col9 + "'" + > ", col10: " + this.col10 + > '}'; > } > } > > ApplicationConfig > > package examples.cassandra_persistence_store.config; > > import org.apache.ignite.Ignite; > import org.apache.ignite.Ignition; > import org.springframework.context.annotation.Bean; > import org.springframework.context.annotation.Configuration; > > @Configuration > public class ApplicationConfig { > > @Bean > public Ignite ignite() { > return Ignition.start("cassandra-ignite.xml"); > } > } > > Application > > package examples.cassandra_persistence_store; > > import java.util.HashSet; > import java.util.Iterator; > import java.util.Map; > import java.util.Set; > import javax.cache.Cache; > import org.apache.commons.lang3.StringUtils; > import org.apache.ignite.Ignite; > import org.apache.ignite.IgniteCache; > import org.apache.ignite.cache.CacheEntry; > import org.apache.ignite.configuration.CacheConfiguration; > import org.springframework.beans.factory.annotation.Autowired; > import org.springframework.boot.Banner; > import org.springframework.boot.CommandLineRunner; > import org.springframework.boot.SpringApplication; > import org.springframework.boot.autoconfigure.SpringBootApplication; > import org.springframework.context.ApplicationContext; > > import examples.cassandra_persistence_store.model.TestResponse; > import examples.cassandra_persistence_store.model.TestResponseKey; > > @SpringBootApplication > public class Application implements CommandLineRunner { > /** > * Cache name. > */ > private static final String TEST_CACHE_NAME = TestResponse.class.getSimpleName(); > > private static TestResponseKey testKey = new TestResponseKey("text1", "$03", > "FLAG", 1491843013376L); > > @Autowired > Ignite ignite; > > public static void main(String... args) { > SpringApplication app = new SpringApplication(Application.class); > app.setBannerMode(Banner.Mode.OFF); > app.run(args); > System.exit(0); > } > > @Override > public void run(String... strings) throws Exception { > testResponse(); > } > > private void testResponse() { > System.out.println(">>> Cassandra cache store example started."); > try (IgniteCache<TestResponseKey, TestResponse> cache = this.ignite > .getOrCreateCache(new CacheConfiguration<TestResponseKey, TestResponse>( > Application.TEST_CACHE_NAME))) { > /* uncomment this to Preload Cache > System.out.println(StringUtils.EMPTY); > System.out.println("Loading cache..."); > > cache.loadCache(null, > "select * from dev_keyspace.test_response " + > " where col1 = 'text1' and col2 = '$03';"); > System.out.println(StringUtils.EMPTY); > System.out.println("Cache size: " + cache.size()); > > Iterable<Cache.Entry<TestResponseKey, TestResponse>> entries = cache.localEntries(); > Iterator<Cache.Entry<TestResponseKey, TestResponse>> it = entries.iterator(); > System.out.println(StringUtils.EMPTY); > System.out.println("Entries..."); > while (it.hasNext()) { > Cache.Entry<TestResponseKey, TestResponse> entry = it.next(); > System.out.println("Key: " + entry.getKey()+ ", Value: " + entry.getValue()); > } > */ > // Read from C* > System.out.println(StringUtils.EMPTY); > System.out.println(">>> Cache retrieve example started."); > Set<TestResponseKey> keys = new HashSet<>(); > keys.add(Application.testKey); > final Map<TestResponseKey, TestResponse> value2 = cache.getAll(keys); > System.out.println(String.format(">>> Read from C*. Key: [%s], Value: [%s]", Application.testKey, value2)); > final TestResponse value3 = cache.get(Application.testKey); > System.out.println(String.format(">>> Read from C*. Key: [%s], Value: [%s]", Application.testKey, value3)); > System.out.println(StringUtils.EMPTY); > System.out.println("Cache size: " + cache.size()); > } > System.out.println(StringUtils.EMPTY); > } > } > > DATA Table Info > > tableName: test_response > columns: col1 (text), col2 (text), col3 (text), col4 (bigint), col5 (bigint), col6 (text), col7 (text), col8 (bigint), col9 (text), col10 (bigint) > partition key: col1, col2 > cluster key: col3, col4 > > Inserts > > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1491843013376,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1491999483231,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492081339596,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492173434330,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492254138310,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492340538017,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492430355581,60,null,null,'C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492599740168,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1492599741108,144,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1495969325403,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496487738766,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496590566077,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496746939945,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496833338465,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1496930018886,60,null,null,'03C39A9EFB7E',1,'NA'); > INSERT INTO test_response (col1,col2,col3,col4,col10,col5,col6,col7,col8,col9) VALUES ('text1','$03','FLAG',1497016098855,60,null,null,'03C39A9EFB7E',1,'NA'); > > > ------------------------------ > Sent from the Apache Ignite Users mailing list archive > <http://apache-ignite-users.70518.x6.nabble.com/> at Nabble.com. > > |
Free forum by Nabble | Edit this page |