Exemplo n.º 1
0
  boolean isUsedInPartitioning() {
    boolean ok = false;
    // TODO: Asif: Handle this case where region is turning out to be null
    // Ideally Bug 39923 workaround should ensure that region is not null. But we are doing
    // this check only for Update type statements. For Select queries, it may stll be null,
    // hence the check

    if (this.tqi == null) {
      return ok;
    }
    Region rgnOwningColumn = this.tqi.getRegion();
    assert rgnOwningColumn != null;
    RegionAttributes ra = rgnOwningColumn.getAttributes();
    // If the region is a Replicated Region or if it is a PR with just
    // itself
    // as a member then we should go with Derby's Activation Object
    DataPolicy policy = ra.getDataPolicy();

    if (policy.withPartitioning()) {
      PartitionedRegion pr = (PartitionedRegion) rgnOwningColumn;
      GfxdPartitionResolver rslvr = (GfxdPartitionResolver) pr.getPartitionResolver();
      ok = rslvr != null && rslvr.isUsedInPartitioning(this.actualColumnName);
    }
    return ok;
  }
  @SuppressWarnings("unchecked")
  @Override
  public void cmdExecute(Message msg, ServerConnection servConn, long start)
      throws IOException, ClassNotFoundException, InterruptedException {
    String regionFullPath = null;
    CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
    regionFullPath = msg.getPart(0).getString();
    String errMessage = "";
    if (regionFullPath == null) {
      logger.warn(
          LocalizedMessage.create(
              LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL));
      errMessage =
          LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL
              .toLocalizedString();
      writeErrorResponse(
          msg, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), servConn);
      servConn.setAsTrue(RESPONDED);
    } else {
      Region region = crHelper.getRegion(regionFullPath);
      if (region == null) {
        logger.warn(
            LocalizedMessage.create(
                LocalizedStrings
                    .GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH,
                regionFullPath));
        errMessage =
            LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString()
                + regionFullPath;
        writeErrorResponse(
            msg,
            MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR,
            errMessage.toString(),
            servConn);
        servConn.setAsTrue(RESPONDED);
      } else {
        try {
          Message responseMsg = servConn.getResponseMessage();
          responseMsg.setTransactionId(msg.getTransactionId());
          responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);

          PartitionedRegion prRgion = (PartitionedRegion) region;

          PartitionResolver partitionResolver = prRgion.getPartitionResolver();
          int numParts = 2; // MINUMUM PARTS
          if (partitionResolver != null) {
            numParts++;
          }
          responseMsg.setNumberOfParts(numParts);
          // PART 1
          responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());

          // PART 2
          if (partitionResolver != null) {
            responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
          }

          // PART 3
          String leaderRegionPath = null;
          PartitionedRegion leaderRegion = null;
          String leaderRegionName = prRgion.getColocatedWith();
          if (leaderRegionName != null) {
            Cache cache = prRgion.getCache();
            while (leaderRegionName != null) {
              leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
              if (leaderRegion.getColocatedWith() == null) {
                leaderRegionPath = leaderRegion.getFullPath();
                break;
              } else {
                leaderRegionName = leaderRegion.getColocatedWith();
              }
            }
          }
          responseMsg.addObjPart(leaderRegionPath);
          responseMsg.send();
          msg.flush();
        } catch (Exception e) {
          writeException(msg, e, false, servConn);
        } finally {
          servConn.setAsTrue(Command.RESPONDED);
        }
      }
    }
  }