Reputation: 141
I am developing an application for data communication in that i want to communicate to cassandra through ignite c++. when i try to put data to cassandra its works fine. but i can't get the data from the same. here is my code.
test.h
namespace ignite
{
namespace examples
{
struct Test
{
Test()
{
// No-op.
}
Test(const std::string& assetid, const std::string& asset_desc, const std::string& groupid) :
assetid (assetid), asset_desc (asset_desc), groupid (groupid)
{
// No-op.
}
std::string ToString()
{
std::ostringstream oss;
oss << "Address [street=" << assetid << ", zip=" << asset_desc<< "]";
return oss.str();
}
std::string assetid;
std::string asset_desc;
std::string groupid;
};
}
}
cassandra-config.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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Cassandra connection settings -->
<import resource="file:connection-settings.xml" />
<!-- Persistence settings for 'cache1' -->
<bean id="cache1_persistence_settings" class="org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings">
<constructor-arg type="org.springframework.core.io.Resource" value="file:persistence-settings-1.xml" />
</bean>
<!-- Persistence settings for 'cache2'
<bean id="cache2_persistence_settings" class="org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings">
<constructor-arg type="org.springframework.core.io.Resource" value="classpath:org/apache/ignite/tests/persistence/blob/persistence-settings-3.xml" />
</bean>-->
<!-- Ignite configuration -->
<bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<list>
<!-- Configuring persistence for "cache1" cache -->
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="cache1"/>
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="Test"/>
<property name="valueType" value="Test"/>
<property name="fields">
<map>
<!--entry key="assetid" value="assetid"/-->
<entry key="asset_desc" value="asset_desc"/>
<entry key="groupid" value="groupid"/>
</map>
</property>
</bean>
</list>
</property>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="storeKeepBinary" value="true"/>
<property name="cacheStoreFactory">
<bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory">
<property name="dataSourceBean" value="cassandraAdminDataSource"/>
<property name="persistenceSettingsBean" value="cache1_persistence_settings"/>
</bean>
</property>
</bean>
<!-- Configuring persistence for "cache2" cache
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="cache2"/>
<property name="readThrough" value="true"/>
<property name="writeThrough" value="true"/>
<property name="cacheStoreFactory">
<bean class="org.apache.ignite.cache.store.cassandra.CassandraCacheStoreFactory">
<property name="dataSourceBean" value="cassandraAdminDataSource"/>
<property name="persistenceSettingsBean" value="cache2_persistence_settings"/>
</bean>
</property>
</bean>
-->
</list>
</property>
<!-- 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>
</bean>
</beans>
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>127.0.0.1</value>
</util:list>
<bean id="cassandraAdminDataSource" class="org.apache.ignite.cache.store.cassandra.datasource.DataSource">
<property name="contactPoints" ref="contactPoints"/>
<!-- <property name="user" value="user"/>
<property name="password" value="p@ssw0rd"/> -->
<property name="readConsistency" value="ONE"/>
<property name="writeConsistency" value="ONE"/>
<property name="loadBalancingPolicy" ref="loadBalancingPolicy"/>
</bean>
</beans>
persistance-settings.xml
<persistence keyspace="sam" table="user_permission">
<keyPersistence class="com.test.Test" strategy="POJO">
<partitionKey>
<!-- Mapping from POJO field to Cassandra table column -->
<field name="assetid" column="assetid" />
</partitionKey>
</keyPersistence>
<valuePersistence class="com.test.Test" strategy="POJO">
<!-- Mapping from POJO field to Cassandra table column -->
<!-- field name="companyid" column="companyid" />
<field name="company_name" column="company_name" /-->>
<field name="assetid" column="assetid"/>
<field name="asset_desc" column="asset_desc"/>
<field name="groupid" column="groupid"/>
</valuePersistence>
</persistence>
main
int main()
{
IgniteConfiguration cfg;
cfg.springCfgPath = "apache-ignite-fabric-2.0.0-bin/cassandra-config.xml";
Ignite grid = Ignition::Start(cfg);
Cache<Test, Test> cache = grid.GetCache<Test, Test>("cache1");
Test test;
test.assetid = "456dsfds";
Test obj;
obj.asset_desc = "wdsdfsf";
obj.groupid = "sddvwfsf";
cache.Put (test, obj,err);
Test get = cache.Get (test, err);
cout << "Error Found" << err.GetText () << endl;
cout << "Ignite \t" << "\t" << get.asset_desc << "\t" << get.groupid;
}
Test.jar
package com.test;
import java.io.Serializable;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryReader;
import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.binary.Binarylizable;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
public class Test implements Binarylizable ,Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
String assetid;
@QuerySqlField(index = true)
String asset_desc;
String groupid;
public String getGroupId() {
return groupid;
}
public void setGroupId(String groupId) {
this.groupid = groupId;
}
public String getAssetid() {
return assetid;
}
public void setAssetid(String assetid) {
this.assetid = assetid;
}
public String getAsset_desc() {
return asset_desc;
}
public void setAsset_desc(String asset_desc) {
this.asset_desc = asset_desc;
}
@Override
public void readBinary(BinaryReader reader) throws BinaryObjectException {
assetid = reader.readString("assetid");
asset_desc = reader.readString("asset_desc");
groupid = reader.readString("groupid");
}
@Override
public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeString("assetid", assetid);
writer.writeString("asset_desc", asset_desc);
writer.writeString("groupid", groupid);
}
}
it shows the error like this
Topology snapshot [ver=1, servers=1, clients=0, CPUs=1, heap=0.97GB] [16:14:20,834][ERROR][sys-#29%null%][CassandraCacheStore] Failed to execute Cassandra CQL statement: select "assetid", "asset_desc", "groupid" from "sam"."user_permission" where "assetid"=? and "asset_desc"=? and "groupid"=?; class org.apache.ignite.IgniteException: Failed to execute Cassandra CQL statement: select "assetid", "asset_desc", "groupid" from "sam"."user_permission" where "assetid"=? and "asset_desc"=? and "groupid"=?;
Upvotes: 2
Views: 243
Reputation: 1
As far as you are using C++ to work with Ignite, you are also utilizing BinaryObjects. Current implementation of Cassandra store doesn't support BinaryObjects as cache keys and values.
Because of this, from Ignite C++ client you can't use Cassandra table with 1 partiton key ,3 clustering keys. You can only do it from java client configuring POJO persistence strategy and avoiding BinaryObjects.
There is also a ticket in Ignite JIRA to implement BinaryObjects support in Cassandra store: https://issues.apache.org/jira/browse/IGNITE-5270
Upvotes: 0
Reputation: 463
I assume that's because you are using this:
<property name="storeKeepBinary" value="true"/>
Current implementation supports only BLOB serialization for binary objects. There is a ticket for this: https://issues.apache.org/jira/browse/IGNITE-5270
Upvotes: 2