Search in sources :

Example 91 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class XAResourceImpl method clearRemoteTransactions.

private void clearRemoteTransactions(Xid xid) {
    NodeEngine nodeEngine = getNodeEngine();
    IPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();
    SerializableXID serializableXID = new SerializableXID(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
    Data xidData = nodeEngine.toData(serializableXID);
    int partitionId = partitionService.getPartitionId(xidData);
    ClearRemoteTransactionOperation operation = new ClearRemoteTransactionOperation(xidData);
    operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) ClearRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.ClearRemoteTransactionOperation) IPartitionService(com.hazelcast.internal.partition.IPartitionService) Data(com.hazelcast.internal.serialization.Data) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 92 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class XATransaction method commitAsync.

public void commitAsync(BiConsumer callback) {
    if (state != PREPARED) {
        throw new IllegalStateException("Transaction is not prepared");
    }
    checkTimeout();
    state = COMMITTING;
    BiConsumer wrappedCallback = (input, throwable) -> {
        try {
            callback.accept(input, throwable);
        } finally {
            if (throwable != null) {
                transactionLog.onCommitFailure();
            } else {
                transactionLog.onCommitSuccess();
            }
        }
    };
    transactionLog.commitAsync(nodeEngine, wrappedCallback);
    // We should rethrow exception if transaction is not TWO_PHASE
    state = COMMITTED;
}
Also used : TransactionLogRecord(com.hazelcast.transaction.impl.TransactionLogRecord) FutureUtil.logAllExceptions(com.hazelcast.internal.util.FutureUtil.logAllExceptions) Clock(com.hazelcast.internal.util.Clock) PutRemoteTransactionOperation(com.hazelcast.transaction.impl.xa.operations.PutRemoteTransactionOperation) FutureUtil(com.hazelcast.internal.util.FutureUtil) ROLLING_BACK(com.hazelcast.transaction.impl.Transaction.State.ROLLING_BACK) MINUTES(java.util.concurrent.TimeUnit.MINUTES) TransactionException(com.hazelcast.transaction.TransactionException) Level(java.util.logging.Level) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) RETHROW_TRANSACTION_EXCEPTION(com.hazelcast.internal.util.FutureUtil.RETHROW_TRANSACTION_EXCEPTION) ILogger(com.hazelcast.logging.ILogger) ROLLED_BACK(com.hazelcast.transaction.impl.Transaction.State.ROLLED_BACK) BiConsumer(java.util.function.BiConsumer) PREPARING(com.hazelcast.transaction.impl.Transaction.State.PREPARING) UuidUtil(com.hazelcast.internal.util.UuidUtil) TransactionLog(com.hazelcast.transaction.impl.TransactionLog) Xid(javax.transaction.xa.Xid) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Collection(java.util.Collection) FutureUtil.waitWithDeadline(com.hazelcast.internal.util.FutureUtil.waitWithDeadline) PREPARED(com.hazelcast.transaction.impl.Transaction.State.PREPARED) IPartitionService(com.hazelcast.internal.partition.IPartitionService) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) SERVICE_NAME(com.hazelcast.transaction.impl.xa.XAService.SERVICE_NAME) ACTIVE(com.hazelcast.transaction.impl.Transaction.State.ACTIVE) Transaction(com.hazelcast.transaction.impl.Transaction) UUID(java.util.UUID) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) COMMIT_FAILED(com.hazelcast.transaction.impl.Transaction.State.COMMIT_FAILED) COMMITTING(com.hazelcast.transaction.impl.Transaction.State.COMMITTING) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) NO_TXN(com.hazelcast.transaction.impl.Transaction.State.NO_TXN) COMMITTED(com.hazelcast.transaction.impl.Transaction.State.COMMITTED) XAException(javax.transaction.xa.XAException) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) TransactionType(com.hazelcast.transaction.TransactionOptions.TransactionType) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BiConsumer(java.util.function.BiConsumer)

Example 93 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class XAResourceImpl method recover.

