ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kotamrajuyashasvi <kotamrajuyasha...@gmail.com>
Subject Re: Affinity Key field is not identified if binary configuration is used on cache key object
Date Sun, 06 Aug 2017 10:14:20 GMT
Hi

"I already did LoadCache before running the client program ".. I meant that
LoadCache was successful but not Cache.Get(). LoadCache works similar to
Get() right but does bulk operations? Even if I don't loadcache and try to
call Get()[the key called by Get is initially not loaded/present in cache] I
get the same error.

Here is my code.

--------------------------------- ignite 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">


        <import resource="file:connection-settings.xml" />
        
    <bean id="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>

    <bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
        
         <property name="clientMode" value="true"/>  
  
                 <property name="binaryConfiguration">
            <bean
class="org.apache.ignite.configuration.BinaryConfiguration">
                <property name="compactFooter" value="false"/>

                <property name="idMapper">
                    <bean
class="org.apache.ignite.binary.BinaryBasicIdMapper">
                        <property name="lowerCase" value="true"/>
                    </bean>
                </property>

                <property name="nameMapper">
                    <bean
class="org.apache.ignite.binary.BinaryBasicNameMapper">
                        <property name="simpleName" value="true"/>
                    </bean>
                </property>

                <property name="classNames">
                    <list>
                        <value>com.ignitetest.PersonPK</value>
                    </list>
                </property>
            </bean>
        </property>
 
         <property name="cacheKeyConfiguration">
                <list>
                   <bean
class="org.apache.ignite.cache.CacheKeyConfiguration">
                        <property name="typeName"
value="com.ignitetest.PersonPK"/>
                        <property name="AffinityKeyFieldName" value="col5"/>
                    </bean>
              </list>
          </property>


                <property name="cacheConfiguration">
            <list>                
                <bean
class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="indexedTypes">
                        <list>
                            <value>com.ignitetest.PersonPK</value>
                            <value>com.ignitetest.Person</value>
                        </list>
                    </property>
                    <property name="name" value="cache1"/>
                    <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="persistence_settings"/>
                        </bean>
                    </property>
                </bean>
           </list>
        </property>
  <property name="peerClassLoadingEnabled" value="true"></property>
        <property name="discoverySpi">
            <bean
class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">                    
                    <bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                        <property name="addresses">
                            <list>
                                <value>127.0.0.1</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>


<persistence keyspace="testkeyspace" table="person">
        <keyPersistence class="com.ignitetest.PersonPK" strategy="POJO" />
    <valuePersistence class="com.ignitetest.Person" strategy="POJO" />
</persistence>

---------------------------------Person Pojo 
--------------------------------------------------------- 
package com.ignitetest; 

public class Person { 
        int col1; 
        int col2; 
        int col3; 
        String col4; 
        String col5; 
        public int getCol1() { 
                return col1; 
        } 
        public void setCol1(int col1) { 
                this.col1 = col1; 
        } 
        public int getCol2() { 
                return col2; 
        } 
        public void setCol2(int col2) { 
                this.col2 = col2; 
        } 
        public int getCol3() { 
                return col3; 
        } 
        public void setCol3(int col3) { 
                this.col3 = col3; 
        } 
        public String getCol4() { 
                return col4; 
        } 
        public void setCol4(String col4) { 
                this.col4 = col4; 
        } 

        public String getCol5() { 
                return col5; 
        } 
        public void setCol5(String col5) { 
                this.col5 = col5; 
        } 
} 


---------------------------------PersonPK Pojo 
--------------------------------------------------------- 
package com.ignitetest; 

import org.apache.ignite.binary.BinaryObjectException; 
import org.apache.ignite.binary.BinaryReader; 
import org.apache.ignite.binary.BinaryWriter; 
import org.apache.ignite.binary.Binarylizable; 

public class PersonPK implements Binarylizable{ 
        int col1; 
        String col5; 
        public int getCol1() { 
                return col1; 
        } 
        public void setCol1(int col1) { 
                this.col1 = col1; 
        } 
        public String getCol5() { 
                return col5; 
        } 
        public void setCol5(String col5) { 
                this.col5 = col5; 
        } 
        @Override 
        public int hashCode() { 
                final int prime = 31; 
                int result = 1; 
                result = prime * result + col1; 
                result = prime * result + ((col5 == null) ? 0 :
col5.hashCode()); 
                return result; 
        } 
        @Override 
        public boolean equals(Object obj) { 
                if (this == obj) 
                        return true; 
                if (obj == null) 
                        return false; 
                if (getClass() != obj.getClass()) 
                        return false; 
                PersonPK other = (PersonPK) obj; 
                if (col1 != other.col1) 
                        return false; 
                if (col5 == null) { 
                        if (other.col5 != null) 
                                return false; 
                } else if (!col5.equals(other.col5)) 
                        return false; 
                return true; 
        } 
        @Override 
        public void readBinary(BinaryReader reader) throws
BinaryObjectException { 
                this.col1  = reader.readInt("col1"); 
                this.col5 = reader.readString("col5"); 
                
        } 
        @Override 
        public void writeBinary(BinaryWriter writer) throws
BinaryObjectException { 
                writer.writeInt("col1", col1); 
                writer.writeString("col5", col5);	
        } 
        
        
} 

-----------------------------------------C++ pojo map header
--------------------------------------------- 

#include <string>
#include <sstream>

#include "ignite/ignite.h" 
#include "ignite/ignition.h" 

namespace ignite 
{ 
        struct Person 
        { 
            
