2 Replies Latest reply on Nov 3, 2009 5:41 AM by sannegrinovero

    async API guarantees

    sannegrinovero

      Hi,
      I've some questions about the async APIs:

      1)

      cache.putAsync(k1, v1);
      assert cache.get(k1) == v1;

      Immediately after a put operation - even if the remote call has not been executed yet - the value is already guaranteed to be visible locally, regarding get or equivalent operations?

      2)
      After an operation like this on node A:
      cache.putAsync(k1, v1);
      cache.putAsync(k2, v2);

      From node's B point of view, is the order of reception guaranteed?
      In a practical example: say v2 contains a list of keys defining a group of values you need to fetch, if I update v2 adding the key k1 of v1 to this list, and on another node I get this list and *then* want to retrieve all values from the keys in this list, is it possible that I can't yet find v1?
      If I need this guarantee, would I need a transaction? (I would love to avoid that because of other issues)

        • 1. Re: async API guarantees
          manik

          1) Yes. Only the RPC happens in a separate thread. The rest (locking, local update) all happens in the app thread.

          2) No, order is not guaranteed. The async API is only recommended for unrelated entries. And yes, using a transaction or a batch would guarantee order, but then you would not need to use the async API. Just doing:

          cache.startBatch();
          cache.put(k1, v1); // will return immediately, will not wait for RPC
          cache.put(k2, v2); // will also return immediately
          cache.endBatch(true); // will push the replication for the above PUTs in a single RPC message
          



          • 2. Re: async API guarantees
            sannegrinovero

            thanks a lot!
            this clarifies the usage and perfectly solves my needs.
            I'm going to throw away transactions, as Lucene doesn't have this concept and it was making things unnecessarily complex.