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);
}
}
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();
}
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;
}
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);
}
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());
}
Aggregations