Search in sources :

Example 6 with ServerCQ

use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.

the class ExecuteCQ 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);
    // Retrieve the data from the message parts
    String cqName = clientMessage.getPart(0).getString();
    String cqQueryString = clientMessage.getPart(1).getString();
    int cqState = clientMessage.getPart(2).getInt();
    Part isDurablePart = clientMessage.getPart(3);
    byte[] isDurableByte = isDurablePart.getSerializedForm();
    boolean isDurable = (isDurableByte == null || isDurableByte[0] == 0) ? false : true;
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received {} request from {} CqName: {} queryString: {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString(), cqName, cqQueryString);
    }
    DefaultQueryService qService = null;
    CqService cqServiceForExec = null;
    Query query = null;
    Set cqRegionNames = null;
    ExecuteCQOperationContext executeCQContext = null;
    ServerCQ cqQuery = null;
    try {
        qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
        // Authorization check
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            query = qService.newQuery(cqQueryString);
            cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
            executeCQContext = authzRequest.executeCQAuthorize(cqName, cqQueryString, cqRegionNames);
            String newCqQueryString = executeCQContext.getQuery();
            if (!cqQueryString.equals(newCqQueryString)) {
                query = qService.newQuery(newCqQueryString);
                cqQueryString = newCqQueryString;
                cqRegionNames = executeCQContext.getRegionNames();
                if (cqRegionNames == null) {
                    cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
                }
            }
        }
        cqServiceForExec = qService.getCqService();
        cqQuery = cqServiceForExec.executeCq(cqName, cqQueryString, cqState, id, acceptor.getCacheClientNotifier(), isDurable, false, 0, null);
    } catch (CqException cqe) {
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
        return;
    } catch (Exception e) {
        writeChunkedException(clientMessage, e, serverConnection);
        return;
    }
    long oldstart = start;
    boolean sendResults = false;
    boolean successQuery = false;
    if (clientMessage.getMessageType() == MessageType.EXECUTECQ_WITH_IR_MSG_TYPE) {
        sendResults = true;
    }
    // Execute the query and send the result-set to client.
    try {
        if (query == null) {
            query = qService.newQuery(cqQueryString);
            cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
        }
        ((DefaultQuery) query).setIsCqQuery(true);
        successQuery = processQuery(clientMessage, query, cqQueryString, cqRegionNames, start, cqQuery, executeCQContext, serverConnection, sendResults);
        // Update the CQ statistics.
        cqQuery.getVsdStats().setCqInitialResultsTime((DistributionStats.getStatTime()) - oldstart);
        stats.incProcessExecuteCqWithIRTime((DistributionStats.getStatTime()) - oldstart);
    // logger.fine("Time spent in execute with initial results :" +
    // DistributionStats.getStatTime() + ", " + oldstart);
    } finally {
        // If failure to execute the query, close the CQ.
        if (!successQuery) {
            try {
                cqServiceForExec.closeCq(cqName, id);
            } catch (Exception ex) {
            // Ignore.
            }
        }
    }
    if (!sendResults && successQuery) {
        // Send OK to client
        sendCqResponse(MessageType.REPLY, LocalizedStrings.ExecuteCQ_CQ_CREATED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
        long start2 = DistributionStats.getStatTime();
        stats.incProcessCreateCqTime(start2 - oldstart);
    }
    serverConnection.setAsTrue(RESPONDED);
}
Also used : Set(java.util.Set) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) 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) Part(org.apache.geode.internal.cache.tier.sockets.Part) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ExecuteCQOperationContext(org.apache.geode.cache.operations.ExecuteCQOperationContext)

Example 7 with ServerCQ

use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.

the class FilterProfile method cleanupForClient.

void cleanupForClient(CacheClientNotifier ccn, ClientProxyMembershipID client) {
    Iterator cqIter = this.cqs.entrySet().iterator();
    while (cqIter.hasNext()) {
        Map.Entry cqEntry = (Map.Entry) cqIter.next();
        ServerCQ cq = (ServerCQ) cqEntry.getValue();
        ClientProxyMembershipID clientId = cq.getClientProxyId();
        if (clientId.equals(client)) {
            try {
                cq.close(false);
            } catch (Exception ignore) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Failed to remove CQ from the base region. CqName : {}", cq.getName());
                }
            }
            this.closeCq(cq);
        }
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) Iterator(java.util.Iterator) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CopyOnWriteHashMap(org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException)

