Search in sources :

Example 21 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GetPdxTypes70 method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received get pdx types from {}", serverConnection.getName(), serverConnection.getSocketString());
    }
    Map<Integer, PdxType> types;
    try {
        InternalCache cache = serverConnection.getCache();
        types = cache.getPdxRegistry().typeMap();
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    Message responseMsg = serverConnection.getResponseMessage();
    responseMsg.setMessageType(MessageType.RESPONSE);
    responseMsg.setNumberOfParts(1);
    responseMsg.setTransactionId(clientMessage.getTransactionId());
    responseMsg.addObjPart(types);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) Message(org.apache.geode.internal.cache.tier.sockets.Message) InternalCache(org.apache.geode.internal.cache.InternalCache) IOException(java.io.IOException)

Example 22 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class DistTxEntryEvent method fromData.

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    this.eventID = (EventID) DataSerializer.readObject(in);
    String regionName = DataSerializer.readString(in);
    InternalCache cache = GemFireCacheImpl.getInstance();
    this.region = (LocalRegion) cache.getRegion(regionName);
    this.op = Operation.fromOrdinal(in.readByte());
    Object key = DataSerializer.readObject(in);
    Integer bucketId = DataSerializer.readInteger(in);
    this.keyInfo = new DistTxKeyInfo(key, null, /*
                                               * value [DISTTX} TODO see if required
                                               */
    null, /*
                                                       * callbackarg [DISTTX] TODO
                                                       */
    bucketId);
    basicSetNewValue(DataSerializer.readObject(in));
    byte flags = DataSerializer.readByte(in);
    if ((flags & HAS_PUTALL_OP) != 0) {
        putAllFromData(in);
    }
    if ((flags & HAS_REMOVEALL_OP) != 0) {
        removeAllFromData(in);
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 23 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class TXFailoverCommand method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    // Build the TXId for the transaction
    InternalDistributedMember client = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
    int uniqId = clientMessage.getTransactionId();
    if (logger.isDebugEnabled()) {
        logger.debug("TX: Transaction {} from {} is failing over to this server", uniqId, client);
    }
    TXId txId = new TXId(client, uniqId);
    TXManagerImpl mgr = (TXManagerImpl) serverConnection.getCache().getCacheTransactionManager();
    // in case it's already completing here in another
    mgr.waitForCompletingTransaction(txId);
    // thread
    if (mgr.isHostedTxRecentlyCompleted(txId)) {
        writeReply(clientMessage, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        mgr.removeHostedTXState(txId);
        return;
    }
    // fixes bug 43350
    boolean wasInProgress = mgr.setInProgress(true);
    TXStateProxy tx = mgr.getTXState();
    Assert.assertTrue(tx != null);
    if (!tx.isRealDealLocal()) {
        // send message to all peers to find out who hosts the transaction
        FindRemoteTXMessageReplyProcessor processor = FindRemoteTXMessage.send(serverConnection.getCache(), txId);
        try {
            processor.waitForRepliesUninterruptibly();
        } catch (ReplyException e) {
            e.handleAsUnexpected();
        }
        // if hosting member is not null, bootstrap PeerTXStateStub to that member
        // if hosting member is null, rebuild TXCommitMessage from partial TXCommitMessages
        InternalDistributedMember hostingMember = processor.getHostingMember();
        if (hostingMember != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("TX: txState is not local, bootstrapping PeerTXState stub for targetNode: {}", hostingMember);
            }
            // inject the real deal
            tx.setLocalTXState(new PeerTXStateStub(tx, hostingMember, client));
        } else {
            // bug #42228 and bug #43504 - this cannot return until the current view
            // has been installed by all members, so that dlocks are released and
            // the same keys can be used in a new transaction by the same client thread
            InternalCache cache = serverConnection.getCache();
            try {
                WaitForViewInstallation.send((DistributionManager) cache.getDistributionManager());
            } catch (InterruptedException e) {
                cache.getDistributionManager().getCancelCriterion().checkCancelInProgress(e);
                Thread.currentThread().interrupt();
            }
            // tx host has departed, rebuild the tx
            if (processor.getTxCommitMessage() != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("TX: for txId: {} rebuilt a recently completed tx", txId);
                }
                mgr.saveTXCommitMessageForClientFailover(txId, processor.getTxCommitMessage());
            } else {
                writeException(clientMessage, new TransactionDataNodeHasDepartedException("Could not find transaction host for " + txId), false, serverConnection);
                serverConnection.setAsTrue(RESPONDED);
                mgr.removeHostedTXState(txId);
                return;
            }
        }
    }
    if (!wasInProgress) {
        mgr.setInProgress(false);
    }
    writeReply(clientMessage, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) TXId(org.apache.geode.internal.cache.TXId) InternalCache(org.apache.geode.internal.cache.InternalCache) FindRemoteTXMessageReplyProcessor(org.apache.geode.internal.cache.FindRemoteTXMessage.FindRemoteTXMessageReplyProcessor) ReplyException(org.apache.geode.distributed.internal.ReplyException) PeerTXStateStub(org.apache.geode.internal.cache.PeerTXStateStub) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException)

