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