use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.
the class GetDurableCQs method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
AcceptorImpl acceptor = serverConnection.getAcceptor();
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
ClientProxyMembershipID id = serverConnection.getProxyID();
CacheServerStats stats = serverConnection.getCacheServerStats();
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
if (logger.isDebugEnabled()) {
logger.debug("{}: Received {} request from {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString());
}
DefaultQueryService qService = null;
CqService cqServiceForExec = null;
try {
qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
this.securityService.authorizeClusterRead();
// Authorization check
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
authzRequest.getDurableCQsAuthorize();
}
cqServiceForExec = qService.getCqService();
List<String> durableCqs = cqServiceForExec.getAllDurableClientCqs(id);
ChunkedMessage chunkedResponseMsg = serverConnection.getChunkedResponseMessage();
chunkedResponseMsg.setMessageType(MessageType.RESPONSE);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
List durableCqList = new ArrayList(MAXIMUM_CHUNK_SIZE);
final boolean isTraceEnabled = logger.isTraceEnabled();
for (Iterator it = durableCqs.iterator(); it.hasNext(); ) {
Object durableCqName = it.next();
durableCqList.add(durableCqName);
if (isTraceEnabled) {
logger.trace("{}: getDurableCqsResponse <{}>; list size was {}", serverConnection.getName(), durableCqName, durableCqList.size());
}
if (durableCqList.size() == MAXIMUM_CHUNK_SIZE) {
// Send the chunk and clear the list
sendDurableCqsResponseChunk(durableCqList, false, serverConnection);
durableCqList.clear();
}
}
// Send the last chunk even if the list is of zero size.
sendDurableCqsResponseChunk(durableCqList, true, serverConnection);
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
return;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
return;
}
}
use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.
the class StopCQ method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException {
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
ClientProxyMembershipID id = serverConnection.getProxyID();
CacheServerStats stats = serverConnection.getCacheServerStats();
// Based on MessageType.QUERY
// Added by Rao 2/1/2007
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
start = DistributionStats.getStatTime();
// Retrieve the data from the message parts
String cqName = clientMessage.getPart(0).getString();
if (logger.isDebugEnabled()) {
logger.debug("{}: Received stop CQ request from {} cqName: {}", serverConnection.getName(), serverConnection.getSocketString(), cqName);
}
// Process the query request
if (cqName == null) {
String err = LocalizedStrings.StopCQ_THE_CQNAME_FOR_THE_CQ_STOP_REQUEST_IS_NULL.toLocalizedString();
sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
return;
}
// Process CQ stop request
try {
// Append Client ID to CQ name
CqService cqService = crHelper.getCache().getCqService();
cqService.start();
// String cqNameWithClientId = new String(cqName + "__" +
// getMembershipID());
String serverCqName = cqName;
if (id != null) {
serverCqName = cqService.constructServerCqName(cqName, id);
}
InternalCqQuery cqQuery = cqService.getCq(serverCqName);
this.securityService.authorizeDataManage();
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
String queryStr = null;
Set cqRegionNames = null;
if (cqQuery != null) {
queryStr = cqQuery.getQueryString();
cqRegionNames = new HashSet();
cqRegionNames.add(((CqQueryImpl) cqQuery).getRegionName());
}
authzRequest.stopCQAuthorize(cqName, queryStr, cqRegionNames);
}
cqService.stopCq(cqName, id);
if (cqQuery != null)
serverConnection.removeCq(cqName, cqQuery.isDurable());
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
return;
} catch (Exception e) {
String err = LocalizedStrings.StopCQ_EXCEPTION_WHILE_STOPPING_CQ_NAMED_0.toLocalizedString(cqName);
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e, serverConnection);
return;
}
// Send OK to client
sendCqResponse(MessageType.REPLY, LocalizedStrings.StopCQ_CQ_STOPPED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
serverConnection.setAsTrue(RESPONDED);
{
long oldStart = start;
start = DistributionStats.getStatTime();
stats.incProcessStopCqTime(start - oldStart);
}
}
use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.
the class DistributedRegionJUnitTest method retriedBulkOpGetsSavedVersionTag.
@Test
public void retriedBulkOpGetsSavedVersionTag() {
DistributedRegion region = prepare(true, true);
DistributedMember member = mock(DistributedMember.class);
ClientProxyMembershipID memberId = mock(ClientProxyMembershipID.class);
doReturn(false).when(region).isUsedForPartitionedRegionBucket();
byte[] memId = { 1, 2, 3 };
long threadId = 1;
long retrySeqId = 1;
ThreadIdentifier tid = new ThreadIdentifier(memId, threadId);
EventID retryEventID = new EventID(memId, threadId, retrySeqId);
boolean skipCallbacks = true;
int size = 2;
recordPutAllEvents(region, memId, threadId, skipCallbacks, member, memberId, size);
EventTracker eventTracker = region.getEventTracker();
ConcurrentMap<ThreadIdentifier, BulkOpHolder> map = eventTracker.getRecordedBulkOpVersionTags();
BulkOpHolder holder = map.get(tid);
EntryEventImpl retryEvent = EntryEventImpl.create(region, Operation.PUTALL_CREATE, "key1", "value1", null, false, member, !skipCallbacks, retryEventID);
retryEvent.setContext(memberId);
retryEvent.setPutAllOperation(mock(DistributedPutAllOperation.class));
region.hasSeenEvent(retryEvent);
assertTrue(retryEvent.getVersionTag().equals(holder.entryVersionTags.get(retryEventID)));
}
use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.
the class ClientsWithVersioningRetryDUnitTest method testRetryPut.
/**
* Test that we can successfully retry a distributed put all and get the version information.
* second failure in bug 44951
*/
@Test
public void testRetryPut() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
createServerRegion(vm0, RegionShortcut.REPLICATE);
createServerRegion(vm1, RegionShortcut.REPLICATE);
// create an event tag in vm0 and then replay that event in vm1
final DistributedMember memberID = (DistributedMember) vm0.invoke(new SerializableCallable("get id") {
public Object call() {
return ((DistributedRegion) getCache().getRegion("region")).getDistributionManager().getDistributionManagerId();
}
});
vm0.invoke(new SerializableCallable("create entry with fake event ID") {
@Override
public Object call() {
DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
VersionTag tag = new VMVersionTag();
tag.setMemberID(dr.getVersionMember());
tag.setRegionVersion(123);
tag.setEntryVersion(9);
tag.setVersionTimeStamp(System.currentTimeMillis());
EventID eventID = new EventID(new byte[0], 1, 0);
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
event.setVersionTag(tag);
event.setContext(new ClientProxyMembershipID(memberID));
dr.recordEvent(event);
event.release();
return memberID;
}
});
vm1.invoke(new SerializableRunnable("recover event tag in vm1 from vm0") {
@Override
public void run() {
DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
EventID eventID = new EventID(new byte[0], 1, 0);
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
try {
event.setContext(new ClientProxyMembershipID(memberID));
boolean recovered = ((BaseCommand) Put70.getCommand()).recoverVersionTagForRetriedOperation(event);
assertTrue("Expected to recover the version for this event ID", recovered);
assertEquals("Expected the region version to be 123", 123, event.getVersionTag().getRegionVersion());
} finally {
event.release();
}
}
});
// bug #48205 - a retried op in PR nodes not owning the primary bucket
// may already have a version assigned to it in another backup bucket
vm1.invoke(new SerializableRunnable("recover posdup event tag in vm1 event tracker from vm0") {
@Override
public void run() {
DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
EventID eventID = new EventID(new byte[0], 1, 0);
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
event.setPossibleDuplicate(true);
try {
dr.hasSeenEvent(event);
assertTrue("Expected to recover the version for the event ID", event.getVersionTag() != null);
} finally {
event.release();
}
}
});
}
use of org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID in project geode by apache.
the class InstantiatorTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
Instantiator mockInstantiator = mock(Instantiator.class);
EventID mockEventID = mock(EventID.class);
ClientProxyMembershipID mockClientProxyMembershipID = mock(ClientProxyMembershipID.class);
when(mockInstantiator.getInstantiatedClass()).thenReturn(null);
when(mockInstantiator.getId()).thenReturn(0);
when(mockInstantiator.getEventId()).thenReturn(mockEventID);
when(mockInstantiator.getContext()).thenReturn(mockClientProxyMembershipID);
mockInstantiator.setEventId(mockEventID);
mockInstantiator.setContext(mockClientProxyMembershipID);
verify(mockInstantiator, times(1)).setEventId(mockEventID);
verify(mockInstantiator, times(1)).setContext(mockClientProxyMembershipID);
assertThat(mockInstantiator.getEventId()).isSameAs(mockEventID);
assertThat(mockInstantiator.getContext()).isSameAs(mockClientProxyMembershipID);
assertThat(mockInstantiator.getInstantiatedClass()).isNull();
}
Aggregations