Search in sources :

Example 1 with PartitionReplicaVersionManager

use of com.hazelcast.internal.partition.PartitionReplicaVersionManager in project hazelcast by hazelcast.

the class FinalizePromotionOperation method shiftUpReplicaVersions.

/**
 * Sets replica versions up to this replica to the version of the last lost replica and
 * sends a {@link IPartitionLostEvent}.
 */
private void shiftUpReplicaVersions() {
    int partitionId = getPartitionId();
    int currentReplicaIndex = migrationInfo.getDestinationCurrentReplicaIndex();
    int lostReplicaIndex = currentReplicaIndex - 1;
    try {
        InternalPartitionServiceImpl partitionService = getService();
        PartitionReplicaVersionManager partitionReplicaVersionManager = partitionService.getPartitionReplicaVersionManager();
        for (ServiceNamespace namespace : partitionReplicaVersionManager.getNamespaces(partitionId)) {
            // returns the internal array itself, not the copy
            long[] versions = partitionReplicaVersionManager.getPartitionReplicaVersions(partitionId, namespace);
            if (currentReplicaIndex > 1) {
                long[] versionsCopy = Arrays.copyOf(versions, versions.length);
                long version = versions[lostReplicaIndex];
                Arrays.fill(versions, 0, lostReplicaIndex, version);
                if (logger.isFinestEnabled()) {
                    logger.finest("Partition replica is lost! partitionId=" + partitionId + " namespace: " + namespace + " lost replicaIndex=" + lostReplicaIndex + " replica versions before shift up=" + Arrays.toString(versionsCopy) + " replica versions after shift up=" + Arrays.toString(versions));
                }
            } else if (logger.isFinestEnabled()) {
                logger.finest("PROMOTE partitionId=" + getPartitionId() + " namespace: " + namespace + " from currentReplicaIndex=" + currentReplicaIndex);
            }
        }
        PartitionEventManager partitionEventManager = partitionService.getPartitionEventManager();
        partitionEventManager.sendPartitionLostEvent(partitionId, lostReplicaIndex);
    } catch (Throwable e) {
        logger.warning("Promotion failed. partitionId=" + partitionId + " replicaIndex=" + currentReplicaIndex, e);
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionEventManager(com.hazelcast.internal.partition.impl.PartitionEventManager) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 2 with PartitionReplicaVersionManager

use of com.hazelcast.internal.partition.PartitionReplicaVersionManager in project hazelcast by hazelcast.

the class PartitionReplicaSyncRequestOffloadable method readReplicaVersions.

private void readReplicaVersions() {
    InternalPartitionServiceImpl partitionService = getService();
    OperationService operationService = getNodeEngine().getOperationService();
    PartitionReplicaVersionManager versionManager = partitionService.getPartitionReplicaVersionManager();
    UrgentPartitionRunnable<Void> gatherReplicaVersionsRunnable = new UrgentPartitionRunnable<>(partitionId(), () -> {
        for (ServiceNamespace ns : namespaces) {
            // make a copy because
            // getPartitionReplicaVersions
            // returns references to the internal
            // replica versions data structures
            // that may change under our feet
            long[] versions = Arrays.copyOf(versionManager.getPartitionReplicaVersions(partitionId(), ns), IPartition.MAX_BACKUP_COUNT);
            replicaVersions.put(BiTuple.of(partitionId(), ns), versions);
        }
    });
    operationService.execute(gatherReplicaVersionsRunnable);
    gatherReplicaVersionsRunnable.future.joinInternal();
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 3 with PartitionReplicaVersionManager

use of com.hazelcast.internal.partition.PartitionReplicaVersionManager in project hazelcast by hazelcast.

the class PartitionReplicaSyncRequest method createResponse.

protected PartitionReplicaSyncResponse createResponse(Collection<Operation> operations, Collection<ChunkSupplier> chunkSuppliers, ServiceNamespace ns) {
    int partitionId = partitionId();
    int replicaIndex = getReplicaIndex();
    InternalPartitionServiceImpl partitionService = getService();
    PartitionReplicaVersionManager versionManager = partitionService.getPartitionReplicaVersionManager();
    long[] versions = versionManager.getPartitionReplicaVersions(partitionId, ns);
    PartitionReplicaSyncResponse syncResponse = new PartitionReplicaSyncResponse(operations, chunkSuppliers, ns, versions, isChunkedMigrationEnabled(), getMaxTotalChunkedDataInBytes(), getLogger(), partitionId);
    syncResponse.setPartitionId(partitionId).setReplicaIndex(replicaIndex);
    return syncResponse;
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 4 with PartitionReplicaVersionManager

use of com.hazelcast.internal.partition.PartitionReplicaVersionManager in project hazelcast by hazelcast.

the class OperationBackupHandler method sendBackups0.

int sendBackups0(BackupAwareOperation backupAwareOp) {
    int requestedSyncBackups = requestedSyncBackups(backupAwareOp);
    int requestedAsyncBackups = requestedAsyncBackups(backupAwareOp);
    int requestedTotalBackups = requestedTotalBackups(backupAwareOp);
    if (requestedTotalBackups == 0) {
        return 0;
    }
    Operation op = (Operation) backupAwareOp;
    PartitionReplicaVersionManager versionManager = node.getPartitionService().getPartitionReplicaVersionManager();
    ServiceNamespace namespace = versionManager.getServiceNamespace(op);
    long[] replicaVersions = versionManager.incrementPartitionReplicaVersions(op.getPartitionId(), namespace, requestedTotalBackups);
    boolean syncForced = backpressureRegulator.isSyncForced(backupAwareOp);
    int syncBackups = syncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    int asyncBackups = asyncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    // TODO: This could cause a problem with back pressure
    if (!op.returnsResponse()) {
        asyncBackups += syncBackups;
        syncBackups = 0;
    }
    if (syncBackups + asyncBackups == 0) {
        return 0;
    }
    return makeBackups(backupAwareOp, op.getPartitionId(), replicaVersions, syncBackups, asyncBackups);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 5 with PartitionReplicaVersionManager

use of com.hazelcast.internal.partition.PartitionReplicaVersionManager in project hazelcast by hazelcast.

the class Backup method run.

@Override
public void run() throws Exception {
    if (validationFailure != null) {
        onExecutionFailure(validationFailure);
        return;
    }
    ensureBackupOperationInitialized();
    runDirect(backupOp);
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    PartitionReplicaVersionManager versionManager = nodeEngine.getPartitionService().getPartitionReplicaVersionManager();
    versionManager.updatePartitionReplicaVersions(getPartitionId(), namespace, replicaVersions, getReplicaIndex());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Aggregations

PartitionReplicaVersionManager (com.hazelcast.internal.partition.PartitionReplicaVersionManager)7 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)4 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)1 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)1 ReplicaFragmentMigrationState (com.hazelcast.internal.partition.ReplicaFragmentMigrationState)1 PartitionEventManager (com.hazelcast.internal.partition.impl.PartitionEventManager)1 ILogger (com.hazelcast.logging.ILogger)1 BackupAwareOperation (com.hazelcast.spi.impl.operationservice.BackupAwareOperation)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)1 HashMap (java.util.HashMap)1