Пример #1
0
 protected EntryView getEntryViewInternal(Data key) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation operation = operationProvider.createGetEntryViewOperation(name, key);
   operation.setThreadId(ThreadUtil.getThreadId());
   operation.setServiceName(SERVICE_NAME);
   try {
     Future future = operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
     return (EntryView) toObject(future.get());
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
Пример #2
0
  private Collection<Integer> getPartitionsForKeys(Collection<Data> keys) {
    int partitions = partitionService.getPartitionCount();
    // TODO: is there better way to estimate the size?
    int capacity = min(partitions, keys.size());
    Set<Integer> partitionIds = new HashSet<Integer>(capacity);

    Iterator<Data> iterator = keys.iterator();
    while (iterator.hasNext() && partitionIds.size() < partitions) {
      Data key = iterator.next();
      partitionIds.add(partitionService.getPartitionId(key));
    }
    return partitionIds;
  }
Пример #3
0
 protected boolean containsKeyInternal(Data key) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation containsKeyOperation = operationProvider.createContainsKeyOperation(name, key);
   containsKeyOperation.setThreadId(ThreadUtil.getThreadId());
   containsKeyOperation.setServiceName(SERVICE_NAME);
   try {
     Future future =
         operationService.invokeOnPartition(SERVICE_NAME, containsKeyOperation, partitionId);
     return (Boolean) toObject(future.get());
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
Пример #4
0
 private Data readBackupDataOrNull(Data key) {
   int partitionId = partitionService.getPartitionId(key);
   IPartition partition = partitionService.getPartition(partitionId, false);
   if (!partition.isOwnerOrBackup(thisAddress)) {
     return null;
   }
   PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
   RecordStore recordStore = partitionContainer.getExistingRecordStore(name);
   if (recordStore == null) {
     return null;
   }
   return recordStore.readBackupData(key);
 }
 @Override
 public Collection<Integer> getPartitions() {
   IPartitionService partitionService = nodeEngine.getPartitionService();
   int partitions = partitionService.getPartitionCount();
   int capacity = Math.min(partitions, parameters.keys.size());
   Set<Integer> partitionIds = new HashSet<Integer>(capacity);
   Iterator<Data> iterator = parameters.keys.iterator();
   while (iterator.hasNext() && partitionIds.size() < partitions) {
     Data key = iterator.next();
     partitionIds.add(partitionService.getPartitionId(key));
   }
   return partitionIds;
 }
Пример #6
0
  protected void loadAllInternal(boolean replaceExistingValues) {
    int mapNamePartition = partitionService.getPartitionId(name);

    Operation operation = operationProvider.createLoadMapOperation(name, replaceExistingValues);
    Future loadMapFuture =
        operationService.invokeOnPartition(SERVICE_NAME, operation, mapNamePartition);

    try {
      loadMapFuture.get();
    } catch (Throwable t) {
      throw rethrow(t);
    }

    waitUntilLoaded();
  }
Пример #7
0
 public Data executeOnKeyInternal(Data key, EntryProcessor entryProcessor) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation operation = operationProvider.createEntryOperation(name, key, entryProcessor);
   operation.setThreadId(ThreadUtil.getThreadId());
   try {
     Future future =
         operationService
             .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
             .setResultDeserialized(false)
             .invoke();
     return (Data) future.get();
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
Пример #8
0
  private Map<Integer, List<Data>> getPartitionIdToKeysMap(Iterable<Data> keys) {
    if (keys == null) {
      return Collections.emptyMap();
    }

    Map<Integer, List<Data>> idToKeys = new HashMap<Integer, List<Data>>();
    for (Data key : keys) {
      int partitionId = partitionService.getPartitionId(key);
      List<Data> keyList = idToKeys.get(partitionId);
      if (keyList == null) {
        keyList = new ArrayList<Data>();
        idToKeys.put(partitionId, keyList);
      }
      keyList.add(key);
    }
    return idToKeys;
  }
Пример #9
0
 public ICompletableFuture executeOnKeyInternal(
     Data key, EntryProcessor entryProcessor, ExecutionCallback<Object> callback) {
   int partitionId = partitionService.getPartitionId(key);
   MapOperation operation = operationProvider.createEntryOperation(name, key, entryProcessor);
   operation.setThreadId(ThreadUtil.getThreadId());
   try {
     if (callback == null) {
       return operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
     } else {
       return operationService
           .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
           .setExecutionCallback(new MapExecutionCallbackAdapter(callback))
           .invoke();
     }
   } catch (Throwable t) {
     throw rethrow(t);
   }
 }
Пример #10
0
  protected ICompletableFuture<Data> getAsyncInternal(Data key) {
    int partitionId = partitionService.getPartitionId(key);

    MapOperation operation = operationProvider.createGetOperation(name, key);
    try {
      long startTime = System.currentTimeMillis();
      InternalCompletableFuture<Data> future =
          operationService
              .createInvocationBuilder(SERVICE_NAME, operation, partitionId)
              .setResultDeserialized(false)
              .invoke();

      if (statisticsEnabled) {
        future.andThen(new IncrementStatsExecutionCallback<Data>(operation, startTime));
      }

      return future;
    } catch (Throwable t) {
      throw rethrow(t);
    }
  }
Пример #11
0
  public void waitUntilLoaded() {
    try {
      int mapNamePartition = partitionService.getPartitionId(name);
      Operation op = new PartitionCheckIfLoadedOperation(name, false, true);
      Future loadingFuture = operationService.invokeOnPartition(SERVICE_NAME, op, mapNamePartition);
      // wait for keys to be loaded - it's insignificant since it doesn't trigger the keys loading
      // it's just waiting for them to be loaded. Timeout failure doesn't mean anything negative
      // here.
      // This call just introduces some ordering of requests.
      FutureUtil.waitWithDeadline(
          singleton(loadingFuture),
          CHECK_IF_LOADED_TIMEOUT_SECONDS,
          SECONDS,
          logAllExceptions(WARNING));

      OperationFactory opFactory = new PartitionCheckIfLoadedOperationFactory(name);
      Map<Integer, Object> results =
          operationService.invokeOnAllPartitions(SERVICE_NAME, opFactory);
      // wait for all the data to be loaded on all partitions - wait forever
      waitAllTrue(results, opFactory);
    } catch (Throwable t) {
      throw rethrow(t);
    }
  }
Пример #12
0
  /**
   * This method will group all puts per partition and send a {@link
   * com.hazelcast.map.impl.operation.PutAllPartitionAwareOperationFactory} per member.
   *
   * <p>If there are e.g. five keys for a single member, there will only be a single remote
   * invocation instead of having five remote invocations.
   *
   * <p>There is also an optional support for batching to send smaller packages. Takes care about
   * {@code null} checks for keys and values.
   */
  @SuppressWarnings({"checkstyle:npathcomplexity", "UnnecessaryBoxing"})
  @SuppressFBWarnings(
      value = "DM_NUMBER_CTOR",
      justification = "we need a shared counter object for each member per partition")
  protected void putAllInternal(Map<?, ?> map) {
    try {
      int mapSize = map.size();
      if (mapSize == 0) {
        return;
      }

      boolean useBatching = isPutAllUseBatching(mapSize);
      int partitionCount = partitionService.getPartitionCount();
      int initialSize = getPutAllInitialSize(useBatching, mapSize, partitionCount);

      Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();

      // init counters for batching
      MutableLong[] counterPerMember = null;
      Address[] addresses = null;
      if (useBatching) {
        counterPerMember = new MutableLong[partitionCount];
        addresses = new Address[partitionCount];
        for (Entry<Address, List<Integer>> addressListEntry : memberPartitionsMap.entrySet()) {
          MutableLong counter = new MutableLong();
          Address address = addressListEntry.getKey();
          for (int partitionId : addressListEntry.getValue()) {
            counterPerMember[partitionId] = counter;
            addresses[partitionId] = address;
          }
        }
      }

      // fill entriesPerPartition
      MapEntries[] entriesPerPartition = new MapEntries[partitionCount];
      for (Entry entry : map.entrySet()) {
        checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
        checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);

        Data keyData = toData(entry.getKey(), partitionStrategy);
        int partitionId = partitionService.getPartitionId(keyData);
        MapEntries entries = entriesPerPartition[partitionId];
        if (entries == null) {
          entries = new MapEntries(initialSize);
          entriesPerPartition[partitionId] = entries;
        }

        entries.add(keyData, toData(entry.getValue()));

        if (useBatching) {
          long currentSize = ++counterPerMember[partitionId].value;
          if (currentSize % putAllBatchSize == 0) {
            List<Integer> partitions = memberPartitionsMap.get(addresses[partitionId]);
            invokePutAllOperation(addresses[partitionId], partitions, entriesPerPartition);
          }
        }
      }

      // invoke operations for entriesPerPartition
      for (Entry<Address, List<Integer>> entry : memberPartitionsMap.entrySet()) {
        invokePutAllOperation(entry.getKey(), entry.getValue(), entriesPerPartition);
      }
    } catch (Exception e) {
      throw rethrow(e);
    }
  }