LATEST VERSION: 9.0.4 - CHANGELOG
Pivotal GemFire® v9.0

Peer-to-Peer Event Distribution

When a region or entry operation is performed, Geode distributes the associated events in the distributed system according to system and cache configurations.

Install a cache listener for a region in each system member that needs to receive notification of region and entry changes.

Events in a Partitioned Region

A distributed operation follows this sequence in a partitioned region:

  1. Apply the operation to the cache with the primary data entry, if appropriate.
  2. Do the distribution based on the subscription-attributes interest-policy of the other members.
  3. Invoke any listeners in the caches that receive the distribution.
  4. Invoke the listener in the cache with the primary data entry.

In the following figure:

  1. An API call in member M1 creates an entry.
  2. The partitioned region creates the new entry in the cache in M2. M2, the holder of the primary copy, drives the rest of the procedure.
  3. These two operations occur simultaneously:

    • The partitioned region creates a secondary copy of the entry in the cache in M3. Creating the secondary copy does not invoke the listener on M3.
    • M2 distributes the event to M4. This distribution to the other members is based on their interest policies. M4 has an interest-policy of all , so it receives notification of all events anywhere in the region. Since M1 and M3 have an interest-policy of cache-content , and this event does not affect any pre-existing entry in their local caches, they do not receive the event.
  4. The cache listener on M4 handles the notification of the remote event on M2.

  5. Once everything on the other members has completed successfully, the original create operation on M2 succeeds and invokes the cache listener on M2.

Events in a Distributed Region

A distributed operation follows this sequence in a distributed region:

  1. Apply the operation to the local cache, if appropriate.
  2. Invoke the local listeners.
  3. Do the distribution.
  4. Each member that receives the distribution carries out its own operation in response, which invokes any local listeners.

In the following figure:

  1. An entry is created through a direct API call on member M1.
  2. The create invokes the cache listener on M1.
  3. M1 distributes the event to the other members.
  4. M2 and M3 apply the remote change through their own local operations.
  5. M3 does a create, but M2 does an update, because the entry already existed in its cache.
  6. The cache listener on M2 receives callbacks for the local update. Since there is no cache listener on M3, the callbacks from the create on M3 are not handled. An API call in member M1 creates an entry.

Managing Events in Multi-threaded Applications

For partitioned regions, Geode guarantees ordering of events across threads, but for distributed regions it doesn’t. For multi-threaded applications that create distributed regions, you need to use your application synchronization to make sure that one operation completes before the next one begins. Distribution through the distributed-no-ack queue can work with multiple threads if you set the conserve-sockets attribute to true. Then the threads share one queue, preserving the order of the events in distributed regions. Different threads can invoke the same listener, so if you allow different threads to send events, it can result in concurrent invocations of the listener. This is an issue only if the threads have some shared state - if they are incrementing a serial number, for example, or adding their events to a log queue. Then you need to make your code thread safe.