5 Replies Latest reply on Dec 13, 2016 3:47 AM by rvansa

    Questions about Infinispan distribution mode

    seto

      How is object stored in the cache and sync with other nodes?

      I make put an object in the cache of master node.

      And then I start a slave node.

      Then I make changes to the object without put the object again.

      The slave node will get the old object.

      The master node cache.get will get the new object.

       

      If I understand distribution mode correctly, the slave will ask the master node for the object when the num of owners is 1.

      So I think the master node still keep the old object.

       

      How can I get the old object in the master node?

      But the cache.get in master node returns me the new one.

       

      I want to implement a transaction like mechanism for object itself.

      I want to revert the object back when some fail occurs.

        • 1. Re: Questions about Infinispan distribution mode
          rvansa

          In distribution/replication mode, Infinispan always stores a copy of the object you've passed in, to prevent concurrency issues. So if you insert an entry and then modify the value, these changes won't be reflected - you have to insert it again.

           

          Note that local caches store just a reference to the object, for efficiency reasons.

          • 2. Re: Questions about Infinispan distribution mode
            seto

            Yes. I know it. I want to get the unmodified copy in the node where I change it before I put it again. How can I get it? I call cache.get(), but it returns me the modifed copy.

            For example I begin a work. And I  meet some failure.Then I rollback the transaction. The put will be reverted. But the object is modified. I want to revert it as well. So I need a way to get the unmodified copy.

            • 3. Re: Questions about Infinispan distribution mode
              rvansa

              Uh, I've tried a test to verify and I was partially wrong; it actually can store the original object if this node is a primary owner. So, the answer is: don't modify the original object, ideally you should make it immutable, because you can't really know if the object is about to be stored on local or remote node (so you can't know if the modification will have any effect). If you can't guarantee that, you should create a defensive copy yourselves. Or, as an alternative, you can configure store-as-binary  which will always serialize the object when storing that (and keep the serialized form).

              • 4. Re: Questions about Infinispan distribution mode
                seto

                A deep copy myself, or store-as-binary? Which one do you recommend?

                It seems that a fast deep copy implementation uses serialization. It seems that it's the same as story-as binary.

                • 5. Re: Questions about Infinispan distribution mode
                  rvansa

                  With store-as-binary, the object will be held as binary blob and whenever you'll read it locally, this blob will have to be deserialized. On the other hand, when the object is held as instance, it has to be serialized when it is read from remote node.

                   

                  Just setting store-as-binary is probably simpler, it does not require any code changes. Besides that, the choice is only a matter of performance in your use case.