You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Anil <an...@gmail.com> on 2017/05/02 05:49:23 UTC

BinaryObject

Hi,

java.lang.ClassCastException:
org.apache.ignite.internal.binary.BinaryObjectImpl cannot be cast to
org.apache.ignite.cache.affinity.Affinity  exception thrown when a field
updated using BinaryObject for a cache entry. and it is intermittent.

Following is the snippet i am using

IgniteCache<Affinity<String>, BinaryObject> cache =
ignite.cache(CacheManager.CACHE).withKeepBinary();
IgniteCache<Affinity<String>, BinaryObject> lCache =
ignite.cache(CacheManager.LOCK_CACHE).withKeepBinary();
ScanQuery<Affinity<String>, BinaryObject> scanQuery = new
ScanQuery<Affinity<String>, BinaryObject>();
scanQuery.setLocal(true);
scanQuery.setPartition(1);

Iterator<Entry<Affinity<String>, BinaryObject>> iterator =
cache.query(scanQuery).iterator();
Integer oldStat = null, newStat = null;
boolean changed = false;
Entry<Affinity<String>, BinaryObject> row = null;
while (iterator.hasNext()) {
try {
row = iterator.next();
BinaryObject itrVal = row.getValue();
String id = itrVal.<String>field("id");
Lock lock = lCache.lock(id);
try {
lock.lock();
BinaryObject val = cache.get(row.getKey());
if (null != val){
BinaryObjectBuilder bldr = val.toBuilder();
oldStat = val.<Integer>field("stat");
Status status = null ; // determine status
if (!CommonUtils.equalsObject(oldStat, newStat)){
changed = true;
bldr.setField("stat", status.getStatus());
bldr.setField("status", status.getDescription());
}

                                                        // update other
fields
if(changed){
cache.put(row.getKey(), bldr.build());
}
}
}catch (Exception ex){
log.error("Failed to update the status of  {}  {} ", id, ex);
}finally {
lock.unlock();
}
}catch (Exception ex){
log.error("Failed to process and update status of  {}  {} ", row, ex);
}
}


Do you see any issue in the above snippet ? thanks.


Thanks

Re: BinaryObject

Posted by Anton Vinogradov <av...@gridgain.com>.
Anil,

This seems to be fixed at https://issues.apache.org/jira/browse/IGNITE-4891,
please check.


On Wed, May 3, 2017 at 12:08 PM, Anil <an...@gmail.com> wrote:

> HI Team,
>
> Did you get a chance to look into it ? thanks.
>
> Thanks
>
> On 2 May 2017 at 11:19, Anil <an...@gmail.com> wrote:
>
>> Hi,
>>
>> java.lang.ClassCastException: org.apache.ignite.internal.binary.BinaryObjectImpl
>> cannot be cast to org.apache.ignite.cache.affinity.Affinity  exception
>> thrown when a field updated using BinaryObject for a cache entry. and it is
>> intermittent.
>>
>> Following is the snippet i am using
>>
>> IgniteCache<Affinity<String>, BinaryObject> cache =
>> ignite.cache(CacheManager.CACHE).withKeepBinary();
>> IgniteCache<Affinity<String>, BinaryObject> lCache =
>> ignite.cache(CacheManager.LOCK_CACHE).withKeepBinary();
>> ScanQuery<Affinity<String>, BinaryObject> scanQuery = new
>> ScanQuery<Affinity<String>, BinaryObject>();
>> scanQuery.setLocal(true);
>> scanQuery.setPartition(1);
>>
>> Iterator<Entry<Affinity<String>, BinaryObject>> iterator =
>> cache.query(scanQuery).iterator();
>> Integer oldStat = null, newStat = null;
>> boolean changed = false;
>> Entry<Affinity<String>, BinaryObject> row = null;
>> while (iterator.hasNext()) {
>> try {
>> row = iterator.next();
>> BinaryObject itrVal = row.getValue();
>> String id = itrVal.<String>field("id");
>> Lock lock = lCache.lock(id);
>> try {
>> lock.lock();
>> BinaryObject val = cache.get(row.getKey());
>> if (null != val){
>> BinaryObjectBuilder bldr = val.toBuilder();
>> oldStat = val.<Integer>field("stat");
>> Status status = null ; // determine status
>> if (!CommonUtils.equalsObject(oldStat, newStat)){
>> changed = true;
>> bldr.setField("stat", status.getStatus());
>> bldr.setField("status", status.getDescription());
>> }
>>
>>                                                         // update other
>> fields
>> if(changed){
>> cache.put(row.getKey(), bldr.build());
>> }
>> }
>> }catch (Exception ex){
>> log.error("Failed to update the status of  {}  {} ", id, ex);
>> }finally {
>> lock.unlock();
>> }
>> }catch (Exception ex){
>> log.error("Failed to process and update status of  {}  {} ", row, ex);
>> }
>> }
>>
>>
>> Do you see any issue in the above snippet ? thanks.
>>
>>
>> Thanks
>>
>>
>

Re: BinaryObject

Posted by Anil <an...@gmail.com>.
HI Team,

Did you get a chance to look into it ? thanks.

Thanks

On 2 May 2017 at 11:19, Anil <an...@gmail.com> wrote:

> Hi,
>
> java.lang.ClassCastException: org.apache.ignite.internal.binary.BinaryObjectImpl
> cannot be cast to org.apache.ignite.cache.affinity.Affinity  exception
> thrown when a field updated using BinaryObject for a cache entry. and it is
> intermittent.
>
> Following is the snippet i am using
>
> IgniteCache<Affinity<String>, BinaryObject> cache =
> ignite.cache(CacheManager.CACHE).withKeepBinary();
> IgniteCache<Affinity<String>, BinaryObject> lCache =
> ignite.cache(CacheManager.LOCK_CACHE).withKeepBinary();
> ScanQuery<Affinity<String>, BinaryObject> scanQuery = new
> ScanQuery<Affinity<String>, BinaryObject>();
> scanQuery.setLocal(true);
> scanQuery.setPartition(1);
>
> Iterator<Entry<Affinity<String>, BinaryObject>> iterator =
> cache.query(scanQuery).iterator();
> Integer oldStat = null, newStat = null;
> boolean changed = false;
> Entry<Affinity<String>, BinaryObject> row = null;
> while (iterator.hasNext()) {
> try {
> row = iterator.next();
> BinaryObject itrVal = row.getValue();
> String id = itrVal.<String>field("id");
> Lock lock = lCache.lock(id);
> try {
> lock.lock();
> BinaryObject val = cache.get(row.getKey());
> if (null != val){
> BinaryObjectBuilder bldr = val.toBuilder();
> oldStat = val.<Integer>field("stat");
> Status status = null ; // determine status
> if (!CommonUtils.equalsObject(oldStat, newStat)){
> changed = true;
> bldr.setField("stat", status.getStatus());
> bldr.setField("status", status.getDescription());
> }
>
>                                                         // update other
> fields
> if(changed){
> cache.put(row.getKey(), bldr.build());
> }
> }
> }catch (Exception ex){
> log.error("Failed to update the status of  {}  {} ", id, ex);
> }finally {
> lock.unlock();
> }
> }catch (Exception ex){
> log.error("Failed to process and update status of  {}  {} ", row, ex);
> }
> }
>
>
> Do you see any issue in the above snippet ? thanks.
>
>
> Thanks
>
>