use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.
the class MapBackupAccessor method getRecord.
public Record getRecord(K key) {
IPartition partition = getPartitionForKey(key);
HazelcastInstance hz = getHazelcastInstance(partition);
Node node = getNode(hz);
SerializationService serializationService = node.getSerializationService();
MapService mapService = node.getNodeEngine().getService(MapService.SERVICE_NAME);
MapServiceContext context = mapService.getMapServiceContext();
int partitionId = partition.getPartitionId();
PartitionContainer partitionContainer = context.getPartitionContainer(partitionId);
return runOnPartitionThread(hz, new GetRecordCallable(serializationService, partitionContainer, key), partitionId);
}
use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.
the class WanPublisherMigrationTest method testMigration.
@Test
public void testMigration() {
HazelcastInstance[] instances = factory.newInstances(getConfig());
HazelcastInstance member1 = instances[0];
HazelcastInstance member2 = instances[1];
IMap<Object, Object> map = member1.getMap("dummyMap");
for (int i = 0; i < 100; i++) {
map.put(i, i);
}
int partitionsToMigrate = 0;
for (IPartition partition : getPartitionService(member1).getPartitions()) {
if (partition.isLocal()) {
partitionsToMigrate++;
}
}
member1.shutdown();
assertClusterSizeEventually(1, member2);
MigrationCountingWanPublisher publisher = getPublisher(member2);
if (!failMigrations) {
assertEquals(exceptionMsg("migrationStart", publisher), partitionsToMigrate, publisher.migrationStart.intValue());
// it may happen that we have additional partition anti-entropy operations
// that call process but don't show up as migration operations
assertTrue("Expected at least " + partitionsToMigrate + " migration operations to be processed but was " + publisher, publisher.migrationProcess.intValue() >= partitionsToMigrate);
assertEquals(exceptionMsg("migrationCommit", publisher), partitionsToMigrate, publisher.migrationCommit.intValue());
} else {
assertEquals(exceptionMsg("migrationStart", publisher), partitionsToMigrate + 1, publisher.migrationStart.intValue());
// it may happen that we have additional partition anti-entropy operations
// that call process but don't show up as migration operations
assertTrue("Expected at least " + partitionsToMigrate + " migration operations to be processed but was " + publisher, publisher.migrationProcess.intValue() >= partitionsToMigrate);
assertEquals(exceptionMsg("migrationCommit", publisher), partitionsToMigrate, publisher.migrationCommit.intValue());
assertEquals(exceptionMsg("migrationRollback", publisher), 1, publisher.migrationRollback.intValue());
}
}
use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.
the class DefaultRecordStore method isBackup.
private boolean isBackup(RecordStore recordStore) {
int partitionId = recordStore.getPartitionId();
IPartition partition = partitionService.getPartition(partitionId, false);
return !partition.isLocal();
}
use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.
the class MapKeyLoader method calculateRole.
/**
* Calculates and returns the role for the map key loader on this partition
*/
private Role calculateRole() {
boolean isPartitionOwner = partitionService.isPartitionOwner(partitionId);
boolean isMapNamePartition = partitionId == mapNamePartition;
boolean isMapNamePartitionFirstReplica = false;
if (hasBackup && isMapNamePartition) {
IPartition partition = partitionService.getPartition(partitionId);
Address firstReplicaAddress = partition.getReplicaAddress(1);
Member member = clusterService.getMember(firstReplicaAddress);
if (member != null) {
isMapNamePartitionFirstReplica = member.localMember();
}
}
return assignRole(isPartitionOwner, isMapNamePartition, isMapNamePartitionFirstReplica);
}
use of com.hazelcast.internal.partition.IPartition in project hazelcast by hazelcast.
the class LocalMapStatsProvider method addIndexStats.
private void addIndexStats(String mapName, LocalMapStatsImpl localMapStats) {
MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
Indexes globalIndexes = mapContainer.getIndexes();
Map<String, OnDemandIndexStats> freshStats = null;
if (globalIndexes != null) {
assert globalIndexes.isGlobal();
localMapStats.setQueryCount(globalIndexes.getIndexesStats().getQueryCount());
localMapStats.setIndexedQueryCount(globalIndexes.getIndexesStats().getIndexedQueryCount());
freshStats = aggregateFreshIndexStats(globalIndexes.getIndexes(), null);
finalizeFreshIndexStats(freshStats);
} else {
long queryCount = 0;
long indexedQueryCount = 0;
PartitionContainer[] partitionContainers = mapServiceContext.getPartitionContainers();
for (PartitionContainer partitionContainer : partitionContainers) {
IPartition partition = partitionService.getPartition(partitionContainer.getPartitionId());
if (!partition.isLocal()) {
continue;
}
Indexes partitionIndexes = partitionContainer.getIndexes().get(mapName);
if (partitionIndexes == null) {
continue;
}
assert !partitionIndexes.isGlobal();
IndexesStats indexesStats = partitionIndexes.getIndexesStats();
// Partitions may have different query stats due to migrations
// (partition stats is not preserved while migrating) and/or
// partition-specific queries, map query stats is estimated as a
// maximum among partitions.
queryCount = Math.max(queryCount, indexesStats.getQueryCount());
indexedQueryCount = Math.max(indexedQueryCount, indexesStats.getIndexedQueryCount());
freshStats = aggregateFreshIndexStats(partitionIndexes.getIndexes(), freshStats);
}
localMapStats.setQueryCount(queryCount);
localMapStats.setIndexedQueryCount(indexedQueryCount);
finalizeFreshIndexStats(freshStats);
}
localMapStats.updateIndexStats(freshStats);
}
Aggregations