@Override
public Xid[] recover(int flag) throws XAException {
    NodeEngine nodeEngine = getNodeEngine();
    XAService xaService = getService();
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    Collection<Member> memberList = clusterService.getMembers();
    List<Future<SerializableList>> futureList = new ArrayList<Future<SerializableList>>();
    for (Member member : memberList) {
        if (member.localMember()) {
            continue;
        }
        CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation();
        Address address = member.getAddress();
        InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address);
        futureList.add(future);
    }
    Set<SerializableXID> xids = new HashSet<SerializableXID>(xaService.getPreparedXids());
    for (Future<SerializableList> future : futureList) {
        try {
            SerializableList xidSet = future.get();
            for (Data xidData : xidSet) {
                SerializableXID xid = nodeEngine.toObject(xidData);
                xids.add(xid);
            }
        } catch (InterruptedException e) {
            currentThread().interrupt();
            throw new XAException(XAException.XAER_RMERR);
        } catch (MemberLeftException e) {
            logger.warning("Member left while recovering", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof HazelcastInstanceNotActiveException || cause instanceof TargetNotMemberException) {
                logger.warning("Member left while recovering", e);
            } else {
                throw new XAException(XAException.XAER_RMERR);
            }
        }
    }
    return xids.toArray(new SerializableXID[0]);
}
Also used : Address(com.hazelcast.cluster.Address) SerializableList(com.hazelcast.spi.impl.SerializableList) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeEngine(com.hazelcast.spi.impl.NodeEngine) CollectRemoteTransactionsOperation(com.hazelcast.transaction.impl.xa.operations.CollectRemoteTransactionsOperation) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet) MemberLeftException(com.hazelcast.core.MemberLeftException) XAException(javax.transaction.xa.XAException) Data(com.hazelcast.internal.serialization.Data) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ClusterService(com.hazelcast.internal.cluster.ClusterService) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 94 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class XaReplicationOperation method run.

