You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Guilherme Melo <gu...@gmelo.org> on 2017/04/14 16:50:42 UTC

LocalDateTime field being ignored on Cassandra write through

Hello,
I am running some tests using the Cassandra as persistent storage using
CassandraCacheStoreFactory, however the LocalDateTime field is ignored,
I've tried having the table automatically defined and the field is not
created, I have also manually defined the table, however the value passed
is null. There are no error messages on either side, and when I pull the
object from the cache the value is there, therefore the problem is with the
cache store.
Has anyone dealt with anything similar, I am using the latest version of
ignite and the cassandra client.

Thank you,
Guilherme Melo
www.gmelo.org

Re: LocalDateTime field being ignored on Cassandra write through

Posted by Guilherme Melo <gu...@gmail.com>.
Thank you Dimitry, I will take a look

Cheers,

Guilherme Melo
www.gmelo.org

On 18 April 2017 at 22:08, dkarachentsev <dk...@gridgain.com> wrote:

> Guilherme,
>
> You may track feature development here [1] or contribute it by yourself.
>
> [1] https://issues.apache.org/jira/browse/IGNITE-5013
>
> -Dmitry.
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/LocalDateTime-field-being-ignored-on-Cassandra-write-
> through-tp11986p12032.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: LocalDateTime field being ignored on Cassandra write through

Posted by dkarachentsev <dk...@gridgain.com>.
Guilherme,

You may track feature development here [1] or contribute it by yourself.

[1] https://issues.apache.org/jira/browse/IGNITE-5013

-Dmitry.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/LocalDateTime-field-being-ignored-on-Cassandra-write-through-tp11986p12032.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: LocalDateTime field being ignored on Cassandra write through

Posted by dkarachentsev <dk...@gridgain.com>.
Hi Guilherme,

Now Ignite Cassandra store has hard mappings from java to Cassandra types:
org.apache.ignite.cache.store.cassandra.common.PropertyMappingHelper#JAVA_TO_CASSANDRA_MAPPING

If type is not in this map - it will be serialized. LocalDateTime is not
there for compatibility reasons, and no way to bypass it for now. I will
open a ticket for this feature.

Thanks!
-Dmitry.





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/LocalDateTime-field-being-ignored-on-Cassandra-write-through-tp11986p12031.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: LocalDateTime field being ignored on Cassandra write through

Posted by Guilherme Melo <gu...@gmail.com>.
Hello Dimitry,
Thanks, it looks like if I add all the fields on the persist.xml (even
though in the documentation it says that it is not required, for Pojo)the
date is stored as a blob.
I've added annotations to the class to use a custom codec, however it is
ignored.
Is this a bug or are Cassandra annotations not expected to be picked up by
the cache store?
Thanks again.
Guilherme


On 18 Apr 2017 3:32 p.m., "dkarachentsev" <dk...@gridgain.com>
wrote:

> Hi,
>
> I tried your configuration and it works fine for me. Please check attached
> project. I used Cassandra v3.0.13.
>
> cassandra-test.zip
> <http://apache-ignite-users.70518.x6.nabble.com/file/
> n12015/cassandra-test.zip>
>
> -Dmitry.
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/LocalDateTime-field-being-ignored-on-Cassandra-write-
> through-tp11986p12015.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: LocalDateTime field being ignored on Cassandra write through

Posted by dkarachentsev <dk...@gridgain.com>.
Hi,

I tried your configuration and it works fine for me. Please check attached
project. I used Cassandra v3.0.13.

cassandra-test.zip
<http://apache-ignite-users.70518.x6.nabble.com/file/n12015/cassandra-test.zip>  

-Dmitry.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/LocalDateTime-field-being-ignored-on-Cassandra-write-through-tp11986p12015.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: LocalDateTime field being ignored on Cassandra write through

