示例#1
0
  @Override
  public void run() throws Exception {
    if (!valid) {
      onExecutionFailure(
          new IllegalStateException("Wrong target! " + toString() + " cannot be processed!"));
      return;
    }

    NodeEngine nodeEngine = getNodeEngine();

    if (backupOp == null && backupOpData != null) {
      backupOp = nodeEngine.getSerializationService().toObject(backupOpData);
    }

    if (backupOp != null) {
      ensureBackupOperationInitialized();

      backupOp.beforeRun();
      backupOp.run();
      backupOp.afterRun();
    }

    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    partitionService.updatePartitionReplicaVersions(
        getPartitionId(), replicaVersions, getReplicaIndex());
  }
  private int makeBackups(
      BackupAwareOperation backupAwareOp,
      int partitionId,
      long[] replicaVersions,
      int syncBackups,
      int asyncBackups) {
    int sendSyncBackups = 0;

    InternalPartitionService partitionService = node.getPartitionService();
    InternalPartition partition = partitionService.getPartition(partitionId);

    Data backupOpData = getBackupOperationData(backupAwareOp);

    for (int replicaIndex = 1; replicaIndex <= syncBackups + asyncBackups; replicaIndex++) {
      Address target = partition.getReplicaAddress(replicaIndex);

      if (target == null) {
        continue;
      }

      assertNoBackupOnPrimaryMember(partition, target);

      boolean isSyncBackup = replicaIndex <= syncBackups;

      Backup backup =
          newBackup(backupAwareOp, backupOpData, replicaVersions, replicaIndex, isSyncBackup);
      operationService.send(backup, target);

      if (isSyncBackup) {
        sendSyncBackups++;
      }
    }

    return sendSyncBackups;
  }
示例#3
0
  public Runnable prepareMergeRunnable() {
    Map<MapContainer, Collection<Record>> recordMap =
        new HashMap<MapContainer, Collection<Record>>(mapContainers.size());
    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    Address thisAddress = nodeEngine.getClusterService().getThisAddress();

    for (MapContainer mapContainer : mapContainers.values()) {
      for (int i = 0; i < partitionCount; i++) {
        RecordStore recordStore = 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);
          }
          records.addAll(recordStore.getReadonlyRecordMap().values());
        }
        // clear all records either owned or backup
        recordStore.reset();
      }
    }
    return new Merger(recordMap);
  }
  public int backup(BackupAwareOperation backupAwareOp) throws Exception {
    int requestedSyncBackups = requestedSyncBackups(backupAwareOp);
    int requestedAsyncBackups = requestedAsyncBackups(backupAwareOp);
    int requestedTotalBackups = requestedTotalBackups(backupAwareOp);
    if (requestedTotalBackups == 0) {
      return 0;
    }

    Operation op = (Operation) backupAwareOp;
    InternalPartitionService partitionService = node.getPartitionService();
    long[] replicaVersions =
        partitionService.incrementPartitionReplicaVersions(
            op.getPartitionId(), requestedTotalBackups);

    boolean syncForced = backpressureRegulator.isSyncForced(backupAwareOp);

    int syncBackups = syncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);
    int asyncBackups = asyncBackups(requestedSyncBackups, requestedAsyncBackups, syncForced);

    // TODO: This could cause a problem with back pressure
    if (!op.returnsResponse()) {
      asyncBackups += syncBackups;
      syncBackups = 0;
    }

    if (syncBackups + asyncBackups == 0) {
      return 0;
    }

    return makeBackups(
        backupAwareOp, op.getPartitionId(), replicaVersions, syncBackups, asyncBackups);
  }
  int syncBackups(int requestedSyncBackups, int requestedAsyncBackups, boolean syncForced) {
    if (syncForced) {
      // if force sync enabled, then the sum of the backups
      requestedSyncBackups += requestedAsyncBackups;
    }

    InternalPartitionService partitionService = node.getPartitionService();
    int maxBackupCount = partitionService.getMaxBackupCount();
    return min(maxBackupCount, requestedSyncBackups);
  }
  int asyncBackups(int requestedSyncBackups, int requestedAsyncBackups, boolean syncForced) {
    if (syncForced || requestedAsyncBackups == 0) {
      // if syncForced, then there will never be any async backups (they are forced to become sync)
      // if there are no asyncBackups then we are also done.
      return 0;
    }

    InternalPartitionService partitionService = node.getPartitionService();
    int maxBackupCount = partitionService.getMaxBackupCount();
    return min(maxBackupCount - requestedSyncBackups, requestedAsyncBackups);
  }