Example 8 with ServerCQ

use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.

the class FilterProfile method processSetCqState.

public void processSetCqState(String serverCqName, ServerCQ ServerCQ) {
    ServerCQ cq = (ServerCQ) this.cqs.get(serverCqName);
    if (cq != null) {
        CqStateImpl cqState = (CqStateImpl) ServerCQ.getState();
        cq.setCqState(cqState.getState());
    }
}
Also used : ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CqStateImpl(org.apache.geode.cache.query.internal.CqStateImpl)

Example 9 with ServerCQ

use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.

the class FilterProfile method toData.

public void toData(DataOutput out) throws IOException {
    InternalDataSerializer.invokeToData(((InternalDistributedMember) memberID), out);
    InternalDataSerializer.writeSetOfLongs(this.allKeyClients, this.clientMap.hasLongID, out);
    DataSerializer.writeHashMap(this.keysOfInterest, out);
    DataSerializer.writeHashMap(this.patternsOfInterest, out);
    DataSerializer.writeHashMap(this.filtersOfInterest, out);
    InternalDataSerializer.writeSetOfLongs(this.allKeyClientsInv, this.clientMap.hasLongID, out);
    DataSerializer.writeHashMap(this.keysOfInterestInv, out);
    DataSerializer.writeHashMap(this.patternsOfInterestInv, out);
    DataSerializer.writeHashMap(this.filtersOfInterestInv, out);
    // Write CQ info.
    Map theCQs = this.cqs;
    int size = theCQs.size();
    InternalDataSerializer.writeArrayLength(size, out);
    for (Iterator it = theCQs.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry) it.next();
        String name = (String) entry.getKey();
        ServerCQ cq = (ServerCQ) entry.getValue();
        DataSerializer.writeString(name, out);
        InternalDataSerializer.invokeToData(cq, out);
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CopyOnWriteHashMap(org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 10 with ServerCQ

use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.

the class FilterProfile method fromData.

public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    InternalDistributedMember id = new InternalDistributedMember();
    InternalDataSerializer.invokeFromData(id, in);
    this.memberID = id;
    this.allKeyClients.addAll(InternalDataSerializer.readSetOfLongs(in));
    this.keysOfInterest.putAll(DataSerializer.readHashMap(in));
    this.patternsOfInterest.putAll(DataSerializer.readHashMap(in));
    this.filtersOfInterest.putAll(DataSerializer.readHashMap(in));
    this.allKeyClientsInv.addAll(InternalDataSerializer.readSetOfLongs(in));
    this.keysOfInterestInv.putAll(DataSerializer.readHashMap(in));
    this.patternsOfInterestInv.putAll(DataSerializer.readHashMap(in));
    this.filtersOfInterestInv.putAll(DataSerializer.readHashMap(in));
    // Read CQ Info.
    int numCQs = InternalDataSerializer.readArrayLength(in);
    if (numCQs > 0) {
        // do this
        int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
        // 33471
        try {
            for (int i = 0; i < numCQs; i++) {
                String serverCqName = DataSerializer.readString(in);
                ServerCQ cq = CqServiceProvider.readCq(in);
                processRegisterCq(serverCqName, cq, false);
                this.cqs.put(serverCqName, cq);
            }
        } finally {
            LocalRegion.setThreadInitLevelRequirement(oldLevel);
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ)

Aggregations

ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)11 Map (java.util.Map)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CancelException (org.apache.geode.CancelException)3 CqService (org.apache.geode.cache.query.internal.cq.CqService)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)3 Iterator (java.util.Iterator)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 CqStateImpl (org.apache.geode.cache.query.internal.CqStateImpl)2 FilterProfile (org.apache.geode.internal.cache.FilterProfile)2 FilterInfo (org.apache.geode.internal.cache.FilterRoutingInfo.FilterInfo)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 HAContainerMap (org.apache.geode.internal.cache.ha.HAContainerMap)2 CopyOnWriteHashMap (org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Region (org.apache.geode.cache.Region)1