Hbase put寫入源碼分析

今天有空閒時間看一下HBASE的寫入代碼java

 

MutiAction類,是一個action的container,包括get . put. delete。而且是根據region name分組的。其中核心的就是add方法,根據傳進來的region name將action分組ide

public final class MultiAction<R> {
  // TODO: This class should not be visible outside of the client package.

  // map of regions to lists of puts/gets/deletes for that region.
  public Map<byte[], List<Action<R>>> actions =
    new TreeMap<byte[], List<Action<R>>>(Bytes.BYTES_COMPARATOR);

  private long nonceGroup = HConstants.NO_NONCE;

  public MultiAction() {
    super();
  }

  /**
   * Get the total number of Actions
   *
   * @return total number of Actions for all groups in this container.
   */
  public int size() {
    int size = 0;
    for (List<?> l : actions.values()) {
      size += l.size();
    }
    return size;
  }

  /**
   * Add an Action to this container based on it's regionName. If the regionName
   * is wrong, the initial execution will fail, but will be automatically
   * retried after looking up the correct region.
   *
   * @param regionName
   * @param a
   */
  public void add(byte[] regionName, Action<R> a) {
    add(regionName, Arrays.asList(a));
  }

  /**
   * Add an Action to this container based on it's regionName. If the regionName
   * is wrong, the initial execution will fail, but will be automatically
   * retried after looking up the correct region.
   *
   * @param regionName
   * @param actionList list of actions to add for the region
   */
  public void add(byte[] regionName, List<Action<R>> actionList){
    List<Action<R>> rsActions = actions.get(regionName);
    if (rsActions == null) {
      rsActions = new ArrayList<Action<R>>(actionList.size());
      actions.put(regionName, rsActions);
    }
    rsActions.addAll(actionList);
  }

  public void setNonceGroup(long nonceGroup) {
    this.nonceGroup = nonceGroup;
  }

  public Set<byte[]> getRegions() {
    return actions.keySet();
  }

  public boolean hasNonceGroup() {
    return nonceGroup != HConstants.NO_NONCE;
  }

  public long getNonceGroup() {
    return this.nonceGroup;
  }
}  

接下來介紹AyncProcess類,該類this

待續blog

相關文章
相關標籤/搜索