zookeeper 节点类型

zookeeper 节点类型

Intro

Zookeeper 中节点类型按持久化可分为临时节点和持久节点,按顺序性可分为顺序和无序。

Code

public sealed class CreateMode
{
    /// <summary>
    /// The znode will not be automatically deleted upon client's disconnect.
    /// </summary>
    public static readonly CreateMode PERSISTENT = new CreateMode(0, false, false);

    /// <summary>
    /// The znode will not be automatically deleted upon client's disconnect,
    /// and its name will be appended with a monotonically increasing number.
    /// </summary>
    public static readonly CreateMode PERSISTENT_SEQUENTIAL = new CreateMode(2, false, true);

    /// <summary>
    /// The znode will be deleted upon the client's disconnect.
    /// </summary>
    public static readonly CreateMode EPHEMERAL = new CreateMode(1, true, false);

    /// <summary>
    /// The znode will be deleted upon the client's disconnect, and its name
    /// will be appended with a monotonically increasing number.
    /// </summary>
    public static readonly CreateMode EPHEMERAL_SEQUENTIAL = new CreateMode(3, true, true);

    //...
}
public enum CreateMode {  
    /** 
     * 持久节点:节点创建后,会一直存在,不会因客户端会话失效而删除; 
     */  
    PERSISTENT (0, false, false),  
  
    /** 
     * 持久顺序节点:基本特性与持久节点一致,创建节点的过程中,zookeeper会在其名字后自动追加一个单调增长的数字后缀,作为新的节点名;  
     */  
    PERSISTENT_SEQUENTIAL (2, false, true),  
  
    /** 
     * 临时节点:客户端会话失效或连接关闭后,该节点会被自动删除,且不能再临时节点下面创建子节点,否则报如下错(org.apache.zookeeper.KeeperException$NoChildrenForEphemeralsException: KeeperErrorCode = NoChildrenForEphemerals for /node/child); 
     */  
    EPHEMERAL (1, true, false),  
  
    /** 
     * 临时顺序节点:基本特性与临时节点一致,创建节点的过程中,zookeeper会在其名字后自动追加一个单调增长的数字后缀,作为新的节点名;  
     */  
    EPHEMERAL_SEQUENTIAL (3, true, true); 

    //...
}

Reference

Contact

Contact me: weihanli@outlook.com

    原文作者:天天向上卡索
    原文地址: https://www.jianshu.com/p/64df03bfc200
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