示例#7
0
 private void clearRemoteTransactions(Xid xid) {
   NodeEngine nodeEngine = getNodeEngine();
   InternalPartitionService partitionService = nodeEngine.getPartitionService();
   OperationService operationService = nodeEngine.getOperationService();
   SerializableXID serializableXID =
       new SerializableXID(
           xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
   Data xidData = nodeEngine.toData(serializableXID);
   int partitionId = partitionService.getPartitionId(xidData);
   ClearRemoteTransactionOperation operation = new ClearRemoteTransactionOperation(xidData);
   operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
 }
示例#8
0
 private List<Object>[] buildMapping(InternalPartitionService partitionService) {
   List<Object>[] mapping = new List[partitionService.getPartitionCount()];
   for (Object key : keys) {
     int pid = partitionService.getPartitionId(key);
     List<Object> list = mapping[pid];
     if (list == null) {
       list = new ArrayList<Object>();
       mapping[pid] = list;
     }
     list.add(key);
   }
   return mapping;
 }
示例#9
0
 @Override
 public void run() {
   final long now = Clock.currentTimeMillis();
   final String mapName = this.mapName;
   final MapServiceContext mapServiceContext = this.mapServiceContext;
   final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
   final ClusterService clusterService = nodeEngine.getClusterService();
   final InternalPartitionService partitionService = nodeEngine.getPartitionService();
   final Address thisAddress = clusterService.getThisAddress();
   final int partitionCount = partitionService.getPartitionCount();
   Map<Integer, Integer> partitionToEntryCountHolder = Collections.emptyMap();
   List<DelayedEntry> entries = Collections.emptyList();
   boolean createLazy = true;
   for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
     final InternalPartition partition = partitionService.getPartition(partitionId, false);
     final Address owner = partition.getOwnerOrNull();
     final RecordStore recordStore = getRecordStoreOrNull(mapName, partitionId);
     if (owner == null || recordStore == null) {
       // no-op because no owner is set yet.
       // Therefore we don't know anything about the map
       continue;
     }
     final WriteBehindQueue<DelayedEntry> queue = getWriteBehindQueue(recordStore);
     final List<DelayedEntry> delayedEntries = filterItemsLessThanOrEqualToTime(queue, now);
     if (delayedEntries.isEmpty()) {
       continue;
     }
     if (!owner.equals(thisAddress)) {
       if (now > lastRunTime + backupRunIntervalTime) {
         doInBackup(queue, delayedEntries, partitionId);
       }
       continue;
     }
     // initialize when needed, we do not want
     // to create these on backups for every second.
     if (createLazy) {
       partitionToEntryCountHolder = new HashMap<Integer, Integer>();
       entries = new ArrayList<DelayedEntry>();
       createLazy = false;
     }
     partitionToEntryCountHolder.put(partitionId, delayedEntries.size());
     entries.addAll(delayedEntries);
   }
   if (!entries.isEmpty()) {
     final Map<Integer, List<DelayedEntry>> failsPerPartition =
         writeBehindProcessor.process(entries);
     removeProcessed(mapName, getEntryPerPartitionMap(entries));
     addFailsToQueue(mapName, failsPerPartition);
     lastRunTime = now;
   }
 }
  @Override
  public Collection<Integer> getPartitions() {
    InternalPartitionService partitionService = getClientEngine().getPartitionService();
    int partitions = partitionService.getPartitionCount();
    int capacity = Math.min(partitions, keys.size()); // todo: is there better way to estimate 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;
  }
