Esempio n. 1
0
 private void ensureBackupOperationInitialized() {
   if (backupOp.getNodeEngine() == null) {
     backupOp.setNodeEngine(getNodeEngine());
     backupOp.setPartitionId(getPartitionId());
     backupOp.setReplicaIndex(getReplicaIndex());
     backupOp.setCallerUuid(getCallerUuid());
     OperationAccessor.setCallerAddress(backupOp, getCallerAddress());
     OperationAccessor.setInvocationTime(backupOp, Clock.currentTimeMillis());
     backupOp.setOperationResponseHandler(createEmptyResponseHandler());
   }
 }
  public void whenNormalOperation(boolean partitionSpecific, boolean remoteCall) {
    BasicBackPressureService service = newEnabledBackPressureService();

    Operation op;
    if (partitionSpecific) {
      PartitionSpecificOperation partitionOp = new PartitionSpecificOperation();
      partitionOp.setPartitionId(0);
      op = partitionOp;
    } else {
      op = new GenericOperation();
      op.setPartitionId(-1);
    }

    Connection connection = null;
    if (remoteCall) {
      connection = mock(Connection.class);
      OperationAccessor.setConnection(op, connection);
    }

    int expected = SYNC_WINDOW - 1;
    for (int k = 0; k < SYNC_WINDOW; k++) {
      boolean result = service.isBackPressureNeeded(op);
      assertFalse("no back pressure expected", result);

      AtomicInteger syncDelay = service.getSyncDelay(connection, op.getPartitionId());
      assertEquals(expected, syncDelay.get());
      expected--;
    }

    boolean result = service.isBackPressureNeeded(op);
    assertTrue("back pressure expected", result);

    AtomicInteger syncDelay = service.getSyncDelay(connection, op.getPartitionId());
    assertValidSyncDelay(syncDelay);
  }
Esempio n. 3
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);
    }
  }
  @Test
  public void cleanup_whenConnectionIsNotAlive() {
    BasicBackPressureService service = newEnabledBackPressureService();
    GenericOperation op = new GenericOperation();

    Connection connection = mock(Connection.class);
    when(connection.isAlive()).thenReturn(false);
    OperationAccessor.setConnection(op, connection);

    service.isBackPressureNeeded(op);

    service.cleanup();

    assertNull(service.getSyncDelays(connection));
  }
Esempio n. 5
0
    public void run() {
      final NodeEngine nodeEngine = mapService.getNodeEngine();
      try {
        Map values = mapContainer.getStore().loadAll(keys.values());
        if (values == null || values.isEmpty()) {
          if (checkIfMapLoaded.decrementAndGet() == 0) {
            loaded.set(true);
          }
          return;
        }

        MapEntrySet entrySet = new MapEntrySet();
        for (Data dataKey : keys.keySet()) {
          Object key = keys.get(dataKey);
          Object value = values.get(key);
          if (value != null) {
            Data dataValue = mapService.toData(value);
            entrySet.add(dataKey, dataValue);
          }
        }
        PutAllOperation operation = new PutAllOperation(name, entrySet, true);
        operation.setNodeEngine(nodeEngine);
        operation.setResponseHandler(
            new ResponseHandler() {
              @Override
              public void sendResponse(Object obj) {
                if (checkIfMapLoaded.decrementAndGet() == 0) {
                  loaded.set(true);
                }
              }

              public boolean isLocal() {
                return true;
              }
            });
        operation.setPartitionId(partitionId);
        OperationAccessor.setCallerAddress(operation, nodeEngine.getThisAddress());
        operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
        operation.setServiceName(MapService.SERVICE_NAME);
        nodeEngine.getOperationService().executeOperation(operation);
      } catch (Exception e) {
        logger.warning("Exception while load all task:" + e.toString());
      }
    }