0
votes

This question is strictly related to my previous one.

Quick summary: I am struggling to configure Cassandra as persistence layer for my Ignite 2.0 cache. It fails with write-behind operations because of:

java.lang.IllegalArgumentException: object is not an instance of declaring class

I tried to play with the schema on Cassandra, fields configuration in the persistence settings, cache properties etc. but I am not able to overcome that. The following is last configuration I tried:

Persistence settings:

<persistence keyspace="ignite" table="odbc_test" ttl="86400">
    <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.riccamini.ignite.ValueClass" strategy="POJO"/>
</persistence>

ValueClass:

public class ValueClass implements Serializable{
    @QuerySqlField
    private int numberOne;
    @QuerySqlField
    private int numberTwo;

    public int getNumberOne(){ return numberOne;}

    public int getNumberTwo(){ return numberTwo;}

    public void setNumberOne(int value){
        numberOne = value;
    }

    public void setNumberTwo(int value){
        numberTwo = value;
    }
}

Cassandra's table:

CREATE TABLE ignite.odbc_test (
    key text PRIMARY KEY,
    numberone int,
    numbertwo int);

Ignite's configuration:

boolean persistence = true;

IgniteConfiguration cfg = new IgniteConfiguration();
CacheConfiguration<String, ValueClass> configuration = new CacheConfiguration<String, ValueClass>();

configuration.setName("test-cache");
configuration.setIndexedTypes(String.class, ValueClass.class);

if(persistence){
    //  Configuring Cassandra's persistence
    DataSource dataSource = new DataSource();
    dataSource.setContactPoints("172.17.0.2");
    RoundRobinPolicy robinPolicy = new RoundRobinPolicy();
    dataSource.setLoadBalancingPolicy(robinPolicy);
    dataSource.setReadConsistency("ONE");
    dataSource.setWriteConsistency("ONE");
    String persistenceSettingsXml = FileUtils.readFileToString(new File(persistenceSettingsConfig), "utf-8");
    KeyValuePersistenceSettings persistenceSettings = new KeyValuePersistenceSettings(persistenceSettingsXml);
    CassandraCacheStoreFactory cacheStoreFactory = new CassandraCacheStoreFactory();
    cacheStoreFactory.setDataSource(dataSource);
    cacheStoreFactory.setPersistenceSettings(persistenceSettings);
    configuration.setCacheStoreFactory(cacheStoreFactory);
    configuration.setWriteThrough(true);
    configuration.setReadThrough(true);
    configuration.setWriteBehindEnabled(true);
    configuration.setStoreKeepBinary(true);
    }


//  Setting cache configuration
cfg.setCacheConfiguration(configuration);

//  Configuring ODBC
OdbcConfiguration odbcConfig = new OdbcConfiguration();
odbcConfig.setMaxOpenCursors(100);
cfg.setOdbcConfiguration(odbcConfig);

//  Starting Ignite
Ignite ignite = Ignition.start(cfg);

Complete stack trace:

SEVERE: Failed to process 1 of 1 elements, during BULK_WRITE operation with Cassandra
class org.apache.ignite.IgniteException: Failed to execute Cassandra BULK_WRITE operation
    at org.apache.ignite.cache.store.cassandra.session.CassandraSessionImpl.execute(CassandraSessionImpl.java:266)
    at org.apache.ignite.cache.store.cassandra.CassandraCacheStore.writeAll(CassandraCacheStore.java:333)
    at org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore.updateStore(GridCacheWriteBehindStore.java:804)
    at org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore.applyBatch(GridCacheWriteBehindStore.java:720)
    at org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore.access$2400(GridCacheWriteBehindStore.java:75)
    at org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore$Flusher.flushCacheCoalescing(GridCacheWriteBehindStore.java:1135)
    at org.apache.ignite.internal.processors.cache.store.GridCacheWriteBehindStore$Flusher.body(GridCacheWriteBehindStore.java:1006)
    at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
    at java.lang.Thread.run(Thread.java:748)
Caused by: class org.apache.ignite.IgniteException: Failed to get value of the field 'numberOne' from the instance  of 'class org.apache.ignite.internal.binary.BinaryObjectImpl' class
    at org.apache.ignite.cache.store.cassandra.persistence.PojoField.getValueFromObject(PojoField.java:165)
    at org.apache.ignite.cache.store.cassandra.persistence.PersistenceController.bindValues(PersistenceController.java:450)
    at org.apache.ignite.cache.store.cassandra.persistence.PersistenceController.bindKeyValue(PersistenceController.java:203)
    at org.apache.ignite.cache.store.cassandra.CassandraCacheStore$4.bindStatement(CassandraCacheStore.java:347)
    at org.apache.ignite.cache.store.cassandra.CassandraCacheStore$4.bindStatement(CassandraCacheStore.java:333)
    at org.apache.ignite.cache.store.cassandra.session.CassandraSessionImpl.execute(CassandraSessionImpl.java:230)
    ... 8 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ignite.cache.store.cassandra.persistence.PojoField.getValueFromObject(PojoField.java:147)
    ... 13 more

Thank you for all the help provided so far.

1

1 Answers

0
votes

This happens because you set this:

configuration.setStoreKeepBinary(true);

Set it to false (which is default), deploy POJO classes on server nodes and it will work. Current implementation can't work with binary objects directly, this will be improved in the scope of this ticket: https://issues.apache.org/jira/browse/IGNITE-5270