示例#11
0
 @Override
 public boolean open(NodeEngine nodeEngine) {
   NodeEngineImpl nei = (NodeEngineImpl) nodeEngine;
   InternalPartitionService ps = nei.getPartitionService();
   MapService mapService = nei.getService(MapService.SERVICE_NAME);
   ss = nei.getSerializationService();
   Address partitionOwner = ps.getPartitionOwner(partitionId);
   if (partitionOwner == null) {
     return false;
   }
   RecordStore recordStore =
       mapService.getMapServiceContext().getRecordStore(partitionId, mapName);
   iterator = recordStore.entrySetData().iterator();
   return true;
 }
示例#12
0
 /**
  * @param queue write behind queue.
  * @param delayedEntries entries to be processed.
  * @param partitionId corresponding partition id.
  */
 private void doInBackup(
     final WriteBehindQueue queue,
     final List<DelayedEntry> delayedEntries,
     final int partitionId) {
   final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
   final ClusterService clusterService = nodeEngine.getClusterService();
   final InternalPartitionService partitionService = nodeEngine.getPartitionService();
   final Address thisAddress = clusterService.getThisAddress();
   final InternalPartition partition = partitionService.getPartition(partitionId, false);
   final Address owner = partition.getOwnerOrNull();
   if (owner != null && !owner.equals(thisAddress)) {
     writeBehindProcessor.callBeforeStoreListeners(delayedEntries);
     removeProcessed(mapName, getEntryPerPartitionMap(delayedEntries));
     writeBehindProcessor.callAfterStoreListeners(delayedEntries);
   }
 }
  /**
   * Initializes all mocks needed to execute a query operation.
   *
   * @param nodeResultLimit configures the result size limit, use <code>Long.MAX_VALUE</code> to
   *     disable feature
   * @param numberOfReturnedQueryEntries configures the number of returned entries of the query
   *     operation
   */
  protected void initMocks(long nodeResultLimit, int numberOfReturnedQueryEntries) {
    for (int i = 0; i < numberOfReturnedQueryEntries; i++) {
      QueryableEntry queryableEntry = mock(QueryableEntry.class);
      when(queryableEntry.getKeyData()).thenAnswer(randomDataAnswer);
      when(queryableEntry.getIndexKey()).thenAnswer(randomDataAnswer);
      when(queryableEntry.getValueData()).thenAnswer(randomDataAnswer);

      queryEntries.add(queryableEntry);
      queryEntrySet.add(queryableEntry);
    }

    QueryResult queryResult = new QueryResult(nodeResultLimit);

    when(mapContextQuerySupport.newQueryResult(anyInt())).thenReturn(queryResult);
    when(mapContextQuerySupport.queryOnPartition(
            MAP_NAME, TruePredicate.INSTANCE, Operation.GENERIC_PARTITION_ID))
        .thenReturn(queryEntries);

    IndexService indexService = mock(IndexService.class);
    when(indexService.query(TruePredicate.INSTANCE)).thenReturn(queryEntrySet);

    MapConfig mapConfig = mock(MapConfig.class);
    when(mapConfig.isStatisticsEnabled()).thenReturn(false);

    MapServiceContext mapServiceContext = mock(MapServiceContext.class);
    when(mapServiceContext.getMapContextQuerySupport()).thenReturn(mapContextQuerySupport);

    MapService mapService = mock(MapService.class);
    when(mapService.getMapServiceContext()).thenReturn(mapServiceContext);

    queryOperation.mapService = mapService;

    MapContainer mapContainer = mock(MapContainer.class);
    when(mapContainer.getIndexService()).thenReturn(indexService);
    when(mapContainer.getMapConfig()).thenReturn(mapConfig);

    queryOperation.mapContainer = mapContainer;

    InternalPartitionService partitionService = mock(InternalPartitionService.class);
    when(partitionService.getPartitionStateVersion()).thenReturn(0);
    when(partitionService.hasOnGoingMigrationLocal()).thenReturn(false);

    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getPartitionService()).thenReturn(partitionService);

    queryOperation.setNodeEngine(nodeEngine);
  }
  @Test(expected = IllegalStateException.class)
  public void test_lockClusterState_forFrozenState_whenHasOnGoingMigration() throws Exception {
    when(partitionService.hasOnGoingMigrationLocal()).thenReturn(true);

    Address initiator = newAddress();
    final ClusterState newState = FROZEN;
    clusterStateManager.lockClusterState(newState, initiator, TXN, 1000, 0);
  }
  @Override
  public void process(
      EntryTaskScheduler<String, Void> scheduler,
      Collection<ScheduledEntry<String, Void>> entries) {
    if (entries.isEmpty()) {
      return;
    }

    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    OperationService operationService = nodeEngine.getOperationService();

    for (ScheduledEntry<String, Void> entry : entries) {
      String name = entry.getKey();
      int partitionId = partitionService.getPartitionId(nodeEngine.toData(name));
      CheckAndEvictOperation op = new CheckAndEvictOperation(entry.getKey());
      operationService.invokeOnPartition(QueueService.SERVICE_NAME, op, partitionId).getSafely();
    }
  }
