use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class QueryResult method combine.
@Override
public void combine(QueryResult result) {
PartitionIdSet otherPartitionIds = result.getPartitionIds();
if (otherPartitionIds == null) {
return;
}
if (partitionIds == null) {
partitionIds = new PartitionIdSet(otherPartitionIds);
} else {
partitionIds.addAll(otherPartitionIds);
}
rows.addAll(result.rows);
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class QueryRunner method runIndexQueryOnOwnedPartitions.
/**
* Performs the given query using indexes.
* <p>
* The method may return a special failure result, which has {@code null}
* {@link Result#getPartitionIds() partition IDs}, in the following
* situations:
* <ul>
* <li>If a partition migration is detected during the query execution.
* <li>If it's impossible to perform the given query using indexes.
* </ul>
* <p>
* The method may be invoked on any thread.
*
* @param query the query to perform.
* @return the result of the query; if the result has {@code null} {@link
* Result#getPartitionIds() partition IDs} this indicates a failure.
*/
public Result runIndexQueryOnOwnedPartitions(Query query) {
int migrationStamp = getMigrationStamp();
PartitionIdSet initialPartitions = mapServiceContext.getOrInitCachedMemberPartitions();
MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
// to optimize the query we need to get any index instance
Indexes indexes = mapContainer.getIndexes();
if (indexes == null) {
indexes = mapContainer.getIndexes(initialPartitions.iterator().next());
}
// first we optimize the query
Predicate predicate = queryOptimizer.optimize(query.getPredicate(), indexes);
// then we try to run using an index
Iterable<QueryableEntry> entries = runUsingGlobalIndexSafely(predicate, mapContainer, migrationStamp, initialPartitions.size());
Result result;
if (entries == null) {
// failed with index query because of ongoing migrations
result = populateEmptyResult(query, initialPartitions);
} else {
// success
result = populateNonEmptyResult(query, entries, initialPartitions);
}
return result;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class GlobalIndexPartitionTracker method clear.
public void clear() {
lock.lock();
try {
State oldState = state.get();
State newState = new State(oldState.stamp + 1, new PartitionIdSet(partitionCount), 0);
state.set(newState);
} finally {
lock.unlock();
}
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class MapTableUtils method estimatePartitionedMapRowCount.
public static long estimatePartitionedMapRowCount(NodeEngine nodeEngine, MapServiceContext context, String mapName) {
long entryCount = 0L;
PartitionIdSet ownerPartitions = context.getOrInitCachedMemberPartitions();
for (PartitionContainer partitionContainer : context.getPartitionContainers()) {
if (!ownerPartitions.contains(partitionContainer.getPartitionId())) {
continue;
}
RecordStore<?> recordStore = partitionContainer.getExistingRecordStore(mapName);
if (recordStore == null) {
continue;
}
entryCount += recordStore.size();
}
int memberCount = nodeEngine.getClusterService().getMembers(MemberSelectors.DATA_MEMBER_SELECTOR).size();
return entryCount * memberCount;
}
use of com.hazelcast.internal.util.collection.PartitionIdSet in project hazelcast by hazelcast.
the class SerializationUtil method readNullablePartitionIdSet.
public static PartitionIdSet readNullablePartitionIdSet(ObjectDataInput in) throws IOException {
int partitionCount = in.readInt();
if (partitionCount == -1) {
return null;
}
PartitionIdSet result = new PartitionIdSet(partitionCount);
int setSize = in.readInt();
for (int i = 0; i < setSize; i++) {
result.add(in.readInt());
}
return result;
}
Aggregations