Search in sources :

Example 46 with Operation

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);
}
Also used : Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 47 with Operation

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;
}
Also used : Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 48 with Operation

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;
}
Also used : KeyLoadStatusOperation(com.hazelcast.map.impl.operation.KeyLoadStatusOperation) TriggerLoadIfNeededOperation(com.hazelcast.map.impl.operation.TriggerLoadIfNeededOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) TriggerLoadIfNeededOperation(com.hazelcast.map.impl.operation.TriggerLoadIfNeededOperation)

Example 49 with Operation

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));
}
Also used : ArrayList(java.util.ArrayList) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) KeyLoadStatusOperation(com.hazelcast.map.impl.operation.KeyLoadStatusOperation) KeyLoadStatusOperation(com.hazelcast.map.impl.operation.KeyLoadStatusOperation) TriggerLoadIfNeededOperation(com.hazelcast.map.impl.operation.TriggerLoadIfNeededOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) KeyLoadStatusOperationFactory(com.hazelcast.map.impl.operation.KeyLoadStatusOperationFactory)

Example 50 with Operation

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;
}
Also used : MapReplicationOperation(com.hazelcast.map.impl.operation.MapReplicationOperation) MapReplicationOperation(com.hazelcast.map.impl.operation.MapReplicationOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint)

Aggregations

Operation (com.hazelcast.spi.impl.operationservice.Operation)271 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)79 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)56 Address (com.hazelcast.cluster.Address)31 HazelcastInstance (com.hazelcast.core.HazelcastInstance)25 Data (com.hazelcast.internal.serialization.Data)24 Future (java.util.concurrent.Future)24 Member (com.hazelcast.cluster.Member)22 ArrayList (java.util.ArrayList)21 NodeEngine (com.hazelcast.spi.impl.NodeEngine)18 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)17 AssertTask (com.hazelcast.test.AssertTask)15 ILogger (com.hazelcast.logging.ILogger)14 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Config (com.hazelcast.config.Config)12 CompletableFuture (java.util.concurrent.CompletableFuture)12