示例#16
0
 public void run() {
   backupRecordInfos = new ArrayList<RecordInfo>();
   backupEntrySet = new ArrayList<Map.Entry<Data, Data>>();
   int partitionId = getPartitionId();
   final MapServiceContext mapServiceContext = mapService.getMapServiceContext();
   RecordStore recordStore = mapServiceContext.getRecordStore(partitionId, name);
   Set<Map.Entry<Data, Data>> entries = entrySet.getEntrySet();
   InternalPartitionService partitionService = getNodeEngine().getPartitionService();
   Set<Data> keysToInvalidate = new HashSet<Data>();
   for (Map.Entry<Data, Data> entry : entries) {
     Data dataKey = entry.getKey();
     Data dataValue = entry.getValue();
     if (partitionId == partitionService.getPartitionId(dataKey)) {
       Data dataOldValue = null;
       if (initialLoad) {
         recordStore.putFromLoad(dataKey, dataValue, -1);
       } else {
         dataOldValue = mapServiceContext.toData(recordStore.put(dataKey, dataValue, -1));
       }
       mapServiceContext.interceptAfterPut(name, dataValue);
       EntryEventType eventType =
           dataOldValue == null ? EntryEventType.ADDED : EntryEventType.UPDATED;
       final MapEventPublisher mapEventPublisher = mapServiceContext.getMapEventPublisher();
       mapEventPublisher.publishEvent(
           getCallerAddress(), name, eventType, dataKey, dataOldValue, dataValue);
       keysToInvalidate.add(dataKey);
       if (mapContainer.getWanReplicationPublisher() != null
           && mapContainer.getWanMergePolicy() != null) {
         Record record = recordStore.getRecord(dataKey);
         final Data dataValueAsData = mapServiceContext.toData(dataValue);
         final EntryView entryView =
             EntryViews.createSimpleEntryView(dataKey, dataValueAsData, record);
         mapEventPublisher.publishWanReplicationUpdate(name, entryView);
       }
       backupEntrySet.add(entry);
       RecordInfo replicationInfo = Records.buildRecordInfo(recordStore.getRecord(dataKey));
       backupRecordInfos.add(replicationInfo);
     }
   }
   invalidateNearCaches(keysToInvalidate);
 }
  protected Object call() {
    InternalPartitionService service = getService(InternalPartitionService.SERVICE_NAME);
    service.firstArrangement();

    Map<Address, List<Integer>> partitionsMap = new HashMap<Address, List<Integer>>();

    for (InternalPartition partition : service.getPartitions()) {
      Address owner = partition.getOwnerOrNull();
      if (owner == null) {
        partitionsMap.clear();
        return ClientGetPartitionsCodec.encodeResponse(partitionsMap.entrySet());
      }
      List<Integer> indexes = partitionsMap.get(owner);
      if (indexes == null) {
        indexes = new LinkedList<Integer>();
        partitionsMap.put(owner, indexes);
      }
      indexes.add(partition.getPartitionId());
    }
    return ClientGetPartitionsCodec.encodeResponse(partitionsMap.entrySet());
  }
  static MapKeyLoader.Role assignRole(
      InternalPartitionService partitionService, int mapNamePartition, int partitionId) {

    boolean isPartitionOwner = partitionService.isPartitionOwner(partitionId);
    boolean isMapPartition = (mapNamePartition == partitionId);

    if (isMapPartition) {
      return isPartitionOwner ? MapKeyLoader.Role.SENDER : MapKeyLoader.Role.SENDER_BACKUP;
    }

    return isPartitionOwner ? MapKeyLoader.Role.RECEIVER : MapKeyLoader.Role.NONE;
  }
