0

We are using Gemfire PCC for one of our generic caching solution. Where clients would use gemfire as a caching service. In order to achieve we have common data model defined with name, value fields. So for n number of regions it's going to be same class.

The issue is, when a first put or putAll happens PDXType for this class type has been registered with the fields inserted. From there onwards every cache it's using the same PDXType because of same class type.

Let's say I inserted below record Region1 - foo.GenericClass

  • name=FirstName, value=Abc
  • name=LastName, value=Def

After this point PDXType will be registered with

info 2018/07/06 12:22:24.213 EDT <http-nio-8080-exec-4> tid=0x45] Caching PdxType[dsid=0, typenum=14294267
    name=foo.GenericClass
    fields=[
    _cacheName:String:0:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=-1
    FirstName:String:identity:1:1:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=1        
LastName:String:identity:2:1:idx0(relativeOffset)=-2:idx1(vlfOffsetIndex)=-1]]

From here onwards for all the operations on foo.GenericClass using same PDXType.

When i try to insert below record instead of AddressLine1 it is store as FirstName as field name in Region2.
Region2 - foo.GenericClass

  • name=AddressLine1, value=123 Main St
  • name=City, value=Atlata

Is there anyway to insert data into different regions by using same domain object and register their own PDXTypes during serialization? Am i missing some simple thing here?

rajanikanth
  • 123
  • 1
  • 2
  • 8

2 Answers2

2

Rajanikanth Would you share the source code for your classes and how they're instantiated to have these values? A simple Java class with "name" and "value" fields shouldn't be serialized like this. Also, are you using the ReflectionBasedAutoSerializer, the Spring serializer or something else?

2

Hi there @rajanikanth,

As Bruce has indicated, the PDX definition provided is not that of the expected,

Caching PdxType[dsid=0, typenum=14294267, name=foo.GenericClass
,fields=[
  _cacheName:String:0:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=-1
  name:String:identity:1:1:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=1        
  value:String:identity:2:1:idx0(relativeOffset)=-2:idx1(vlfOffsetIndex)=-1]]

Whilst I can understand the benefit of wanting to create a GenericClass in order to avoid having an explicitly defined a domain model and having to care how to handle change, I can only think that this approach to modeling data would not be scalable.

Whilst PCC is a key-value store, I can only imagine that your region definition would have to be something like Region<Key,GenericClass>. Which does not really allow for optimal usage of a caching technology, if the lookups are this granular. Or was your intended usage of this to be more like:

UserObject:
  _cacheName: String
  data: Set<GenericClass>

Looking at the provided input data, I would imagine a potentially better approach would be to maybe have a GenericClass modelled in the following manner:

GenericClass:
  _cacheName: String
  className: String
  genericData: Map<String,Object>

This way you could represent a User in the following manner (please excuse my rough JSON notation):

GenericClass:
  _cacheName = "UserCache"
  className = "foo.bar.User"
  genericData = {("firstName":"Bob"),("lastName":"Sponge"),("AddressLine1":"100 Under the Sea Lane"),("age":21)}

Now using this approach is "acceptable" if you do not care to search for any specific user properties. BUT this approach will be HUGELY inefficient if you would like to use some amount of Querying capability to find all users with lastName of "Sponge" or user under the age of 30. Also, looking at the described GenericClass, you may just as well use:

GenericClass:
  _cacheName: String
  jsonDocument: String
Udo
  • 63
  • 6
  • Thanks a lot for the response. I realized it's not efficient way as you mentioned when dig through more detailed in to the problem. Modified the code by wrapping each definition i have into it's specific domain model. It works fine now. – rajanikanth Jul 13 '18 at 19:32