Esempio n. 1
0
  /** @return dataNodeIndex -> [partitionKeysValueTuple+] */
  public static Set<String> ruleByJoinValueCalculate(
      RouteResultset rrs, TableConfig tc, Set<ColumnRoutePair> colRoutePairSet)
      throws SQLNonTransientException {

    String joinValue = "";

    if (colRoutePairSet.size() > 1) {
      LOGGER.warn("joinKey can't have multi Value");
    } else {
      Iterator it = colRoutePairSet.iterator();
      ColumnRoutePair joinCol = (ColumnRoutePair) it.next();
      joinValue = joinCol.colValue;
    }

    Set<String> retNodeSet = new LinkedHashSet<String>();

    Set<String> nodeSet = new LinkedHashSet<String>();
    if (tc.isSecondLevel()
        && tc.getParentTC().getPartitionColumn().equals(tc.getParentKey())) { // using
      // parent
      // rule to
      // find
      // datanode

      nodeSet = ruleCalculate(tc.getParentTC(), colRoutePairSet);
      if (nodeSet.isEmpty()) {
        throw new SQLNonTransientException(
            "parent key can't find  valid datanode ,expect 1 but found: " + nodeSet.size());
      }
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
            "found partion node (using parent partion rule directly) for child table to insert  "
                + nodeSet
                + " sql :"
                + rrs.getStatement());
      }
      retNodeSet.addAll(nodeSet);

      //			for(ColumnRoutePair pair : colRoutePairSet) {
      //				nodeSet = ruleCalculate(tc.getParentTC(),colRoutePairSet);
      //				if (nodeSet.isEmpty() || nodeSet.size() > 1) {//an exception would be thrown, if sql was
      // executed on more than on sharding
      //					throw new SQLNonTransientException(
      //							"parent key can't find  valid datanode ,expect 1 but found: "
      //									+ nodeSet.size());
      //				}
      //				String dn = nodeSet.iterator().next();
      //				if (LOGGER.isDebugEnabled()) {
      //					LOGGER.debug("found partion node (using parent partion rule directly) for child table
      // to insert  "
      //							+ dn + " sql :" + rrs.getStatement());
      //				}
      //				retNodeSet.addAll(nodeSet);
      //			}
      return retNodeSet;
    } else {
      retNodeSet.addAll(tc.getParentTC().getDataNodes());
    }

    return retNodeSet;
  }