public LocalMapStats createStats(String name) {
    LocalMultiMapStatsImpl stats = getLocalMultiMapStatsImpl(name);
    long ownedEntryCount = 0;
    long backupEntryCount = 0;
    long hits = 0;
    long lockedEntryCount = 0;
    ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();

    Address thisAddress = clusterService.getThisAddress();
    for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
      InternalPartition partition = nodeEngine.getPartitionService().getPartition(i);
      MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
      MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
      if (multiMapContainer == null) {
        continue;
      }
      Address owner = partition.getOwnerOrNull();
      if (owner != null) {
        if (owner.equals(thisAddress)) {
          lockedEntryCount += multiMapContainer.getLockedCount();
          for (MultiMapWrapper wrapper : multiMapContainer.multiMapWrappers.values()) {
            hits += wrapper.getHits();
            ownedEntryCount += wrapper.getCollection(false).size();
          }
        } else {
          int backupCount = multiMapContainer.config.getTotalBackupCount();
          for (int j = 1; j <= backupCount; j++) {
            Address replicaAddress = partition.getReplicaAddress(j);
            int memberSize = nodeEngine.getClusterService().getMembers().size();

            int tryCount = REPLICA_ADDRESS_TRY_COUNT;
            // wait if the partition table is not updated yet
            while (memberSize > backupCount && replicaAddress == null && tryCount-- > 0) {
              try {
                Thread.sleep(REPLICA_ADDRESS_SLEEP_WAIT_MILLIS);
              } catch (InterruptedException e) {
                throw ExceptionUtil.rethrow(e);
              }
              replicaAddress = partition.getReplicaAddress(j);
            }

            if (replicaAddress != null && replicaAddress.equals(thisAddress)) {
              for (MultiMapWrapper wrapper : multiMapContainer.multiMapWrappers.values()) {
                backupEntryCount += wrapper.getCollection(false).size();
              }
            }
          }
        }
      }
    }
    stats.setOwnedEntryCount(ownedEntryCount);
    stats.setBackupEntryCount(backupEntryCount);
    stats.setHits(hits);
    stats.setLockedEntryCount(lockedEntryCount);
    return stats;
  }
  @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());
  }
 QueueProxySupport(final String name, final QueueService queueService, NodeEngine nodeEngine) {
   super(nodeEngine, queueService);
   this.name = name;
   this.partitionId =
       nodeEngine.getPartitionService().getPartitionId(getNameAsPartitionAwareData());
   this.config = nodeEngine.getConfig().getQueueConfig(name);
 }
 public Set<Data> localKeySet(String name) {
   Set<Data> keySet = new HashSet<Data>();
   for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
     InternalPartition partition = nodeEngine.getPartitionService().getPartition(i);
     MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
     MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
     if (multiMapContainer == null) {
       continue;
     }
     if (partition.isLocal()) {
       keySet.addAll(multiMapContainer.keySet());
     }
   }
   getLocalMultiMapStatsImpl(name).incrementOtherOperations();
   return keySet;
 }
  public void init(final NodeEngine nodeEngine, Properties properties) {
    int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int partition = 0; partition < partitionCount; partition++) {
      partitionContainers[partition] = new MultiMapPartitionContainer(this, partition);
    }
    final LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
    if (lockService != null) {
      lockService.registerLockStoreConstructor(
          SERVICE_NAME,
          new ConstructorFunction<ObjectNamespace, LockStoreInfo>() {
            public LockStoreInfo createNew(final ObjectNamespace key) {
              String name = key.getObjectName();
              final MultiMapConfig multiMapConfig = nodeEngine.getConfig().findMultiMapConfig(name);

              return new LockStoreInfo() {
                public int getBackupCount() {
                  return multiMapConfig.getSyncBackupCount();
                }

                public int getAsyncBackupCount() {
                  return multiMapConfig.getAsyncBackupCount();
                }
              };
            }
          });
    }
  }
Exemple #6
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);
  }