示例#19
0
  public LocalMapStatsImpl createLocalMapStats(String mapName) {
    MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
    LocalMapStatsImpl stats = getLocalMapStatsImpl(mapName);
    if (!mapContainer.getMapConfig().isStatisticsEnabled()) {
      return stats;
    }
    int backupCount = mapContainer.getTotalBackupCount();
    Address thisAddress = clusterService.getThisAddress();

    LocalMapOnDemandCalculatedStats onDemandStats = new LocalMapOnDemandCalculatedStats();
    onDemandStats.setBackupCount(backupCount);

    addNearCacheStats(stats, onDemandStats, mapContainer);

    for (int partitionId = 0; partitionId < partitionService.getPartitionCount(); partitionId++) {
      InternalPartition partition = partitionService.getPartition(partitionId);
      Address owner = partition.getOwnerOrNull();
      if (owner == null) {
        // no-op because no owner is set yet. Therefore we don't know anything about the map
        continue;
      }

      if (owner.equals(thisAddress)) {
        addOwnerPartitionStats(stats, onDemandStats, mapName, partitionId);
      } else {
        addReplicaPartitionStats(
            onDemandStats,
            mapName,
            partitionId,
            partition,
            partitionService,
            backupCount,
            thisAddress);
      }
    }

    onDemandStats.copyValuesTo(stats);

    return stats;
  }
示例#20
0
 private static boolean isEvictablePerPartition(final MapContainer mapContainer) {
   final MapService mapService = mapContainer.getMapService();
   final MaxSizeConfig maxSizeConfig = mapContainer.getMapConfig().getMaxSizeConfig();
   final int maxSize = getApproximateMaxSize(maxSizeConfig.getSize());
   final String mapName = mapContainer.getName();
   final NodeEngine nodeEngine = mapService.getNodeEngine();
   final InternalPartitionService partitionService = nodeEngine.getPartitionService();
   for (int i = 0; i < partitionService.getPartitionCount(); i++) {
     final Address owner = partitionService.getPartitionOwner(i);
     if (nodeEngine.getThisAddress().equals(owner)) {
       final PartitionContainer container = mapService.getPartitionContainer(i);
       if (container == null) {
         return false;
       }
       final int size = container.getRecordStore(mapName).size();
       if (size >= maxSize) {
         return true;
       }
     }
   }
   return false;
 }
  @Override
  public void run() throws Exception {
    final int partitionId = getPartitionId();
    final InternalPartitionService partitionService = getNodeEngine().getPartitionService();

    Set<Data> filteredKeys = new HashSet<Data>();
    if (keys != null) {
      for (Data k : keys) {
        if (partitionService.getPartitionId(k) == partitionId) {
          filteredKeys.add(k);
        }
      }
    }

    if (filteredKeys.isEmpty()) {
      return;
    }

    try {
      final ICacheService service = getService();
      cache = service.getOrCreateRecordStore(name, partitionId);
      final Set<Data> keysLoaded = cache.loadAll(filteredKeys, replaceExistingValues);
      shouldBackup = !keysLoaded.isEmpty();
      if (shouldBackup) {
        backupRecords = new HashMap<Data, CacheRecord>(keysLoaded.size());
        for (Data key : keysLoaded) {
          CacheRecord record = cache.getRecord(key);
          // Loaded keys may have been evicted, then record will be null.
          // So if the loaded key is evicted, don't send it to backup.
          if (record != null) {
            backupRecords.put(key, record);
          }
        }
      }
    } catch (CacheException e) {
      response = new CacheClearResponse(e);
    }
  }
