技术

zookeeper源码学习-Zxid

This post is currently available in Chinese only. The original text follows.Open the Chinese page →

zxid计算的相关,其中高32位存储Epoch的id,低32位存储事务的计数器

public class ZxidUtils {

    public static long getEpochFromZxid(long zxid) {
        return zxid >> 32L;
    }
    public static long getCounterFromZxid(long zxid) {
        return zxid & 0xffffffffL;
    }
    public static long makeZxid(long epoch, long counter) {
        return (epoch << 32L) | (counter & 0xffffffffL);
    }
    public static String zxidToString(long zxid) {
        return Long.toHexString(zxid);
    }

}