            Person(int32_t _col1,int64_t _col2,int64_t _col3, const
std::string& _col4, const std::string& _col5): 
                  col1(_col1), 
                  col2(_col2), 
                  col3(_col3), 
                  col4(_col4), 
                  col5(_col5) 
            { 
                // No-op. 
            } 
                        
            int32_t col1; 
            int32_t col2; 
            int32_t col3; 
            std::string col4; 
            std::string col5; 
        }; 

                 struct PersonPK 
          { 
                          PersonPK(){ 

                          }	
  
              PersonPK(const ignite::PersonPK& copyfromPersonPK) 
              { 
                  col1         = copyfromPersonPK.col1; 
                  col5         = copyfromPersonPK.col5; 
              } 
  
              PersonPK(int32_t _col1, const std::string& _col5): 
                    col1(_col1), 
                    col5(_col5) 
              { 
  
              } 
  
              int32_t col1; 
              std::string col5; 
          }; 

} 

namespace ignite 
{ 
    namespace binary 
    { 
        IGNITE_BINARY_TYPE_START(ignite::Person) 

            typedef ignite::Person Person; 

            IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Person) 
            IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Person) 
            IGNITE_BINARY_GET_FIELD_ID_AS_HASH 
            IGNITE_BINARY_GET_HASH_CODE_ZERO(Person) 
            IGNITE_BINARY_IS_NULL_FALSE(Person) 
            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Person) 

            void Write(BinaryWriter& writer, ignite::Person obj) 
            { 
                writer.WriteInt32("col1", obj.col1); 
                writer.WriteInt32("col2", obj.col2); 
                writer.WriteInt32("col3", obj.col3); 
                writer.WriteString("col4", obj.col4); 
                writer.WriteString("col5", obj.col5); 
            } 

            ignite::Person Read(BinaryReader& reader) 
            { 
                int32_t _col1 = reader.ReadInt32("col1"); 
                int32_t _col2 = reader.ReadInt32("col2"); 
                int32_t _col3 = reader.ReadInt32("col3"); 
                std::string _col4 = reader.ReadString("col4"); 
                std::string _col5 = reader.ReadString("col5"); 

                return ignite::Person(_col1, _col2, _col3, _col4, _col5); 
            } 

        IGNITE_BINARY_TYPE_END 


          template<> 
      struct BinaryType<PersonPK>
      { 
        static int32_t GetTypeId() 
        { 
          return GetBinaryStringHashCode("PersonPK"); 
        } 
  
        std::string GetTypeName() 
        { 
          return "PersonPK"; 
        } 
  
        static int32_t GetFieldId(const char* name) 
        { 
          return GetBinaryStringHashCode(name); 
        } 
  
        static bool IsNull(const PersonPK& obj) 
        { 
          return false; 
        } 
  
        static void GetNull(PersonPK& dst) 
        { 
          dst = PersonPK(); 
        } 
  
        static void Read(BinaryReader& reader, PersonPK& dst) 
        { 
          dst.col1 = reader.ReadInt32("col1"); 
          dst.col5 = reader.ReadString("col5"); 
        } 
  
        static void Write(BinaryWriter& writer, const PersonPK& obj) 
        { 
          writer.WriteInt32("col1", obj.col1); 
          writer.WriteString("col5", obj.col5); 
       }
      
       int32_t GetHashCode(const PersonPK& obj){
               int32_t prime = 31;
               int32_t result = 1;

              int32_t strhash = 0;
              int32_t i,len;
              std::string custstr;

              custstr = obj.col5;
              len = custstr.length();
              for(i=0;i<len;++i){
                strhash = (prime*strhash) + custstr[i];
              }
              result = (prime*result)+strhash;

              result = (prime*result)+ obj.col1;
     
             return result;
         }
 
     }; 

    } 
}; 

------------------------------------------------- ignite c++ client
--------------------------------------- 
#include &lt;stdint.h>
#include <iostream>
#include "ignite/ignite.h" 
#include "ignite/ignition.h" 
#include "pojomap.h" 

using namespace std; 
using namespace ignite; 
using namespace cache; 
using namespace query; 

void callIgnite(); 

int main() 
{ 
        callIgnite(); 
        return 0; 
} 

void callIgnite() 
{ 
        IgniteConfiguration cfg; 
        cfg.springCfgPath = "default-config.xml"; 

        try 
        { 
                Ignite ignite = Ignition::Start(cfg); 

                Person myPerson; 
                PersonPK pk ; 
                
                std::cout << std::endl; 
                std::cout << ">>> Cassandra Cache query example started." <<
std::endl; 
                std::cout << std::endl; 

                Cache<PersonPK, Person> PersonCache =
ignite.GetOrCreateCache<PersonPK, Person>("cache1"); 

                std::cout << "CACHE SIZE before loadCache(): " <<
PersonCache.Size()<<std::endl; 
                PersonCache.LoadCache(); 
                std::cout << "CACHE SIZE after loadCache
:"<<PersonCache.Size()<<std::endl;  

                pk = PersonPK(1,"cust1"); 
                myPerson = PersonCache.Get(pk); //error
                std::cout<<myPerson.col4<<endl; 
               
                Ignition::StopAll(false); 
        } 
        catch (IgniteError& err) 
        { 
                std::cout << "An error occurred: " << err.GetText() <<
std::endl; 
        } 
} 

If I remove cacheKeyConfiguration (where affinity field is added) in config
xml, Get() is successful but affinity is not working.




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Affinity-Key-field-is-not-identified-if-binary-configuration-is-used-on-cache-key-object-tp15959p16018.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message