Example 24 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class ClientTXStateStub method obtainLocalLocks.

/**
   * Lock the keys in a local transaction manager
   * 
   * @throws CommitConflictException if the key is already locked by some other transaction
   */
private void obtainLocalLocks() {
    lockReq = new TXLockRequest();
    InternalCache cache = GemFireCacheImpl.getExisting("");
    for (TransactionalOperation txOp : this.recordedOperations) {
        if (ServerRegionOperation.lockKeyForTx(txOp.getOperation())) {
            TXRegionLockRequest rlr = lockReq.getRegionLockRequest(txOp.getRegionName());
            if (rlr == null) {
                rlr = new TXRegionLockRequestImpl(cache.getRegionByPath(txOp.getRegionName()));
                lockReq.addLocalRequest(rlr);
            }
            if (txOp.getOperation() == ServerRegionOperation.PUT_ALL || txOp.getOperation() == ServerRegionOperation.REMOVE_ALL) {
                rlr.addEntryKeys(txOp.getKeys());
            } else {
                rlr.addEntryKey(txOp.getKey());
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("TX: client localLockRequest: {}", lockReq);
    }
    try {
        lockReq.obtain();
    } catch (CommitConflictException e) {
        // cleanup tx artifacts on server
        rollback();
        throw e;
    }
    if (internalAfterLocalLocks != null) {
        internalAfterLocalLocks.run();
    }
}
Also used : CommitConflictException(org.apache.geode.cache.CommitConflictException) TXRegionLockRequestImpl(org.apache.geode.internal.cache.TXRegionLockRequestImpl) TXLockRequest(org.apache.geode.internal.cache.TXLockRequest) InternalCache(org.apache.geode.internal.cache.InternalCache) TXRegionLockRequest(org.apache.geode.internal.cache.locks.TXRegionLockRequest)

Example 25 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GetPDXIdForType method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received get pdx id for type request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int noOfParts = clientMessage.getNumberOfParts();
    PdxType type = (PdxType) clientMessage.getPart(0).getObject();
    int pdxId;
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        pdxId = registry.defineType(type);
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    Message responseMsg = serverConnection.getResponseMessage();
    responseMsg.setMessageType(MessageType.RESPONSE);
    responseMsg.setNumberOfParts(1);
    responseMsg.setTransactionId(clientMessage.getTransactionId());
    responseMsg.addIntPart(pdxId);
    responseMsg.send(serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) Message(org.apache.geode.internal.cache.tier.sockets.Message) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Aggregations

InternalCache (org.apache.geode.internal.cache.InternalCache)267 DistributedMember (org.apache.geode.distributed.DistributedMember)78 Test (org.junit.Test)64 UnitTest (org.apache.geode.test.junit.categories.UnitTest)52 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 CliMetaData (org.apache.geode.management.cli.CliMetaData)34 CliCommand (org.springframework.shell.core.annotation.CliCommand)34 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)32 Region (org.apache.geode.cache.Region)31 Result (org.apache.geode.management.cli.Result)30 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)30 Expectations (org.jmock.Expectations)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)26 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)24 Set (java.util.Set)23 ResultCollector (org.apache.geode.cache.execute.ResultCollector)22 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)20