Posted by Guilherme Melo <gu...@gmail.com>.
Hello,
The Spring config:

 @Bean
    public IgniteConfiguration getIgniteConfiguration() {
        IgniteConfiguration cfg = new IgniteConfiguration();
        //cfg.setClientMode(true);
        cfg.setClientMode(false);

        //orders
        CacheConfiguration orderCache = new CacheConfiguration();
        orderCache.setName("thirdCache");
        orderCache.setBackups(1);
        orderCache.setCacheMode(CacheMode.PARTITIONED);
        orderCache.setCacheStoreFactory(getCassandraCacheStoreFactory());
        orderCache.setReadThrough(true);
        orderCache.setWriteThrough(true);

        cfg.setCacheConfiguration(
                orderCache);
        return cfg;
    }

    @Bean
    public CassandraCacheStoreFactory getCassandraCacheStoreFactory() {
        CassandraCacheStoreFactory cassandraCacheStoreFactory = new
CassandraCacheStoreFactory();
        cassandraCacheStoreFactory.setDataSource(getCassandraDataSource());
        cassandraCacheStoreFactory.setPersistenceSettings(getPersistenceSettings());
        return cassandraCacheStoreFactory;
    }

    @Bean
    public DataSource getCassandraDataSource() {
    DataSource dataSource = new DataSource();
        dataSource.setContactPoints("127.0.0.1");

        return dataSource;
    }

    @Bean
    public KeyValuePersistenceSettings getPersistenceSettings() {
        Resource resource = new ClassPathResource("persistence-settings.xml");

        KeyValuePersistenceSettings keyValuePersistenceSettings = new
KeyValuePersistenceSettings(resource);
        return keyValuePersistenceSettings;
    }

The Persistence.xml

<persistence keyspace="my_keyspace" table="my_table" ttl="86400">
    <!--
    Specifies Cassandra keyspace options which should be used to
create provided keyspace if it doesn't exist.

    Note: optional element
    -->
    <keyspaceOptions>
        REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 3}
        AND DURABLE_WRITES = true
    </keyspaceOptions>

    <!--
    Specifies Cassandra table options which should be used to create
provided table if it doesn't exist.

    Note: optional element
    -->
    <tableOptions>
        comment = 'A most excellent and useful table'
        AND read_repair_chance = 0.2
    </tableOptions>

    <!--
    Specifies persistent settings for Ignite cache keys.

    Note: required element

    Attributes:
      1) class      [required] - java class name for Ignite cache key
      2) strategy   [required] - one of three possible persistent strategies:
            a) PRIMITIVE - stores key value as is, by mapping it to
Cassandra table column with corresponding type.
                Should be used only for simple java types (int, long,
String, double, Date) which could be mapped
                to corresponding Cassadra types.
            b) BLOB - stores key value as BLOB, by mapping it to
Cassandra table column with blob type.
                Could be used for any java object. Conversion of java
object to BLOB is handled by "serializer"
                which could be specified in serializer attribute (see below).
            c) POJO - stores each field of an object as a column
having corresponding type in Cassandra table.
                Provides ability to utilize Cassandra secondary
indexes for object fields.
      3) serializer [optional] - specifies serializer class for BLOB
strategy. Shouldn't be used for PRIMITIVE and
        POJO strategies. Available implementations:
            a) org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer
- uses standard Java
                serialization framework
            b) org.apache.ignite.cache.store.cassandra.serializer.KryoSerializer
- uses Kryo
                serialization framework
      4) column     [optional] - specifies column name for PRIMITIVE
and BLOB strategies where to store key value.
        If not specified column having 'key' name will be used.
Shouldn't be used for POJO strategy.
    -->
    <keyPersistence class="java.lang.String" strategy="PRIMITIVE">
        <!--serializer="..." column="..." -->
        <!--
        Specifies partition key fields if POJO strategy used.

        Note: optional element, only required for POJO strategy in
case you want to manually specify
            POJO fields to Cassandra columns mapping, instead of
