Ejemplo n.º 1
0
  private void sendMembershipEvents(
      Collection<MemberImpl> currentMembers, Collection<MemberImpl> newMembers) {
    Set<Member> eventMembers = new LinkedHashSet<Member>(currentMembers);
    if (!newMembers.isEmpty()) {
      if (newMembers.size() == 1) {
        MemberImpl newMember = newMembers.iterator().next();
        // sync call
        node.getPartitionService().memberAdded(newMember);

        // async events
        eventMembers.add(newMember);
        sendMembershipEventNotifications(newMember, unmodifiableSet(eventMembers), true);
      } else {
        for (MemberImpl newMember : newMembers) {
          // sync call
          node.getPartitionService().memberAdded(newMember);

          // async events
          eventMembers.add(newMember);
          sendMembershipEventNotifications(
              newMember, unmodifiableSet(new LinkedHashSet<Member>(eventMembers)), true);
        }
      }
    }
  }
Ejemplo n.º 2
0
  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);
  }
Ejemplo n.º 3
0
  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;
  }
  @Before
  public void setup() {
    when(node.getPartitionService()).thenReturn(partitionService);
    when(node.getClusterService()).thenReturn(clusterService);
    when(node.getNodeExtension()).thenReturn(mock(NodeExtension.class));
    when(node.getLogger(ClusterStateManager.class)).thenReturn(mock(ILogger.class));

    clusterStateManager = new ClusterStateManager(node, lock);
  }
Ejemplo n.º 5
0
  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);
  }
Ejemplo n.º 6
0
 private HazelcastInstance[] findOwnerAndReplicas(HazelcastInstance[] instances, String name) {
   Node node = getNode(instances[0]);
   InternalPartitionService partitionService = node.getPartitionService();
   int partitionId = partitionService.getPartitionId(name);
   InternalPartition partition = partitionService.getPartition(partitionId);
   HazelcastInstance[] ownerAndReplicas = new HazelcastInstance[instances.length];
   for (int i = 0; i < instances.length; i++) {
     ownerAndReplicas[i] = getInstanceForAddress(instances, partition.getReplicaAddress(i));
   }
   return ownerAndReplicas;
 }
Ejemplo n.º 7
0
  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);
  }
Ejemplo n.º 8
0
  private void registerCoreServices() {
    logger.finest("Registering core services...");

    Node node = nodeEngine.getNode();
    registerService(ClusterServiceImpl.SERVICE_NAME, node.getClusterService());
    registerService(InternalPartitionService.SERVICE_NAME, node.getPartitionService());
    registerService(ProxyServiceImpl.SERVICE_NAME, nodeEngine.getProxyService());
    registerService(
        TransactionManagerServiceImpl.SERVICE_NAME, nodeEngine.getTransactionManagerService());
    registerService(ClientEngineImpl.SERVICE_NAME, node.clientEngine);
    registerService(QuorumServiceImpl.SERVICE_NAME, nodeEngine.getQuorumService());
  }
Ejemplo n.º 9
0
 // for testing
 void changeClusterState(ClusterState newState, Collection<Member> members) {
   int partitionStateVersion = node.getPartitionService().getPartitionStateVersion();
   clusterStateManager.changeClusterState(newState, members, partitionStateVersion);
 }
Ejemplo n.º 10
0
 @Override
 public void changeClusterState(ClusterState newState, TransactionOptions options) {
   int partitionStateVersion = node.getPartitionService().getPartitionStateVersion();
   clusterStateManager.changeClusterState(newState, getMembers(), options, partitionStateVersion);
 }
Ejemplo n.º 11
0
 private void onMemberRemove(MemberImpl deadMember, Map<Address, MemberImpl> newMembers) {
   // sync call
   node.getPartitionService().memberRemoved(deadMember);
   // sync call
   nodeEngine.onMemberLeft(deadMember);
 }