use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.
the class LocalRegion method basicBridgeClear.
public void basicBridgeClear(Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EventID eventId) throws TimeoutException, EntryExistsException, CacheWriterException {
if (fromClient) {
// GatewayEventCallbackArgument to store the event id.
if (isGatewaySenderEnabled()) {
callbackArg = new GatewaySenderEventCallbackArgument(callbackArg);
}
}
RegionEventImpl event = new ClientRegionEventImpl(this, Operation.REGION_CLEAR, callbackArg, false, client.getDistributedMember(), client, eventId);
basicClear(event, true);
}
use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.
the class LocalRegion method basicBridgeCreate.
public boolean basicBridgeCreate(final Object key, final byte[] value, boolean isObject, Object callbackArg, final ClientProxyMembershipID client, boolean fromClient, EntryEventImpl clientEvent, boolean throwEntryExists) throws TimeoutException, EntryExistsException, CacheWriterException {
EventID eventId = clientEvent.getEventId();
Object theCallbackArg = callbackArg;
long startPut = CachePerfStats.getStatTime();
if (fromClient) {
// GatewayEventCallbackArgument to store the event id.
if (isGatewaySenderEnabled()) {
theCallbackArg = new GatewaySenderEventCallbackArgument(theCallbackArg);
}
}
@Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.CREATE, key, value, theCallbackArg, false, /* origin remote */
client.getDistributedMember(), true, /* generateCallbacks */
eventId);
try {
event.setContext(client);
// if this is a replayed operation or WAN event we may already have a version tag
event.setVersionTag(clientEvent.getVersionTag());
// carry over the possibleDuplicate flag from clientEvent
event.setPossibleDuplicate(clientEvent.isPossibleDuplicate());
// normal regions. Otherwise, it will become a distributed invalidate.
if (getDataPolicy() == DataPolicy.NORMAL) {
event.setLocalInvalid(true);
}
// Set the new value to the input byte[] if it isn't null
if (value != null) {
// in a CachedDeserializable; otherwise store it directly as a byte[]
if (isObject) {
// The value represents an object
event.setSerializedNewValue(value);
} else {
// The value does not represent an object
event.setNewValue(value);
}
}
// cannot overwrite an existing key
boolean ifNew = true;
// can create a new key
boolean ifOld = false;
// use now
long lastModified = 0L;
// not okay to overwrite the DESTROYED token
boolean overwriteDestroyed = false;
boolean success = basicUpdate(event, ifNew, ifOld, lastModified, overwriteDestroyed);
clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
if (success) {
clientEvent.setVersionTag(event.getVersionTag());
getCachePerfStats().endPut(startPut, event.isOriginRemote());
} else {
this.stopper.checkCancelInProgress(null);
if (throwEntryExists) {
throw new EntryExistsException("" + key, event.getOldValue());
}
}
return success;
} finally {
event.release();
}
}
use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.
the class LocalRegion method basicBridgePut.
public boolean basicBridgePut(Object key, Object value, byte[] deltaBytes, boolean isObject, Object callbackArg, ClientProxyMembershipID memberId, boolean fromClient, EntryEventImpl clientEvent) throws TimeoutException, CacheWriterException {
EventID eventID = clientEvent.getEventId();
Object theCallbackArg = callbackArg;
long startPut = CachePerfStats.getStatTime();
if (fromClient) {
// GatewayEventCallbackArgument to store the event id.
if (isGatewaySenderEnabled()) {
theCallbackArg = new GatewaySenderEventCallbackArgument(theCallbackArg);
}
}
@Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.UPDATE, key, null, /* new value */
theCallbackArg, false, /* origin remote */
memberId.getDistributedMember(), true, /* generateCallbacks */
eventID);
try {
event.setContext(memberId);
event.setDeltaBytes(deltaBytes);
// if this is a replayed operation we may already have a version tag
event.setVersionTag(clientEvent.getVersionTag());
// carry over the possibleDuplicate flag from clientEvent
event.setPossibleDuplicate(clientEvent.isPossibleDuplicate());
// serialized in a CachedDeserializable; otherwise store it directly as a byte[].
if (isObject && value instanceof byte[]) {
event.setSerializedNewValue((byte[]) value);
} else {
event.setNewValue(value);
}
boolean success = false;
try {
// can overwrite an existing key
boolean ifNew = false;
// can create a new key
boolean ifOld = false;
// use now
long lastModified = 0L;
// not okay to overwrite the DESTROYED token
boolean overwriteDestroyed = false;
success = basicUpdate(event, ifNew, ifOld, lastModified, overwriteDestroyed);
} catch (ConcurrentCacheModificationException ignore) {
// thrown by WAN conflicts
event.isConcurrencyConflict(true);
}
clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
if (success) {
clientEvent.setVersionTag(event.getVersionTag());
getCachePerfStats().endPut(startPut, event.isOriginRemote());
} else {
this.stopper.checkCancelInProgress(null);
}
return success;
} finally {
event.release();
}
}
use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.
the class LocalRegion method basicBridgeRemoveAll.
/**
* Called on a bridge server when it has a received a removeAll command from a client.
*
* @param keys a collection of the keys we are putting
* @param retryVersions a collection of version tags. If the client is retrying a key then that
* keys slot will be non-null in this collection. Note that keys and retryVersions are
* parallel lists.
* @param callbackArg callback argument from client
*/
public VersionedObjectList basicBridgeRemoveAll(List<Object> keys, ArrayList<VersionTag> retryVersions, ClientProxyMembershipID memberId, EventID eventId, Object callbackArg) throws TimeoutException, CacheWriterException {
long startOp = CachePerfStats.getStatTime();
if (isGatewaySenderEnabled()) {
callbackArg = new GatewaySenderEventCallbackArgument(callbackArg);
}
@Released final EntryEventImpl event = EntryEventImpl.create(this, Operation.REMOVEALL_DESTROY, null, null, /* new value */
callbackArg, false, /* origin remote */
memberId.getDistributedMember(), true, /* generateCallbacks */
eventId);
try {
event.setContext(memberId);
DistributedRemoveAllOperation removeAllOp = new DistributedRemoveAllOperation(event, keys.size(), true);
try {
VersionedObjectList result = basicRemoveAll(keys, removeAllOp, retryVersions);
getCachePerfStats().endRemoveAll(startOp);
return result;
} finally {
removeAllOp.freeOffHeapResources();
}
} finally {
event.release();
}
}
use of org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument in project geode by apache.
the class SerialGatewaySenderEventProcessor method handleFailover.
/**
* Handle failover. This method is called when a secondary <code>GatewaySender</code> becomes a
* primary <code>GatewaySender</code>.
*
* Once this secondary becomes the primary, it must:
* <ul>
* <li>Remove the queue's CacheListener
* <li>Process the map of unprocessed events (those it has seen but the previous primary had not
* yet processed before it crashed). These will include both queued and unqueued events. Remove
* from the queue any events that were already sent
* <li>Clear the unprocessed events map
* </ul>
*/
protected void handleFailover() {
/*
* We must hold this lock while we're processing these maps to prevent us from handling a
* secondary event while failover occurs. See enqueueEvent
*/
synchronized (this.unprocessedEventsLock) {
// Remove the queue's CacheListener
this.queue.removeCacheListener();
this.unprocessedTokens = null;
// Process the map of unprocessed events
logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_GATEWAY_FAILOVER_INITIATED_PROCESSING_0_UNPROCESSED_EVENTS, this.unprocessedEvents.size()));
GatewaySenderStats statistics = this.sender.getStatistics();
if (!this.unprocessedEvents.isEmpty()) {
// do a reap for bug 37603
// to get rid of timed out events
reapOld(statistics, true);
// now iterate over the region queue to figure out what unprocessed
// events are already in the queue
{
Iterator it = this.queue.getRegion().values().iterator();
while (it.hasNext() && !stopped()) {
Object o = it.next();
if (o != null && o instanceof GatewaySenderEventImpl) {
GatewaySenderEventImpl ge = (GatewaySenderEventImpl) o;
EventWrapper unprocessedEvent = this.unprocessedEvents.remove(ge.getEventId());
if (unprocessedEvent != null) {
unprocessedEvent.event.release();
if (this.unprocessedEvents.isEmpty()) {
break;
}
}
}
}
}
// now for every unprocessed event add it to the end of the queue
{
Iterator<Map.Entry<EventID, EventWrapper>> it = this.unprocessedEvents.entrySet().iterator();
while (it.hasNext()) {
if (stopped())
break;
Map.Entry<EventID, EventWrapper> me = it.next();
EventWrapper ew = me.getValue();
GatewaySenderEventImpl gatewayEvent = ew.event;
// Initialize each gateway event. This initializes the key,
// value
// and callback arg based on the EntryEvent.
// TODO:wan70, remove dependencies from old code
gatewayEvent.initialize();
// Verify that they GatewayEventCallbackArgument is initialized.
// If not, initialize it. It won't be initialized if a client to
// this GatewayHub VM was the creator of this event. This Gateway
// will be the first one to process it. If will be initialized if
// this event was sent to this Gateway from another GatewayHub
// (either directly or indirectly).
GatewaySenderEventCallbackArgument seca = gatewayEvent.getSenderCallbackArgument();
if (seca.getOriginatingDSId() == GatewaySender.DEFAULT_DISTRIBUTED_SYSTEM_ID) {
seca.setOriginatingDSId(sender.getMyDSId());
seca.initializeReceipientDSIds(Collections.singletonList(sender.getRemoteDSId()));
}
it.remove();
boolean queuedEvent = false;
try {
queuedEvent = queuePrimaryEvent(gatewayEvent);
} catch (IOException ex) {
if (!stopped()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_EVENT_DROPPED_DURING_FAILOVER_0, gatewayEvent), ex);
}
} catch (CacheException ex) {
if (!stopped()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_EVENT_DROPPED_DURING_FAILOVER_0, gatewayEvent), ex);
}
} finally {
if (!queuedEvent) {
gatewayEvent.release();
}
}
}
}
// Clear the unprocessed events map
statistics.clearUnprocessedMaps();
}
// Iterate the entire queue and mark all events as possible
// duplicate
logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0__MARKING__1__EVENTS_AS_POSSIBLE_DUPLICATES, new Object[] { getSender(), Integer.valueOf(this.queue.size()) }));
Iterator it = this.queue.getRegion().values().iterator();
while (it.hasNext() && !stopped()) {
Object o = it.next();
if (o != null && o instanceof GatewaySenderEventImpl) {
GatewaySenderEventImpl ge = (GatewaySenderEventImpl) o;
ge.setPossibleDuplicate(true);
}
}
releaseUnprocessedEvents();
}
// synchronized
}
Aggregations