relying on dynamic discovering of
            POJO fields and mapping them to the same columns of Cassandra table.
        -->
        <partitionKey>
            <!--
             Specifies mapping from POJO field to Cassandra table column.

             Note: required element

             Attributes:
               1) name   [required] - POJO field name
               2) column [optional] - Cassandra table column name. If
not specified lowercase
                  POJO field name will be used.
            -->
            <!--<field name="companyCode" column="company"/>-->
        </partitionKey>

        <!--
        Specifies cluster key fields if POJO strategy used.

        Note: optional element, only required for POJO strategy in
case you want to manually specify
            POJO fields to Cassandra columns mapping, instead of
relying on dynamic discovering of
            POJO fields and mapping them to the same columns of Cassandra table.
        -->
        <clusterKey>
            <!--
             Specifies mapping from POJO field to Cassandra table column.

             Note: required element

             Attributes:
               1) name   [required] - POJO field name
               2) column [optional] - Cassandra table column name. If
not specified lowercase
                  POJO field name will be used.
               3) sort   [optional] - specifies sort order (asc or desc)
            -->
            <field name="id"/>
            <!--column="number" sort="desc"/>-->
            <!--...-->
            <!--...-->
        </clusterKey>
    </keyPersistence>

    <!--
    Specifies persistent settings for Ignite cache values.

    Note: required element

    Attributes:
      1) class      [required] - java class name for Ignite cache value
      2) strategy   [required] - one of three possible persistent strategies:
            a) PRIMITIVE - stores key value as is, by mapping it to
Cassandra table column with corresponding type.
                Should be used only for simple java types (int, long,
String, double, Date) which could be mapped
                to corresponding Cassadra types.
            b) BLOB - stores key value as BLOB, by mapping it to
Cassandra table column with blob type.
                Could be used for any java object. Conversion of java
object to BLOB is handled by "serializer"
                which could be specified in serializer attribute (see below).
            c) POJO - stores each field of an object as a column
having corresponding type in Cassandra table.
                Provides ability to utilize Cassandra secondary
indexes for object fields.
      3) serializer [optional] - specifies serializer class for BLOB
strategy. Shouldn't be used for PRIMITIVE and
        POJO strategies. Available implementations:
            a) org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer
- uses standard Java
                serialization framework
            b) org.apache.ignite.cache.store.cassandra.serializer.KryoSerializer
- uses Kryo
                serialization framework
      4) column     [optional] - specifies column name for PRIMITIVE
and BLOB strategies where to store value.
        If not specified column having 'value' name will be used.
Shouldn't be used for POJO strategy.
    -->
    <valuePersistence
class="org.gmelo.investigation.ignite.model.SampleModel"
strategy="POJO">
                      <!--serializer="..." column="">-->
        <!--
         Specifies mapping from POJO field to Cassandra table column.

         Note: required element

         Attributes:
           1) name         [required] - POJO field name
           2) column       [optional] - Cassandra table column name.
If not specified lowercase
              POJO field name will be used.
           3) static       [optional] - boolean flag which specifies
that column is static withing a given partition
           4) index        [optional] - boolean flag specifying that
secondary index should be created for the field
           5) indexClass   [optional] - custom index java class name
if you want to use custom index
           6) indexOptions [optional] - custom index options
        -->
        <!--<field name="firstName" column="first_name" static="..."
index="..." indexClass="..." indexOptions="..."/>-->
        <!--<field name="timestampVal" column="timestampVal" />-->
    </valuePersistence>
</persistence>

I've also tried:

@Field(codec = LocalDateTimeCodec.class)
private LocalDateTime timestampVal;

But to no avail.

Thanks Dmitry


Guilherme Melo
www.gmelo.org

Re: LocalDateTime field being ignored on Cassandra write through

Posted by dkarachentsev <dk...@gridgain.com>.
Hi, please share your configurations.

-Dmitry.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/LocalDateTime-field-being-ignored-on-Cassandra-write-through-tp11986p12000.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.