示例#22
0
 private void finalizeTransactionRemotely(Xid xid, boolean isCommit) throws XAException {
   NodeEngine nodeEngine = getNodeEngine();
   InternalPartitionService partitionService = nodeEngine.getPartitionService();
   OperationService operationService = nodeEngine.getOperationService();
   SerializableXID serializableXID =
       new SerializableXID(
           xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier());
   Data xidData = nodeEngine.toData(serializableXID);
   int partitionId = partitionService.getPartitionId(xidData);
   FinalizeRemoteTransactionOperation operation =
       new FinalizeRemoteTransactionOperation(xidData, isCommit);
   InternalCompletableFuture<Integer> future =
       operationService.invokeOnPartition(SERVICE_NAME, operation, partitionId);
   Integer errorCode;
   try {
     errorCode = future.get();
   } catch (Exception e) {
     throw ExceptionUtil.rethrow(e);
   }
   if (errorCode != null) {
     throw new XAException(errorCode);
   }
 }
示例#23
0
 /** Waits partition table update to get replica address if current replica address is null. */
 protected Address waitForReplicaAddress(
     int replica,
     InternalPartition partition,
     InternalPartitionService partitionService,
     int backupCount) {
   int tryCount = RETRY_COUNT;
   Address replicaAddress = null;
   while (replicaAddress == null
       && partitionService.getMemberGroupsSize() > backupCount
       && tryCount-- > 0) {
     sleep();
     replicaAddress = partition.getReplicaAddress(replica);
   }
   return replicaAddress;
 }
