Search in sources :

Example 36 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MigrationRequestOperation method run.

@Override
public void run() {
    NodeEngine nodeEngine = getNodeEngine();
    verifyGoodMaster(nodeEngine);
    Address source = migrationInfo.getSource();
    Address destination = migrationInfo.getDestination();
    verifyExistingTarget(nodeEngine, destination);
    if (destination.equals(source)) {
        getLogger().warning("Source and destination addresses are the same! => " + toString());
        setFailed();
        return;
    }
    InternalPartition partition = getPartition();
    verifySource(nodeEngine.getThisAddress(), partition);
    setActiveMigration();
    if (!migrationInfo.startProcessing()) {
        getLogger().warning("Migration is cancelled -> " + migrationInfo);
        setFailed();
        return;
    }
    try {
        executeBeforeMigrations();
        Collection<Operation> tasks = prepareMigrationOperations();
        InternalPartitionServiceImpl partitionService = getService();
        long[] replicaVersions = partitionService.getPartitionReplicaVersions(migrationInfo.getPartitionId());
        invokeMigrationOperation(destination, replicaVersions, tasks);
        returnResponse = false;
    } catch (Throwable e) {
        logThrowable(e);
        setFailed();
    } finally {
        migrationInfo.doneProcessing();
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartition(com.hazelcast.internal.partition.InternalPartition) Operation(com.hazelcast.spi.Operation)

Example 37 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class MapSplitBrainHandlerService method prepareMergeRunnable.

@Override
public Runnable prepareMergeRunnable() {
    final long now = getNow();
    final Map<String, MapContainer> mapContainers = getMapContainers();
    final Map<MapContainer, Collection<Record>> recordMap = new HashMap<MapContainer, Collection<Record>>(mapContainers.size());
    final IPartitionService partitionService = nodeEngine.getPartitionService();
    final int partitionCount = partitionService.getPartitionCount();
    final Address thisAddress = nodeEngine.getClusterService().getThisAddress();
    for (MapContainer mapContainer : mapContainers.values()) {
        for (int i = 0; i < partitionCount; i++) {
            RecordStore recordStore = mapServiceContext.getPartitionContainer(i).getRecordStore(mapContainer.getName());
            // add your owned entries to the map so they will be merged
            if (thisAddress.equals(partitionService.getPartitionOwner(i))) {
                Collection<Record> records = recordMap.get(mapContainer);
                if (records == null) {
                    records = new ArrayList<Record>();
                    recordMap.put(mapContainer, records);
                }
                final Iterator<Record> iterator = recordStore.iterator(now, false);
                while (iterator.hasNext()) {
                    final Record record = iterator.next();
                    records.add(record);
                }
            }
            // clear all records either owned or backup
            recordStore.reset();
        }
        Indexes indexes = mapContainer.getIndexes();
        indexes.clearIndexes();
    }
    return new Merger(recordMap);
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Indexes(com.hazelcast.query.impl.Indexes) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Collection(java.util.Collection) Record(com.hazelcast.map.impl.record.Record)

Example 38 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class PartitionTableViewTest method testEquals_whenSingleAddressIsDifferent.

@Test
public void testEquals_whenSingleAddressIsDifferent() throws Exception {
    PartitionTableView table1 = createRandomPartitionTable();
    Address[][] addresses = extractPartitionTableAddresses(table1);
    Address address = addresses[addresses.length - 1][MAX_REPLICA_COUNT - 1];
    addresses[addresses.length - 1][MAX_REPLICA_COUNT - 1] = new Address(address.getInetAddress(), address.getPort() + 1);
    PartitionTableView table2 = new PartitionTableView(addresses, table1.getVersion());
    assertNotEquals(table1, table2);
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 39 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class FrozenPartitionTableTest method getPartitionTable.

private Map<Integer, List<Address>> getPartitionTable(final HazelcastInstance instance) {
    final InternalPartitionServiceImpl partitionService = getNode(instance).partitionService;
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    final Map<Integer, List<Address>> partitionTable = new HashMap<Integer, List<Address>>();
    for (int partitionId = 0; partitionId < partitionService.getPartitionCount(); partitionId++) {
        final InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
        for (int replicaIndex = 0; replicaIndex < InternalPartitionImpl.MAX_REPLICA_COUNT; replicaIndex++) {
            Address replicaAddress = partition.getReplicaAddress(replicaIndex);
            if (replicaAddress == null) {
                break;
            }
            List<Address> replicaAddresses = partitionTable.get(partitionId);
            if (replicaAddresses == null) {
                replicaAddresses = new ArrayList<Address>();
                partitionTable.put(partitionId, replicaAddresses);
            }
            replicaAddresses.add(replicaAddress);
        }
    }
    return partitionTable;
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class FrozenPartitionTableTest method partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIsFrozen.

@Test
public void partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIsFrozen() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
    HazelcastInstance[] instances = factory.newInstances(config, 3);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    Address hz3Address = getNode(hz3).getThisAddress();
    warmUpPartitions(instances);
    final Map<Integer, List<Address>> partitionTable = getPartitionTable(hz1);
    changeClusterStateEventually(hz2, ClusterState.FROZEN);
    terminateInstance(hz3);
    hz3 = factory.newHazelcastInstance(hz3Address);
    assertClusterSizeEventually(3, hz1);
    assertClusterSizeEventually(3, hz2);
    assertClusterSizeEventually(3, hz3);
    for (HazelcastInstance instance : Arrays.asList(hz1, hz2, hz3)) {
        final HazelcastInstance hz = instance;
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertPartitionTablesSame(partitionTable, getPartitionTable(hz));
            }
        });
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) List(java.util.List) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13