示例#1
0
 @Override
 public ArrayList<HashMap> doExecute(Map<String, Object> args) {
   Cache cache = CacheFactory.getAnyInstance();
   String regionPath = (String) args.get(ApiConstant.REGIONPATH);
   Region region = cache.getRegion(regionPath);
   ArrayList<HashMap> list = new ArrayList<HashMap>();
   if (region != null && region instanceof PartitionedRegion) {
     DistributedMember member = cache.getDistributedSystem().getDistributedMember();
     PartitionedRegion pr = (PartitionedRegion) region;
     if (pr.getDataStore() != null) {
       Set<BucketRegion> set2 = pr.getDataStore().getAllLocalBucketRegions();
       for (BucketRegion br : set2) {
         HashMap map = new HashMap();
         map.put("BucketId", br.getId());
         map.put("Size", br.size());
         map.put("Bytes", br.getTotalBytes());
         map.put("host", getHost());
         map.put("node", System.getProperty("NODE_NAME"));
         InternalDistributedMember m = pr.getBucketPrimary(br.getId());
         if (m != null && member.getId().equals(m.getId())) {
           map.put("type", "primary");
         } else {
           map.put("type", "redundant");
         }
         map.put("TotalNumBuckets", pr.getPartitionAttributes().getTotalNumBuckets());
         list.add(map);
       }
     }
   }
   return list;
 }
  /**
   * Safely checks to see if the provided Node participates in the PartitionedRegion return true if
   * the Node participates in the PartitionedRegion
   */
  boolean containsMember(InternalDistributedMember memberId) {
    if (this.nodes != null) {
      for (Node node : this.nodes) {
        if (memberId.equals(node.getMemberId())) {
          return true;
        }
      }
    }

    return false;
  }
  @Override
  public Object processRequest(Object request) throws IOException {
    Object response = null;

    if (logger.isDebugEnabled()) {
      logger.debug("Peer locator processing {}", request);
    }

    if (localAddress == null && services != null) {
      localAddress = services.getMessenger().getMemberID();
    }

    if (request instanceof GetViewRequest) {
      if (view != null) {
        response = new GetViewResponse(view);
      }
    } else if (request instanceof FindCoordinatorRequest) {
      FindCoordinatorRequest findRequest = (FindCoordinatorRequest) request;

      if (findRequest.getMemberID() != null) {
        InternalDistributedMember coord = null;

        // at this level we want to return the coordinator known to membership services,
        // which may be more up-to-date than the one known by the membership manager
        if (view == null) {
          findServices();
        }

        boolean fromView = false;
        int viewId = -1;
        NetView v = this.view;

        if (v != null) {
          // if the ID of the requester matches an entry in the membership view then remove
          // that entry - it's obviously an old member since the ID has been reused
          InternalDistributedMember rid = findRequest.getMemberID();
          for (InternalDistributedMember id : v.getMembers()) {
            if (rid.compareTo(id, false) == 0) {
              NetView newView = new NetView(v, v.getViewId());
              newView.remove(id);
              v = newView;
              break;
            }
          }
          viewId = v.getViewId();
          if (viewId > findRequest.getLastViewId()) {
            // ignore the requests rejectedCoordinators if the view has changed
            coord = v.getCoordinator(Collections.<InternalDistributedMember>emptyList());
          } else {
            coord = v.getCoordinator(findRequest.getRejectedCoordinators());
          }
          logger.debug("Peer locator: coordinator from view is {}", coord);
          fromView = true;
        }

        if (coord == null) {
          // find the "oldest" registrant
          Collection<InternalDistributedMember> rejections = findRequest.getRejectedCoordinators();
          if (rejections == null) {
            rejections = Collections.emptyList();
          }
          synchronized (registrants) {
            registrants.add(findRequest.getMemberID());
            if (services != null) {
              coord = services.getJoinLeave().getMemberID();
            }
            for (InternalDistributedMember mbr : registrants) {
              if (mbr != coord && (coord == null || mbr.compareTo(coord) < 0)) {
                if (!rejections.contains(mbr)
                    && (mbr.getNetMember().preferredForCoordinator()
                        || !mbr.getNetMember().splitBrainEnabled())) {
                  coord = mbr;
                }
              }
            }
            logger.debug("Peer locator: coordinator from registrations is {}", coord);
          }
        }

        synchronized (registrants) {
          response =
              new FindCoordinatorResponse(
                  coord,
                  localAddress,
                  fromView,
                  view,
                  new HashSet<InternalDistributedMember>(registrants),
                  this.networkPartitionDetectionEnabled,
                  this.usePreferredCoordinators);
        }
      }
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Peer locator returning {}", response);
    }
    return response;
  }
  /**
   * flush state to the given target
   *
   * @param recipients The members who may be making state changes to the region. This is typically
   *     taken from a CacheDistributionAdvisor membership set
   * @param target The member who should have all state flushed to it
   * @param processorType The execution processor type for the marker message that is sent to all
   *     members using the given region
   * @param flushNewOps normally only ops that were started before region profile exchange are
   *     flushed. Setting this to true causes the flush to wait for any started after the profile
   *     exchange as well.
   * @throws InterruptedException If the operation is interrupted, usually for shutdown, an
   *     InterruptedException will be thrown
   * @return true if the state was flushed, false if not
   */
  public boolean flush(
      Set recipients, DistributedMember target, int processorType, boolean flushNewOps)
      throws InterruptedException {

    Set recips = recipients; // do not use recipients parameter past this point
    if (Thread.interrupted()) {
      throw new InterruptedException();
    }

    InternalDistributedMember myId = this.dm.getDistributionManagerId();

    if (!recips.contains(target) && !myId.equals(target)) {
      recips = new HashSet(recipients);
      recips.add(target);
    }
    // partial fix for bug 38773 - ensures that this cache will get both
    // a cache op and an adjunct message when creating a bucket region
    //    if (recips.size() < 2 && !myId.equals(target)) {
    //      return true; // no state to flush to a single holder of the region
    //    }
    StateMarkerMessage smm = new StateMarkerMessage();
    smm.relayRecipient = target;
    smm.processorType = processorType;
    smm.flushNewOps = flushNewOps;
    if (region == null) {
      smm.allRegions = true;
    } else {
      smm.regionPath = region.getFullPath();
    }
    smm.setRecipients(recips);

    StateFlushReplyProcessor gfprocessor = new StateFlushReplyProcessor(dm, recips, target);
    smm.processorId = gfprocessor.getProcessorId();
    if (region != null
        && region.isUsedForPartitionedRegionBucket()
        && region.getDistributionConfig().getAckSevereAlertThreshold() > 0) {
      smm.severeAlertEnabled = true;
      gfprocessor.enableSevereAlertProcessing();
    }
    if (logger.isTraceEnabled(LogMarker.STATE_FLUSH_OP)) {
      logger.trace(LogMarker.STATE_FLUSH_OP, "Sending {} with processor {}", smm, gfprocessor);
    }
    Set failures = this.dm.putOutgoing(smm);
    if (failures != null) {
      if (failures.contains(target)) {
        if (logger.isTraceEnabled(LogMarker.STATE_FLUSH_OP)) {
          logger.trace(
              LogMarker.STATE_FLUSH_OP,
              "failed to send StateMarkerMessage to target {}; returning from flush without waiting for replies",
              target);
        }
        return false;
      }
      gfprocessor.messageNotSentTo(failures);
    }

    try {
      //      try { Thread.sleep(100); } catch (InterruptedException e) {
      // Thread.currentThread().interrupt(); } // DEBUGGING - stall before getting membership to
      // increase odds that target has left
      gfprocessor.waitForReplies();
      if (logger.isTraceEnabled(LogMarker.STATE_FLUSH_OP)) {
        logger.trace(LogMarker.STATE_FLUSH_OP, "Finished processing {}", smm);
      }
    } catch (ReplyException re) {
      logger.warn(
          LocalizedMessage.create(
              LocalizedStrings.StateFlushOperation_STATE_FLUSH_TERMINATED_WITH_EXCEPTION),
          re);
      return false;
    }
    return true;
  }