You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by elopez779 <en...@gmail.com> on 2017/09/26 13:08:57 UTC

Cassandra Persistence problem

Hello, Although I've read many topics on this subject, I haven't found a
solution to my problem. First of all, I'm a beginner with Ignite and I'm a
just arrived to my project. I need to use Ignite as a memory cache for
Cassandra and I have tried an example applicaction to prove it.

We cannot use Spring config files so, I have to configure Ignite
programmatically. The example I've tried is closely related with the example
explained by Riccardo Iacomini in

https://medium.com/@iacomini.riccardo/how-to-use-apache-ignite-as-cassandra-cache-layer-e24659e31243

I think the persistence XML file is standard and there is nothing wrong in
it:

<persistence keyspace="pruebasenrique" table="tablaprueba">
    <keyspaceOptions>
        REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}
        AND DURABLE_WRITES = true
    </keyspaceOptions>
    <tableOption>
        comment = 'Cache test'
        AND read_repair_chance = 0.2
    </tableOption>
    <keyPersistence class="java.lang.String" strategy="PRIMITIVE"
column="key" />
    <valuePersistence class="com.ejemploIgnite.EjemploIgnite.ClaseLectura"
strategy="POJO" />
</persistence>


And finally the code. Practically all the code is inserted in a class
because this wanted to be a quick test:

---------------------------------------------------------------------------

IgniteConfiguration cfg = new IgniteConfiguration();
CacheConfiguration configuration = new CacheConfiguration();
configuration.setName("cache-prueba");

// Access to Cassandra through SSL	        
String truststorePath = "C:\\certificates\\cassandra.keystore";
String truststorePassword = "XXXXXXXX";
String keystorePath = "C:\\certificates\\cliente-cert.p12";
String keystorePassword = "XXXXXXX";
        	
SSLContext context = getSSLContext(truststorePath, truststorePassword,
keystorePath, keystorePassword);
String [] cipherSuites =
{"TLS_RSA_WITH_AES_128_CBC_SHA","TLS_DHE_RSA_WITH_AES_128_CBC_SHA","TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"};

DataSource dataSource = new DataSource();
dataSource.setContactPoints("192.168.4.167");
dataSource.setPort(9042);
        	
SSLOptions sslOptions = new SSLOptions(context, cipherSuites); 
dataSource.setSslOptions(sslOptions);
dataSource.setUseSSL(true);
        	
RoundRobinPolicy robinPolicy = new RoundRobinPolicy();
dataSource.setLoadBalancingPolicy(robinPolicy);
dataSource.setReadConsistency("ONE");
dataSource.setWriteConsistency("ONE");
	        
String persistenceSettingsXml = FileUtils.readFileToString(new
File("C:\\01\\cache-prueba.xml"), "utf-8");
KeyValuePersistenceSettings persistenceSettings = new
KeyValuePersistenceSettings(persistenceSettingsXml);
CassandraCacheStoreFactory cacheStoreFactory = new
CassandraCacheStoreFactory();
cacheStoreFactory.setDataSource(dataSource);
cacheStoreFactory.setPersistenceSettings(persistenceSettings);
configuration.setCacheStoreFactory(cacheStoreFactory);
configuration.setWriteThrough(true);
configuration.setWriteBehindEnabled(true);
configuration.setReadThrough(true);
	
//  Sets the cache configuration
cfg.setCacheConfiguration(configuration);
	
//  Starting Ignite
Ignition.setClientMode(true);
Ignite ignite = Ignition.start(cfg);
	        
final IgniteCache<String, ClaseLectura> cache =
ignite.getOrCreateCache("cache-prueba");
	        
for (int i = 0; i < 50; i++)
{
    cache.put(String.valueOf(i), new ClaseLectura("AAA", 10));
}

---------------------------------------------------------------------------

ClaseLectura is as follows:

public class ClaseLectura implements Serializable {
	private String value1;
	private int value2;
	
	public ClaseLectura() {
		super();
	}
	
	public ClaseLectura(String v1, int v2) {
		this.value1 = v1;
		this.value2 = v2;
	}
	
	public String getValue1() { return value1; }
	public int getValue2() { return value2; }
	
	public void setValue1(String v1) { value1 = v1; }
	public void setValue2(int v2) { value2 = v2; }
	
	public String toString() {
		return value1 + " ; " + String.valueOf(value2);
	}
}

cache-prueba.xml (the persistence description) is read correctly as I can
see while debugging.