Exemple #7
0
  public void init(final NodeEngine nodeEngine, Properties properties) {
    int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
    for (int i = 0; i < partitionCount; i++) {
      partitionContainers[i] = new PartitionContainer(this, i);
    }
    final LockService lockService = nodeEngine.getSharedService(LockService.SERVICE_NAME);
    if (lockService != null) {
      lockService.registerLockStoreConstructor(
          SERVICE_NAME,
          new ConstructorFunction<ObjectNamespace, LockStoreInfo>() {
            public LockStoreInfo createNew(final ObjectNamespace key) {
              final MapContainer mapContainer = getMapContainer(key.getObjectName());
              return new LockStoreInfo() {
                public int getBackupCount() {
                  return mapContainer.getBackupCount();
                }

                public int getAsyncBackupCount() {
                  return mapContainer.getAsyncBackupCount();
                }
              };
            }
          });
    }
    mapEvictionManager.init();
  }
 public MultiMapService(NodeEngine nodeEngine) {
   this.nodeEngine = nodeEngine;
   int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
   partitionContainers = new MultiMapPartitionContainer[partitionCount];
   this.logger = nodeEngine.getLogger(MultiMapService.class);
   dispatcher = new MultiMapEventsDispatcher(this, nodeEngine.getClusterService());
   publisher = new MultiMapEventsPublisher(nodeEngine);
 }
 public LocalMapStatsProvider(MapServiceContext mapServiceContext) {
   this.mapServiceContext = mapServiceContext;
   NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
   this.logger = nodeEngine.getLogger(getClass());
   this.nearCacheProvider = mapServiceContext.getNearCacheProvider();
   this.clusterService = nodeEngine.getClusterService();
   this.partitionService = nodeEngine.getPartitionService();
 }
Exemple #10
0
 private static long getUsedHeapSize(final MapContainer mapContainer) {
   long heapCost = 0L;
   final MapService mapService = mapContainer.getMapService();
   final String mapName = mapContainer.getName();
   final NodeEngine nodeEngine = mapService.getNodeEngine();
   final Address thisAddress = nodeEngine.getThisAddress();
   for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
     if (nodeEngine.getPartitionService().getPartition(i).isOwnerOrBackup(thisAddress)) {
       final PartitionContainer container = mapService.getPartitionContainer(i);
       if (container == null) {
         return -1L;
       }
       heapCost += container.getRecordStore(mapName).getHeapCost();
     }
   }
   heapCost += mapContainer.getNearCacheSizeEstimator().getSize();
   return heapCost;
 }
 public Set<Data> localKeySet(String name) {
   Set<Data> keySet = new HashSet<Data>();
   ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
   Address thisAddress = clusterService.getThisAddress();
   for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
     InternalPartition partition = nodeEngine.getPartitionService().getPartition(i);
     MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
     MultiMapContainer multiMapContainer = partitionContainer.getCollectionContainer(name);
     if (multiMapContainer == null) {
       continue;
     }
     if (thisAddress.equals(partition.getOwnerOrNull())) {
       keySet.addAll(multiMapContainer.keySet());
     }
   }
   getLocalMultiMapStatsImpl(name).incrementOtherOperations();
   return keySet;
 }
 @Override
 public final void init(NodeEngine nodeEngine, Properties properties) {
   this.nodeEngine = nodeEngine;
   int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
   segments = new CachePartitionSegment[partitionCount];
   for (int i = 0; i < partitionCount; i++) {
     segments[i] = new CachePartitionSegment(this, i);
   }
   postInit(nodeEngine, properties);
 }
Exemple #13
0
 @Override
 public void onReplicationEvent(WanReplicationEvent replicationEvent) {
   Object eventObject = replicationEvent.getEventObject();
   if (eventObject instanceof MapReplicationUpdate) {
     MapReplicationUpdate replicationUpdate = (MapReplicationUpdate) eventObject;
     EntryView entryView = replicationUpdate.getEntryView();
     MapMergePolicy mergePolicy = replicationUpdate.getMergePolicy();
     String mapName = replicationUpdate.getMapName();
     MapContainer mapContainer = getMapContainer(mapName);
     MergeOperation operation =
         new MergeOperation(
             mapName,
             toData(entryView.getKey(), mapContainer.getPartitioningStrategy()),
             entryView,
             mergePolicy);
     try {
       int partitionId = nodeEngine.getPartitionService().getPartitionId(entryView.getKey());
       Future f =
           nodeEngine
               .getOperationService()
               .invokeOnPartition(SERVICE_NAME, operation, partitionId);
       f.get();
     } catch (Throwable t) {
       throw ExceptionUtil.rethrow(t);
     }
   } else if (eventObject instanceof MapReplicationRemove) {
     MapReplicationRemove replicationRemove = (MapReplicationRemove) eventObject;
     WanOriginatedDeleteOperation operation =
         new WanOriginatedDeleteOperation(
             replicationRemove.getMapName(), replicationRemove.getKey());
     try {
       int partitionId =
           nodeEngine.getPartitionService().getPartitionId(replicationRemove.getKey());
       Future f =
           nodeEngine
               .getOperationService()
               .invokeOnPartition(SERVICE_NAME, operation, partitionId);
       f.get();
     } catch (Throwable t) {
       throw ExceptionUtil.rethrow(t);
     }
   }
 }