示例#24
0
  public LocalMapStatsImpl createLocalMapStats(String mapName) {
    MapContainer mapContainer = getMapContainer(mapName);
    LocalMapStatsImpl localMapStats = getLocalMapStatsImpl(mapName);
    if (!mapContainer.getMapConfig().isStatisticsEnabled()) {
      return localMapStats;
    }

    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long dirtyCount = 0;
    long ownedEntryMemoryCost = 0;
    long backupEntryMemoryCost = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    long heapCost = 0;

    int backupCount = mapContainer.getTotalBackupCount();
    ClusterService clusterService = nodeEngine.getClusterService();
    final InternalPartitionService partitionService = nodeEngine.getPartitionService();

    Address thisAddress = clusterService.getThisAddress();
    for (int partitionId = 0; partitionId < partitionService.getPartitionCount(); partitionId++) {
      InternalPartition partition = partitionService.getPartition(partitionId);
      Address owner = partition.getOwner();
      if (owner == null) {
        // no-op because no owner is set yet. Therefor we don't know anything about the map
        continue;
      }
      if (owner.equals(thisAddress)) {
        PartitionContainer partitionContainer = getPartitionContainer(partitionId);
        RecordStore recordStore = partitionContainer.getExistingRecordStore(mapName);

        // we don't want to force loading the record store because we are loading statistics. So
        // that is why
        // we ask for 'getExistingRecordStore' instead of 'getRecordStore' which does the load.
        if (recordStore != null) {
          heapCost += recordStore.getHeapCost();
          Map<Data, Record> records = recordStore.getReadonlyRecordMap();
          for (Record record : records.values()) {
            RecordStatistics stats = record.getStatistics();
            // there is map store and the record is dirty (waits to be stored)
            ownedEntryCount++;
            ownedEntryMemoryCost += record.getCost();
            localMapStats.setLastAccessTime(stats.getLastAccessTime());
            localMapStats.setLastUpdateTime(stats.getLastUpdateTime());
            hits += stats.getHits();
            if (recordStore.isLocked(record.getKey())) {
              lockedEntryCount++;
            }
          }
        }
      } else {
        for (int replica = 1; replica <= backupCount; replica++) {
          Address replicaAddress = partition.getReplicaAddress(replica);
          int tryCount = 30;
          // wait if the partition table is not updated yet
          while (replicaAddress == null
              && clusterService.getSize() > backupCount
              && tryCount-- > 0) {
            try {
              Thread.sleep(100);
            } catch (InterruptedException e) {
              throw ExceptionUtil.rethrow(e);
            }
            replicaAddress = partition.getReplicaAddress(replica);
          }

          if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
            PartitionContainer partitionContainer = getPartitionContainer(partitionId);
            RecordStore recordStore = partitionContainer.getRecordStore(mapName);
            heapCost += recordStore.getHeapCost();

            Map<Data, Record> records = recordStore.getReadonlyRecordMap();
            for (Record record : records.values()) {
              backupEntryCount++;
              backupEntryMemoryCost += record.getCost();
            }
          } else if (replicaAddress == null && clusterService.getSize() > backupCount) {
            logger.warning("Partition: " + partition + ", replica: " + replica + " has no owner!");
          }
        }
      }
    }

    if (mapContainer.getMapStoreScheduler() != null) {
      dirtyCount = mapContainer.getMapStoreScheduler().size();
    }
    localMapStats.setBackupCount(backupCount);
    localMapStats.setDirtyEntryCount(zeroOrPositive(dirtyCount));
    localMapStats.setLockedEntryCount(zeroOrPositive(lockedEntryCount));
    localMapStats.setHits(zeroOrPositive(hits));
    localMapStats.setOwnedEntryCount(zeroOrPositive(ownedEntryCount));
    localMapStats.setBackupEntryCount(zeroOrPositive(backupEntryCount));
    localMapStats.setOwnedEntryMemoryCost(zeroOrPositive(ownedEntryMemoryCost));
    localMapStats.setBackupEntryMemoryCost(zeroOrPositive(backupEntryMemoryCost));
    // add near cache heap cost.
    heapCost += mapContainer.getNearCacheSizeEstimator().getSize();
    localMapStats.setHeapCost(heapCost);
    if (mapContainer.getMapConfig().isNearCacheEnabled()) {
      NearCacheStatsImpl nearCacheStats = getNearCache(mapName).getNearCacheStats();
      localMapStats.setNearCacheStats(nearCacheStats);
    }

    return localMapStats;
  }
示例#25
0
 private List<Integer> getMemberPartitions() {
   InternalPartitionService partitionService = nodeEngine.getPartitionService();
   List<Integer> partitions = partitionService.getMemberPartitions(nodeEngine.getThisAddress());
   return Collections.unmodifiableList(partitions);
 }
 protected boolean keyNotOwnedByThisPartition(Data key) {
   final InternalPartitionService partitionService = getNodeEngine().getPartitionService();
   return partitionService.getPartitionId(key) != getPartitionId();
 }
示例#27
0
 protected boolean isReplicaAvailable(
     Address replicaAddress, InternalPartitionService partitionService, int backupCount) {
   return !(replicaAddress == null && partitionService.getMemberGroupsSize() > backupCount);
 }
 @Override
 protected int getPartition() {
   InternalPartitionService partitionService = clientEngine.getPartitionService();
   return partitionService.getPartitionId(key);
 }