Search in sources :

Example 6 with ClientProxyMembershipID

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;
    }
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) ArrayList(java.util.ArrayList) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 7 with ClientProxyMembershipID

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);
    }
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) Set(java.util.Set) HashSet(java.util.HashSet) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) HashSet(java.util.HashSet)

Example 8 with ClientProxyMembershipID

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)));
}
Also used : ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) BulkOpHolder(org.apache.geode.internal.cache.EventTracker.BulkOpHolder) DistributedMember(org.apache.geode.distributed.DistributedMember) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 9 with ClientProxyMembershipID

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();
            }
        }
    });
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedMember(org.apache.geode.distributed.DistributedMember) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EventID(org.apache.geode.internal.cache.EventID) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 10 with ClientProxyMembershipID

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();
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) EventID(org.apache.geode.internal.cache.EventID) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)30 Test (org.junit.Test)10 IOException (java.io.IOException)7 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)7 CqException (org.apache.geode.cache.query.CqException)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 CqService (org.apache.geode.cache.query.internal.cq.CqService)5 EventID (org.apache.geode.internal.cache.EventID)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)5 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)5 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)5 Iterator (java.util.Iterator)4 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)4 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)4 HashSet (java.util.HashSet)3 CacheException (org.apache.geode.cache.CacheException)3 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)3