I start an Ignite server (ignite.bat) and I start the application (which
starts Ignite client) and everything seems OK. The for loop is executed
correctly but I don't see any result in the cassandra table. The SSL
connection is Ok because I've tried it with another app connecting directly
to Cassandra. I've read many many topics but I don't find where is my error
(As said before, I'm a beginner). Sorry for my really long mail and for my
broken english. Please, any kind of help will be really appreciated. Thanks. 



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Cassandra Persistence problem

Posted by elopez779 <en...@gmail.com>.
Hi Denis

Thank you for your answer.

I deleted my post five minutes after publish it because I thought nobody had
read it and I found the solution in that moment. The problem was that the
Ignite embedded in the application had setClientMode actived (true), but my
intention was use the embedded Ignite as a server, not as a client.

I started Ignite (Ignite.bat) because I thought that was neccessary. I
hadn't still learned that embedded Ignite can be server or client 
(beginner, do you remember? :-(

Thank you again

Enrique



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Cassandra Persistence problem

Posted by Denis Mekhanikov <dm...@gmail.com>.
Hi!

Try commenting out this line: configuration.setWriteBehindEnabled(true);
Write behind mode makes a cache wait for a moment, when there is enough
updates to write them in a batch. Disabling this mode should help.

Denis

вт, 26 сент. 2017 г. в 16:09, elopez779 <en...@gmail.com>:

> Hello, Although I've read many topics on this subject, I haven't found a
> solution to my problem. First of all, I'm a beginner with Ignite and I'm a
> just arrived to my project. I need to use Ignite as a memory cache for
> Cassandra and I have tried an example applicaction to prove it.
>
> We cannot use Spring config files so, I have to configure Ignite
> programmatically. The example I've tried is closely related with the
> example
> explained by Riccardo Iacomini in
>
>
> https://medium.com/@iacomini.riccardo/how-to-use-apache-ignite-as-cassandra-cache-layer-e24659e31243
>
> I think the persistence XML file is standard and there is nothing wrong in
> it:
>
> <persistence keyspace="pruebasenrique" table="tablaprueba">
>     <keyspaceOptions>
>         REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' :
> 1}
>         AND DURABLE_WRITES = true
>     </keyspaceOptions>
>     <tableOption>
>         comment = 'Cache test'
>         AND read_repair_chance = 0.2
>     </tableOption>
>     <keyPersistence class="java.lang.String" strategy="PRIMITIVE"
> column="key" />
>     <valuePersistence class="com.ejemploIgnite.EjemploIgnite.ClaseLectura"
> strategy="POJO" />
> </persistence>
>
>
> And finally the code. Practically all the code is inserted in a class
> because this wanted to be a quick test:
>
> ---------------------------------------------------------------------------
>
> IgniteConfiguration cfg = new IgniteConfiguration();
> CacheConfiguration configuration = new CacheConfiguration();
> configuration.setName("cache-prueba");
>
> // Access to Cassandra through SSL
> String truststorePath = "C:\\certificates\\cassandra.keystore";
> String truststorePassword = "XXXXXXXX";
> String keystorePath = "C:\\certificates\\cliente-cert.p12";
> String keystorePassword = "XXXXXXX";
>
> SSLContext context = getSSLContext(truststorePath, truststorePassword,
> keystorePath, keystorePassword);
> String [] cipherSuites =
>
> {"TLS_RSA_WITH_AES_128_CBC_SHA","TLS_DHE_RSA_WITH_AES_128_CBC_SHA","TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"};
>
> DataSource dataSource = new DataSource();
> dataSource.setContactPoints("192.168.4.167");
> dataSource.setPort(9042);
>
> SSLOptions sslOptions = new SSLOptions(context, cipherSuites);
> dataSource.setSslOptions(sslOptions);
> dataSource.setUseSSL(true);
>
> RoundRobinPolicy robinPolicy = new RoundRobinPolicy();
> dataSource.setLoadBalancingPolicy(robinPolicy);
> dataSource.setReadConsistency("ONE");
> dataSource.setWriteConsistency("ONE");
>
> String persistenceSettingsXml = FileUtils.readFileToString(new
> File("C:\\01\\cache-prueba.xml"), "utf-8");
> KeyValuePersistenceSettings persistenceSettings = new
> KeyValuePersistenceSettings(persistenceSettingsXml);
> CassandraCacheStoreFactory cacheStoreFactory = new
> CassandraCacheStoreFactory();
> cacheStoreFactory.setDataSource(dataSource);
> cacheStoreFactory.setPersistenceSettings(persistenceSettings);
> configuration.setCacheStoreFactory(cacheStoreFactory);
> configuration.setWriteThrough(true);
> configuration.setWriteBehindEnabled(true);
> configuration.setReadThrough(true);
>
> //  Sets the cache configuration
> cfg.setCacheConfiguration(configuration);
>
> //  Starting Ignite
> Ignition.setClientMode(true);
> Ignite ignite = Ignition.start(cfg);
>
> final IgniteCache<String, ClaseLectura> cache =
> ignite.getOrCreateCache("cache-prueba");
>
> for (int i = 0; i < 50; i++)
> {
>     cache.put(String.valueOf(i), new ClaseLectura("AAA", 10));
> }
>
> ---------------------------------------------------------------------------
>
> ClaseLectura is as follows:
>
> public class ClaseLectura implements Serializable {
>         private String value1;
>         private int value2;
>
>         public ClaseLectura() {
>                 super();
>         }
>
>         public ClaseLectura(String v1, int v2) {
>                 this.value1 = v1;
>                 this.value2 = v2;
>         }
>
>         public String getValue1() { return value1; }
>         public int getValue2() { return value2; }
>
>         public void setValue1(String v1) { value1 = v1; }
>         public void setValue2(int v2) { value2 = v2; }
>
>         public String toString() {
>                 return value1 + " ; " + String.valueOf(value2);
>         }
> }
>
> cache-prueba.xml (the persistence description) is read correctly as I can
> see while debugging.
>
> I start an Ignite server (ignite.bat) and I start the application (which
> starts Ignite client) and everything seems OK. The for loop is executed
> correctly but I don't see any result in the cassandra table. The SSL
> connection is Ok because I've tried it with another app connecting directly
> to Cassandra. I've read many many topics but I don't find where is my error
> (As said before, I'm a beginner). Sorry for my really long mail and for my
> broken english. Please, any kind of help will be really appreciated.
> Thanks.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>