use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class ChunkSerDeHelper method writeChunkedOperations.
public void writeChunkedOperations(ObjectDataOutput out) throws IOException {
IsEndOfChunk isEndOfChunk = new IsEndOfChunk(out, maxTotalChunkedDataInBytes);
for (ChunkSupplier chunkSupplier : chunkSuppliers) {
chunkSupplier.signalEndOfChunkWith(isEndOfChunk);
while (chunkSupplier.hasNext()) {
Operation chunk = chunkSupplier.next();
// migration operation as if it is a single chunk.
if (chunk == null) {
break;
}
logCurrentChunk(chunkSupplier);
out.writeObject(chunk);
if (isEndOfChunk.getAsBoolean()) {
break;
}
}
if (isEndOfChunk.getAsBoolean()) {
logEndOfChunk(isEndOfChunk);
break;
}
}
// indicates end of chunked state
out.writeObject(null);
logEndOfAllChunks(isEndOfChunk);
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class ChunkSerDeHelper method readChunkedOperations.
public static Collection<Operation> readChunkedOperations(ObjectDataInput in, Collection<Operation> operations) throws IOException {
do {
Operation operation = in.readObject();
if (operation == null) {
break;
}
if (isEmpty(operations)) {
operations = new LinkedList<>();
}
operations.add(operation);
} while (true);
return operations;
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class MapKeyLoader method triggerLoading.
/**
* Triggers key loading if needed on the map key loader with the
* {@link Role#SENDER} or {@link Role#SENDER_BACKUP} role if this
* partition does not have any ongoing key loading task.
*
* @return a future representing pending completion of the key loading task
*/
private Future triggerLoading() {
if (keyLoadFinished.isDone()) {
keyLoadFinished = new LoadFinishedFuture();
// side effect -> just trigger load on SENDER_BACKUP ID SENDER died
execService.execute(MAP_LOAD_ALL_KEYS_EXECUTOR, () -> {
// checks if loading has finished and triggers loading in case SENDER died and SENDER_BACKUP took over.
Operation op = new TriggerLoadIfNeededOperation(mapName);
opService.<Boolean>invokeOnPartition(SERVICE_NAME, op, mapNamePartition).whenCompleteAsync(loadingFinishedCallback());
});
}
return keyLoadFinished;
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class MapKeyLoader method sendKeyLoadCompleted.
/**
* Notifies the record stores of the {@link MapKeyLoader.Role#SENDER},
* {@link MapKeyLoader.Role#SENDER_BACKUP} and all other partition record
* stores that the key loading has finished and the keys have been dispatched
* to the partition owners for value loading.
*
* @param clusterSize the size of the cluster
* @param exception the exception that occurred during key loading or
* {@code null} if there was no exception
* @throws Exception if there was an exception when notifying the record stores that the key
* loading has finished
* @see com.hazelcast.map.impl.recordstore.RecordStore#updateLoadStatus(boolean, Throwable)
*/
private void sendKeyLoadCompleted(int clusterSize, Throwable exception) throws Exception {
// Notify SENDER first - reason why this is so important:
// Someone may do map.get(other_nodes_key) and when it finishes do map.loadAll
// The problem is that map.get may finish earlier than then overall loading on the SENDER due to the fact
// that the LoadStatusOperation may first reach the node that did map.get and not the SENDER.
// The SENDER will be then in the LOADING status, thus the loadAll call will be ignored.
// it happens only if all LoadAllOperation finish before the sendKeyLoadCompleted is started (test case, little data)
// Fixes https://github.com/hazelcast/hazelcast/issues/5453
List<Future> futures = new ArrayList<>();
Operation senderStatus = new KeyLoadStatusOperation(mapName, exception);
Future senderFuture = opService.createInvocationBuilder(SERVICE_NAME, senderStatus, mapNamePartition).setReplicaIndex(0).invoke();
futures.add(senderFuture);
// notify SENDER_BACKUP
if (hasBackup && clusterSize > 1) {
Operation senderBackupStatus = new KeyLoadStatusOperation(mapName, exception);
Future senderBackupFuture = opService.createInvocationBuilder(SERVICE_NAME, senderBackupStatus, mapNamePartition).setReplicaIndex(1).invoke();
futures.add(senderBackupFuture);
}
// Blocks until finished on SENDER & SENDER_BACKUP PARTITIONS
// We need to wait for these operation to finished before the map-key-loader returns from the call
// otherwise the loading won't be finished on SENDER and SENDER_BACKUP but the user may be able to call loadAll which
// will be ignored since the SENDER and SENDER_BACKUP are still loading.
FutureUtil.waitForever(futures);
// INVOKES AND BLOCKS UNTIL FINISHED on ALL PARTITIONS (SENDER AND SENDER BACKUP WILL BE REPEATED)
// notify all partitions about loading status: finished or exception encountered
opService.invokeOnAllPartitions(SERVICE_NAME, new KeyLoadStatusOperationFactory(mapName, exception));
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class MapMigrationAwareService method prepareReplicationOperation.
@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event, Collection<ServiceNamespace> namespaces) {
assert assertAllKnownNamespaces(namespaces);
int partitionId = event.getPartitionId();
Operation operation = new MapReplicationOperation(containers[partitionId], namespaces, partitionId, event.getReplicaIndex());
operation.setService(mapServiceContext.getService());
operation.setNodeEngine(mapServiceContext.getNodeEngine());
return operation;
}
Aggregations