use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class RemotePutMessage method operateOnRegion.
/**
* This method is called upon receipt and make the desired changes to the Replicate Region. Note:
* It is very important that this message does NOT cause any deadlocks as the sender will wait
* indefinitely for the acknowledgement
*/
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
// set the internal DS. Required to
this.setInternalDs(r.getSystem());
// checked DS level delta-enabled property
// while sending delta
boolean sendReply = true;
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl eei = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), useOriginRemote, /* originRemote - false to force distribution in buckets */
eventSender, true, /* generateCallbacks */
false);
this.event = eei;
try {
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
this.event.setCausedByMessage(this);
event.setPossibleDuplicate(this.possibleDuplicate);
if (this.bridgeContext != null) {
event.setContext(this.bridgeContext);
}
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
// added for cq procesing
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
if (this.applyDeltaBytes) {
event.setNewValue(this.valObj);
event.setDeltaBytes(this.deltaBytes);
} else {
switch(this.deserializationPolicy) {
case DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY:
event.setSerializedNewValue(getValBytes());
break;
case DistributedCacheOperation.DESERIALIZATION_POLICY_NONE:
event.setNewValue(getValBytes());
break;
default:
throw new AssertionError("unknown deserialization policy: " + deserializationPolicy);
}
}
try {
// the event must show it's true origin for cachewriter invocation
// event.setOriginRemote(true);
// this.op = r.doCacheWriteBeforePut(event, ifNew); // TODO fix this for bug 37072
result = r.getDataView().putEntry(event, this.ifNew, this.ifOld, this.expectedOldValue, this.requireOldValue, this.lastModified, true);
if (!this.result) {
// make sure the region hasn't gone away
r.checkReadiness();
if (!this.ifNew && !this.ifOld) {
// no reason to be throwing an exception, so let's retry
RemoteOperationException fre = new RemoteOperationException(LocalizedStrings.RemotePutMessage_UNABLE_TO_PERFORM_PUT_BUT_OPERATION_SHOULD_NOT_FAIL_0.toLocalizedString());
fre.setHash(key.hashCode());
sendReply(getSender(), getProcessorId(), dm, new ReplyException(fre), r, startTime);
}
}
} catch (CacheWriterException cwe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(cwe), r, startTime);
return false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
return false;
}
// set operation for reply message
setOperation(event.getOperation());
if (sendReply) {
sendReply(getSender(), getProcessorId(), dm, null, r, startTime, event);
}
return false;
} finally {
// OFFHEAP this may be too soon to make this call
this.event.release();
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class RemotePutMessage method distribute.
/**
* this is similar to send() but it selects an initialized replicate that is used to proxy the
* message
*
* @param event represents the current operation
* @param lastModified lastModified time
* @param ifNew whether a new entry can be created
* @param ifOld whether an old entry can be used (updates are okay)
* @param expectedOldValue the value being overwritten is required to match this value
* @param requireOldValue whether the old value should be returned
* @param onlyPersistent send message to persistent members only
* @return whether the message was successfully distributed to another member
*/
public static boolean distribute(EntryEventImpl event, long lastModified, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, boolean onlyPersistent) {
boolean successful = false;
DistributedRegion r = (DistributedRegion) event.getRegion();
Collection replicates = onlyPersistent ? r.getCacheDistributionAdvisor().adviseInitializedPersistentMembers().keySet() : r.getCacheDistributionAdvisor().adviseInitializedReplicates();
if (replicates.isEmpty()) {
return false;
}
if (replicates.size() > 1) {
ArrayList l = new ArrayList(replicates);
Collections.shuffle(l);
replicates = l;
}
int attempts = 0;
if (logger.isDebugEnabled()) {
logger.debug("performing remote put messaging for {}", event);
}
for (Iterator<InternalDistributedMember> it = replicates.iterator(); it.hasNext(); ) {
InternalDistributedMember replicate = it.next();
try {
attempts++;
final boolean posDup = (attempts > 1);
RemotePutResponse response = send(replicate, event.getRegion(), event, lastModified, ifNew, ifOld, expectedOldValue, requireOldValue, false, DistributionManager.SERIAL_EXECUTOR, posDup);
PutResult result = response.waitForResult();
event.setOldValue(result.oldValue, true);
event.setOperation(result.op);
if (result.versionTag != null) {
event.setVersionTag(result.versionTag);
if (event.getRegion().getVersionVector() != null) {
event.getRegion().getVersionVector().recordVersion(result.versionTag.getMemberID(), result.versionTag);
}
}
event.setInhibitDistribution(true);
return true;
} catch (TransactionDataNotColocatedException enfe) {
throw enfe;
} catch (CancelException e) {
event.getRegion().getCancelCriterion().checkCancelInProgress(e);
} catch (CacheException e) {
if (logger.isDebugEnabled()) {
logger.debug("RemotePutMessage caught CacheException during distribution", e);
}
// not a cancel-exception, so don't complain any more about it
successful = true;
} catch (RemoteOperationException e) {
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "RemotePutMessage caught an unexpected exception during distribution", e);
}
}
}
return successful;
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class TXCommitMessage method send.
void send(TXLockId lockId) {
if (isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("empty transaction - nothing to distribute");
}
return;
}
Assert.assertTrue(this.txState != null, "Send must have transaction state.");
this.lockId = (TXLockIdImpl) lockId;
updateLockMembers();
// Map of RegionCommitList keys to Sets of
IdentityHashMap distMap = new IdentityHashMap();
// receivers
HashSet ackReceivers = null;
{
Iterator it = this.msgMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry me = (Map.Entry) it.next();
RegionCommitList rcl = (RegionCommitList) me.getValue();
if (rcl.getNeedsAck()) {
if (ackReceivers == null) {
ackReceivers = new HashSet();
}
ackReceivers.add(me.getKey());
}
HashSet receivers = (HashSet) distMap.get(rcl);
if (receivers == null) {
receivers = new HashSet();
distMap.put(rcl, receivers);
}
receivers.add(me.getKey());
}
}
CommitReplyProcessor processor = null;
{
if (ackReceivers != null) {
processor = new CommitReplyProcessor(this.dm, ackReceivers, msgMap);
if (ackReceivers.size() > 1) {
this.farSiders = ackReceivers;
}
processor.enableSevereAlertProcessing();
}
{
Iterator it = distMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry me = (Map.Entry) it.next();
RegionCommitList rcl = (RegionCommitList) me.getKey();
HashSet recipients = (HashSet) me.getValue();
// now remove from the recipients any guys that the dm no
// longer knows about
recipients.retainAll(this.dm.getDistributionManagerIds());
if (!recipients.isEmpty()) {
if (this.txState.internalDuringIndividualSend != null) {
// Run in test mode, splitting out individaual recipients,
// so we can control who gets what
Iterator indivRecip = recipients.iterator();
while (indivRecip.hasNext()) {
this.txState.internalDuringIndividualSend.run();
setRecipientsSendData(Collections.singleton(indivRecip.next()), processor, rcl);
}
} else {
// Run in normal mode sending to mulitiple recipients in
// one shot
setRecipientsSendData(recipients, processor, rcl);
}
}
}
}
if (this.txState.internalAfterIndividualSend != null) {
this.txState.internalAfterIndividualSend.run();
}
}
if (processor != null) {
// Send the CommitProcessMessage
final CommitProcessMessage cpMsg;
if (this.lockId != null) {
cpMsg = new CommitProcessForLockIdMessage(this.lockId);
} else {
cpMsg = new CommitProcessForTXIdMessage(this.txIdent);
}
if (this.txState.internalDuringIndividualCommitProcess != null) {
// Run in test mode
Iterator<InternalDistributedMember> indivRecip = ackReceivers.iterator();
while (indivRecip.hasNext()) {
this.txState.internalDuringIndividualCommitProcess.run();
cpMsg.setRecipients(Collections.<InternalDistributedMember>singleton(indivRecip.next()));
this.dm.putOutgoing(cpMsg);
cpMsg.resetRecipients();
}
} else {
// Run in normal mode
cpMsg.setRecipients(ackReceivers);
this.dm.putOutgoing(cpMsg);
}
if (this.txState.internalAfterIndividualCommitProcess != null) {
// Testing callback
this.txState.internalAfterIndividualCommitProcess.run();
}
// for() loop removed for bug 36983 - you can't loop on waitForReplies()
dm.getCancelCriterion().checkCancelInProgress(null);
processor.waitForCommitCompletion();
this.dm.getStats().incCommitWaits();
}
if (this.hasReliableRegions) {
checkDistributionReliability(distMap, processor);
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class SearchLoadAndWriteProcessor method netSearchForBlob.
/** perform a net-search, setting this.result to the object found in the search */
private void netSearchForBlob() throws TimeoutException {
if (this.netSearchDone)
return;
this.netSearchDone = true;
CachePerfStats stats = region.getCachePerfStats();
long start = 0;
Set sendSet = null;
this.result = null;
RegionAttributes attrs = region.getAttributes();
// Object aCallbackArgument = null;
this.requestInProgress = true;
this.selectedNodeDead = false;
initRemainingTimeout();
start = stats.startNetsearch();
try {
List<InternalDistributedMember> replicates = new ArrayList(advisor.adviseInitializedReplicates());
if (replicates.size() > 1) {
Collections.shuffle(replicates);
}
for (InternalDistributedMember replicate : replicates) {
synchronized (this.pendingResponders) {
this.pendingResponders.clear();
}
synchronized (this) {
this.requestInProgress = true;
this.remoteGetInProgress = true;
setSelectedNode(replicate);
this.lastNotifySpot = 0;
sendValueRequest(replicate);
waitForObject2(this.remainingTimeout);
if (this.authorative) {
if (this.result != null) {
this.netSearch = true;
}
return;
} else {
// clear anything that might have been set by our query.
this.selectedNode = null;
this.selectedNodeDead = false;
this.lastNotifySpot = 0;
this.result = null;
}
}
}
synchronized (membersLock) {
Set recipients = this.advisor.adviseNetSearch();
if (recipients.isEmpty()) {
return;
}
ArrayList list = new ArrayList(recipients);
Collections.shuffle(list);
sendSet = new HashSet(list);
synchronized (this.pendingResponders) {
this.pendingResponders.clear();
this.pendingResponders.addAll(list);
}
}
boolean useMulticast = region.getMulticastEnabled() && (region instanceof DistributedRegion) && ((DistributedRegion) region).getSystem().getConfig().getMcastPort() != 0;
// moved outside the sync to fix bug 39458
QueryMessage.sendMessage(this, this.regionName, this.key, useMulticast, sendSet, this.remainingTimeout, attrs.getEntryTimeToLive().getTimeout(), attrs.getEntryIdleTimeout().getTimeout());
synchronized (this) {
// moved this send back into sync to fix bug 37132
// QueryMessage.sendMessage(this, this.regionName,this.key,useMulticast,
// sendSet,this.remainingTimeout ,
// attrs.getEntryTimeToLive().getTimeout(),
// attrs.getEntryIdleTimeout().getTimeout());
boolean done = false;
do {
waitForObject2(this.remainingTimeout);
if (this.selectedNodeDead && remoteGetInProgress) {
sendNetSearchRequest();
} else
done = true;
} while (!done);
if (this.result != null) {
this.netSearch = true;
}
return;
}
} finally {
stats.endNetsearch(start);
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class SearchLoadAndWriteProcessor method sendNetSearchRequest.
private synchronized void sendNetSearchRequest() {
InternalDistributedMember nextResponder = nextAppropriateResponder();
if (nextResponder != null) {
// Make a request to the next responder in the queue
RegionAttributes attrs = this.region.getAttributes();
setSelectedNode(nextResponder);
this.requestInProgress = true;
this.remoteGetInProgress = true;
NetSearchRequestMessage.sendMessage(this, this.regionName, this.key, nextResponder, this.remainingTimeout, attrs.getEntryTimeToLive().getTimeout(), attrs.getEntryIdleTimeout().getTimeout());
} else {
this.remoteGetInProgress = false;
checkIfDone();
}
}
Aggregations