Exemple #14
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);
 }
 private long nextId(Data key) {
   final NodeEngine nodeEngine = getNodeEngine();
   TxnGenerateRecordIdOperation operation = new TxnGenerateRecordIdOperation(name, key);
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
     final OperationService operationService = nodeEngine.getOperationService();
     Future<Long> f =
         operationService.invokeOnPartition(MultiMapService.SERVICE_NAME, operation, partitionId);
     return f.get();
   } catch (Throwable t) {
     throw ExceptionUtil.rethrow(t);
   }
 }
    public void run() {
      final long now = Clock.currentTimeMillis();
      final MapService mapService = ExpirationManager.this.mapService;
      final NodeEngine nodeEngine = mapService.getNodeEngine();
      final int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
      List<PartitionContainer> partitionContainers = Collections.emptyList();
      boolean createLazy = true;
      int currentlyRunningCleanupOperationsCount = 0;
      for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartition partition = nodeEngine.getPartitionService().getPartition(partitionId);
        if (partition.isOwnerOrBackup(nodeEngine.getThisAddress())) {
          final PartitionContainer partitionContainer =
              mapService.getPartitionContainer(partitionId);
          if (isContainerEmpty(partitionContainer)) {
            continue;
          }
          if (hasRunningCleanup(partitionContainer)) {
            currentlyRunningCleanupOperationsCount++;
            continue;
          }
          if (currentlyRunningCleanupOperationsCount > getMaxCleanupOperationCountInOneRound()
              || notInProcessableTimeWindow(partitionContainer, now)
              || notAnyExpirableRecord(partitionContainer)) {
            continue;
          }

          if (createLazy) {
            partitionContainers = new ArrayList<PartitionContainer>();
            createLazy = false;
          }
          partitionContainers.add(partitionContainer);
        }
      }
      if (partitionContainers.isEmpty()) {
        return;
      }
      Collections.sort(partitionContainers, partitionContainerComparator);
      sendCleanupOperations(partitionContainers);
    }
 @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;
   }
 }
 private MultiMapResponse lockAndGet(Data key, long timeout, long ttl) {
   final NodeEngine nodeEngine = getNodeEngine();
   TxnLockAndGetOperation operation =
       new TxnLockAndGetOperation(name, key, timeout, ttl, getThreadId());
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
     final OperationService operationService = nodeEngine.getOperationService();
     Future<MultiMapResponse> f =
         operationService.invokeOnPartition(MultiMapService.SERVICE_NAME, operation, partitionId);
     return f.get();
   } catch (Throwable t) {
     throw ExceptionUtil.rethrow(t);
   }
 }
 private Object invokeData(CollectionOperation operation, Data dataKey) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
     Invocation inv =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId)
             .build();
     Future f = inv.invoke();
     return nodeEngine.toObject(f.get());
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
Exemple #20
0
 @Override
 public void beforeRun() throws Exception {
   final NodeEngine nodeEngine = getNodeEngine();
   final int partitionId = getPartitionId();
   final InternalPartition partition = nodeEngine.getPartitionService().getPartition(partitionId);
   final Address owner = partition.getReplicaAddress(getReplicaIndex());
   if (!nodeEngine.getThisAddress().equals(owner)) {
     valid = false;
     final ILogger logger = getLogger();
     if (logger.isFinestEnabled()) {
       logger.finest(
           "Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
     }
   }
 }
 /**
  * @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);
  }
  @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();
    }
  }
Exemple #24
0
 public MapService(NodeEngine nodeEngine) {
   this.nodeEngine = nodeEngine;
   this.mapEvictionManager = new MapEvictionManager(this);
   this.replicaWaitSecondsForScheduledTasks =
       getNodeEngine()
               .getGroupProperties()
               .MAP_REPLICA_WAIT_SECONDS_FOR_SCHEDULED_TASKS
               .getInteger()
           * 1000;
   logger = nodeEngine.getLogger(MapService.class.getName());
   partitionContainers =
       new PartitionContainer[nodeEngine.getPartitionService().getPartitionCount()];
   ownedPartitions = new AtomicReference<List<Integer>>();
   mergePolicyMap = new ConcurrentHashMap<String, MapMergePolicy>();
   mergePolicyMap.put(PutIfAbsentMapMergePolicy.class.getName(), new PutIfAbsentMapMergePolicy());
   mergePolicyMap.put(HigherHitsMapMergePolicy.class.getName(), new HigherHitsMapMergePolicy());
   mergePolicyMap.put(PassThroughMergePolicy.class.getName(), new PassThroughMergePolicy());
   mergePolicyMap.put(
       LatestUpdateMapMergePolicy.class.getName(), new LatestUpdateMapMergePolicy());
 }
 public void process(
     EntryTaskScheduler<String, Void> scheduler,
     Collection<ScheduledEntry<String, Void>> entries) {
   if (entries.isEmpty()) {
     return;
   }
   for (ScheduledEntry<String, Void> entry : entries) {
     String name = entry.getKey();
     int partitionId = nodeEngine.getPartitionService().getPartitionId(nodeEngine.toData(name));
     final Invocation inv =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(
                 QueueService.SERVICE_NAME,
                 new CheckAndEvictOperation(entry.getKey()),
                 partitionId)
             .build();
     inv.invoke();
   }
 }
Exemple #26
0
  @Override
  public void run() throws Exception {
    if (!valid) {
      return;
    }
    final NodeEngine nodeEngine = getNodeEngine();
    final PartitionServiceImpl partitionService =
        (PartitionServiceImpl) nodeEngine.getPartitionService();
    partitionService.updatePartitionReplicaVersions(
        getPartitionId(), replicaVersions, getReplicaIndex());

    if (backupOp != null) {
      backupOp.setNodeEngine(nodeEngine);
      backupOp.setResponseHandler(ResponseHandlerFactory.createEmptyResponseHandler());
      backupOp.setCallerUuid(getCallerUuid());
      OperationAccessor.setCallerAddress(backupOp, getCallerAddress());
      OperationAccessor.setInvocationTime(backupOp, Clock.currentTimeMillis());

      final OperationService operationService = nodeEngine.getOperationService();
      operationService.runOperation(backupOp);
    }
  }
Exemple #27
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;
 }
 private <T> T invoke(Operation operation, Data dataKey) {
   final NodeEngine nodeEngine = getNodeEngine();
   try {
     int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey);
     Invocation invocation =
         nodeEngine
             .getOperationService()
             .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId)
             .build();
     Future f;
     Object o;
     if (config.isStatisticsEnabled()) {
       long time = System.currentTimeMillis();
       f = invocation.invoke();
       o = f.get();
       if (operation instanceof PutOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementPuts(System.currentTimeMillis() - time);
       } else if (operation instanceof RemoveOperation
           || operation instanceof RemoveAllOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementRemoves(System.currentTimeMillis() - time);
       } else if (operation instanceof GetAllOperation) {
         getService()
             .getLocalMultiMapStatsImpl(proxyId)
             .incrementGets(System.currentTimeMillis() - time);
       }
     } else {
       f = invocation.invoke();
       o = f.get();
     }
     return (T) nodeEngine.toObject(o);
   } catch (Throwable throwable) {
     throw ExceptionUtil.rethrow(throwable);
   }
 }
Exemple #29
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);
   }
 }
 public AtomicReferenceProxy(String name, NodeEngine nodeEngine, AtomicReferenceService service) {
   super(nodeEngine, service);
   this.name = name;
   this.partitionId =
       nodeEngine.getPartitionService().getPartitionId(getNameAsPartitionAwareData());
 }