@Override
public void run() throws Exception {
    XAService xaService = getService();
    NodeEngine nodeEngine = getNodeEngine();
    for (XATransactionDTO transactionDTO : migrationData) {
        XATransaction transaction = new XATransaction(nodeEngine, transactionDTO.getRecords(), transactionDTO.getTxnId(), transactionDTO.getXid(), transactionDTO.getOwnerUuid(), transactionDTO.getTimeoutMilis(), transactionDTO.getStartTime());
        xaService.putTransaction(transaction);
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) XAService(com.hazelcast.transaction.impl.xa.XAService) XATransactionDTO(com.hazelcast.transaction.impl.xa.XATransactionDTO) XATransaction(com.hazelcast.transaction.impl.xa.XATransaction)

Example 95 with NodeEngine

use of com.hazelcast.spi.impl.NodeEngine in project hazelcast by hazelcast.

the class ExecutionPlanBuilder method createExecutionPlans.

@SuppressWarnings("checkstyle:ParameterNumber")
public static Map<MemberInfo, ExecutionPlan> createExecutionPlans(NodeEngineImpl nodeEngine, List<MemberInfo> memberInfos, DAG dag, long jobId, long executionId, JobConfig jobConfig, long lastSnapshotId, boolean isLightJob, Subject subject) {
    final int defaultParallelism = nodeEngine.getConfig().getJetConfig().getCooperativeThreadCount();
    final Map<MemberInfo, int[]> partitionsByMember = getPartitionAssignment(nodeEngine, memberInfos);
    final Map<Address, int[]> partitionsByAddress = partitionsByMember.entrySet().stream().collect(toMap(en -> en.getKey().getAddress(), Entry::getValue));
    final List<Address> addresses = toList(partitionsByMember.keySet(), MemberInfo::getAddress);
    final int clusterSize = partitionsByMember.size();
    final boolean isJobDistributed = clusterSize > 1;
    final EdgeConfig defaultEdgeConfig = nodeEngine.getConfig().getJetConfig().getDefaultEdgeConfig();
    final Map<MemberInfo, ExecutionPlan> plans = new HashMap<>();
    int memberIndex = 0;
    for (MemberInfo member : partitionsByMember.keySet()) {
        plans.put(member, new ExecutionPlan(partitionsByAddress, jobConfig, lastSnapshotId, memberIndex++, clusterSize, isLightJob, subject));
    }
    final Map<String, Integer> vertexIdMap = assignVertexIds(dag);
    for (Entry<String, Integer> entry : vertexIdMap.entrySet()) {
        final Vertex vertex = dag.getVertex(entry.getKey());
        assert vertex != null;
        final ProcessorMetaSupplier metaSupplier = vertex.getMetaSupplier();
        final int vertexId = entry.getValue();
        // The local parallelism determination here is effective only
        // in jobs submitted as DAG. Otherwise, in jobs submitted as
        // pipeline, we are already doing this determination while
        // converting it to DAG and there is no vertex left with LP=-1.
        final int localParallelism = vertex.determineLocalParallelism(defaultParallelism);
        final int totalParallelism = localParallelism * clusterSize;
        final List<EdgeDef> inbound = toEdgeDefs(dag.getInboundEdges(vertex.getName()), defaultEdgeConfig, e -> vertexIdMap.get(e.getSourceName()), isJobDistributed);
        final List<EdgeDef> outbound = toEdgeDefs(dag.getOutboundEdges(vertex.getName()), defaultEdgeConfig, e -> vertexIdMap.get(e.getDestName()), isJobDistributed);
        String prefix = prefix(jobConfig.getName(), jobId, vertex.getName(), "#PMS");
        ILogger logger = prefixedLogger(nodeEngine.getLogger(metaSupplier.getClass()), prefix);
        JetServiceBackend jetBackend = nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
        JobClassLoaderService jobClassLoaderService = jetBackend.getJobClassLoaderService();
        ClassLoader processorClassLoader = jobClassLoaderService.getClassLoader(jobId);
        try {
            doWithClassLoader(processorClassLoader, () -> metaSupplier.init(new MetaSupplierCtx(nodeEngine, jobId, executionId, jobConfig, logger, vertex.getName(), localParallelism, totalParallelism, clusterSize, isLightJob, partitionsByAddress, subject, processorClassLoader)));
        } catch (Exception e) {
            throw sneakyThrow(e);
        }
        Function<? super Address, ? extends ProcessorSupplier> procSupplierFn = doWithClassLoader(processorClassLoader, () -> metaSupplier.get(addresses));
        for (Entry<MemberInfo, ExecutionPlan> e : plans.entrySet()) {
            final ProcessorSupplier processorSupplier = doWithClassLoader(processorClassLoader, () -> procSupplierFn.apply(e.getKey().getAddress()));
            if (!isLightJob) {
                // We avoid the check for light jobs - the user will get the error anyway, but maybe with less information.
                // And we can recommend the user to use normal job to have more checks.
                checkSerializable(processorSupplier, "ProcessorSupplier in vertex '" + vertex.getName() + '\'');
            }
            final VertexDef vertexDef = new VertexDef(vertexId, vertex.getName(), processorSupplier, localParallelism);
            vertexDef.addInboundEdges(inbound);
            vertexDef.addOutboundEdges(outbound);
            e.getValue().addVertex(vertexDef);
        }
    }
    return plans;
}
Also used : IntStream(java.util.stream.IntStream) Address(com.hazelcast.cluster.Address) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) Util.checkSerializable(com.hazelcast.jet.impl.util.Util.checkSerializable) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) HashMap(java.util.HashMap) ExceptionUtil.sneakyThrow(com.hazelcast.jet.impl.util.ExceptionUtil.sneakyThrow) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PrefixedLogger.prefixedLogger(com.hazelcast.jet.impl.util.PrefixedLogger.prefixedLogger) LinkedHashMap(java.util.LinkedHashMap) Collectors.toMap(java.util.stream.Collectors.toMap) ILogger(com.hazelcast.logging.ILogger) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Tuple2(com.hazelcast.jet.datamodel.Tuple2) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) PrefixedLogger.prefix(com.hazelcast.jet.impl.util.PrefixedLogger.prefix) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Util.toList(com.hazelcast.jet.impl.util.Util.toList) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) IPartitionService(com.hazelcast.internal.partition.IPartitionService) JobConfig(com.hazelcast.jet.config.JobConfig) MetaSupplierCtx(com.hazelcast.jet.impl.execution.init.Contexts.MetaSupplierCtx) Collectors(java.util.stream.Collectors) Subject(javax.security.auth.Subject) Vertex(com.hazelcast.jet.core.Vertex) List(java.util.List) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) Entry(java.util.Map.Entry) JobClassLoaderService(com.hazelcast.jet.impl.JobClassLoaderService) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) Vertex(com.hazelcast.jet.core.Vertex) Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Util.doWithClassLoader(com.hazelcast.jet.impl.util.Util.doWithClassLoader) ILogger(com.hazelcast.logging.ILogger) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) JobClassLoaderService(com.hazelcast.jet.impl.JobClassLoaderService) MetaSupplierCtx(com.hazelcast.jet.impl.execution.init.Contexts.MetaSupplierCtx)

Aggregations

NodeEngine (com.hazelcast.spi.impl.NodeEngine)165 Data (com.hazelcast.internal.serialization.Data)48 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)30 Address (com.hazelcast.cluster.Address)22 Test (org.junit.Test)21 ILogger (com.hazelcast.logging.ILogger)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)18 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Config (com.hazelcast.config.Config)17 Operation (com.hazelcast.spi.impl.operationservice.Operation)16 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)15 IPartitionService (com.hazelcast.internal.partition.IPartitionService)12 Nonnull (javax.annotation.Nonnull)12 ArrayList (java.util.ArrayList)11 Future (java.util.concurrent.Future)11 Member (com.hazelcast.cluster.Member)10 UUID (java.util.UUID)10 InitializingObject (com.hazelcast.spi.impl.InitializingObject)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)9