drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudheeshkatkam <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-3171: handle concurrent Zookeeper node c...
Date Tue, 17 Nov 2015 00:31:48 GMT
Github user sudheeshkatkam commented on a diff in the pull request:

    https://github.com/apache/drill/pull/260#discussion_r45006978
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/zk/ZkAbstractStore.java
---
    @@ -136,7 +138,81 @@ public boolean putIfAbsent(String key, V value) {
         }
       }
     
    -  public abstract void createNodeInZK (String key, V value);
    +  /**
    +   * Default {@link CreateMode create mode} that will be used in create operations referred
in the see also section.
    +   *
    +   * @see #createOrUpdate(String, Object)
    +   * @see #createWithPrefix(String, Object)
    +   */
    +  protected abstract CreateMode getCreateMode();
    +
    +
    +  /**
    +   * Creates a node in zookeeper with the {@link #getCreateMode() default create mode}
and sets its value if supplied.
    +   *
    +   * @param path    target path
    +   * @param value   value to set, null if none available
    +   *
    +   * @see #getCreateMode()
    +   * @see #createOrUpdate(String, Object)
    +   * @see #withPrefix(String)
    +   */
    +  protected void createWithPrefix(String path, V value) {
    +    createOrUpdate(withPrefix(path), value);
    +  }
    +
    +  /**
    +   * Creates a node in zookeeper with the {@link #getCreateMode() default create mode}
and sets its value if supplied
    +   * or updates its value if the node already exists.
    +   *
    +   * Note that if node exists, its mode will not be changed.
    +   *
    +   * @param path    target path
    +   * @param value   value to set, null if none available
    +   *
    +   * @see #getCreateMode()
    +   * @see #createOrUpdate(String, Object, CreateMode)
    +   */
    +  protected void createOrUpdate(String path, V value) {
    +    createOrUpdate(path, value, getCreateMode());
    +  }
    +
    +  /**
    +   * Creates a node in zookeeper with the given mode and sets its value if supplied or
updates its value if the node
    +   * already exists.
    +   *
    +   * Note that if the node exists, its mode will not be changed.
    +   *
    +   * Internally, the method suppresses {@link org.apache.zookeeper.KeeperException.NodeExistsException}.
It is
    +   * safe to do so since the implementation is idempotent.
    +   *
    +   * @param path    target path
    +   * @param value   value to set, null if none available
    +   * @param mode    creation mode
    +   * @throws RuntimeException  throws a {@link RuntimeException} wrapping the root cause.
    +   */
    +  protected void createOrUpdate(String path, V value, CreateMode mode) {
    +    try {
    +      final boolean isUpdate = value != null;
    +      final byte[] valueInBytes = isUpdate ? config.getSerializer().serialize(value)
: null;
    +      final boolean nodeExists = framework.checkExists().forPath(path) != null;
    +      if (!nodeExists) {
    +        final ACLBackgroundPathAndBytesable<String> creator = framework.create().withMode(mode);
    +        if (isUpdate) {
    +          creator.forPath(path, valueInBytes);
    +        } else {
    +          creator.forPath(path);
    +        }
    +      } else if (isUpdate) {
    +        framework.setData().forPath(path, valueInBytes);
    +      }
    +    } catch (KeeperException.NodeExistsException ex) {
    +      logger.warn("Node already exists in Zookeeper. Skipping... -- [path: {}, mode:
{}]", path, mode);
    --- End diff --
    
    If isUpdate == true, should we try to update?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message