ConsistentKeyIDAuthority

来源:互联网 发布:mac unix 可执行文件 编辑:程序博客网 时间:2024/05/29 08:21

ConsistentKeyIDAuthority Architecture

ConsistentKeyIDAuthority Architecture

IDAuthority Reference

AbstractIDAuthority

/** * Base Class for {@link IDAuthority} implementations. * Handles common aspects such as maintaining the {@link IDBlockSizer}  * and shared configuration options * */public abstract class AbstractIDAuthority implements IDAuthority {

The fields in AbstractIDAuthority.

/* This value can't be changed without either      * corrupting existing ID allocations or taking      * some additional action to prevent such      * corruption.      */    protected static final long BASE_ID = 1;    protected final Duration idApplicationWaitMS;    protected final String uid;    protected final byte[] uidBytes;    protected final String metricsPrefix;    private IDBlockSizer blockSizer;    private volatile boolean isActive;
  public AbstractIDAuthority(Configuration config) {        this.uid = config.get(UNIQUE_INSTANCE_ID);        this.uidBytes = uid.getBytes();        this.isActive = false;        this.idApplicationWaitMS =                config.get(GraphDatabaseConfiguration.IDAUTHORITY_WAIT);        this.metricsPrefix = GraphDatabaseConfiguration.getSystemMetricsPrefix();    }
@Override    public synchronized void setIDBlockSizer(IDBlockSizer sizer) {        Preconditions.checkNotNull(sizer);        if (isActive) throw new IllegalStateException("IDBlockSizer cannot be changed after IDAuthority is in use");        this.blockSizer = sizer;    }
/**     * Returns a byte buffer representation for the given partition id     * @param partition     * @return     */    protected StaticBuffer getPartitionKey(int partition) {        return BufferUtil.getIntBuffer(partition);    }
/**     * Returns the block size of the specified partition as determined by the configured {@link IDBlockSizer}.     * @param idNamespace     * @return     */    protected long getBlockSize(final int idNamespace) {        Preconditions.checkArgument(blockSizer != null, "Blocksizer has not yet been initialized");        isActive = true;        long blockSize = blockSizer.getBlockSize(idNamespace);        Preconditions.checkArgument(blockSize>0,"Invalid block size: %s",blockSize);        Preconditions.checkArgument(blockSize<getIdUpperBound(idNamespace),                "Block size [%s] cannot be larger than upper bound [%s] for partition [%s]",blockSize,getIdUpperBound(idNamespace),idNamespace);        return blockSize;    }
    protected long getIdUpperBound(final int idNamespace) {        Preconditions.checkArgument(blockSizer != null, "Blocksizer has not yet been initialized");        isActive = true;        long upperBound = blockSizer.getIdUpperBound(idNamespace);        Preconditions.checkArgument(upperBound>0,"Invalid upper bound: %s",upperBound);        return upperBound;    }

ConsistentKeyIDAuthority

/** * {@link com.baidu.hugegraph.diskstorage.IDAuthority} implementation * assuming that the backing store supports consistent key operations. * <p/> * ID blocks are allocated by first applying for an id block, waiting for a * specified period of time and then checking that the application was the first * received for that particular id block. If so, the application is considered * successful. If not, some other process won the application and a new * application is tried. * <p/> * The partition id is used as the key and since key operations are considered * consistent, this protocol guarantees unique id block assignments. * <p/> */public class ConsistentKeyIDAuthority extends AbstractIDAuthority implements BackendOperation.TransactionalProvider {
0 0
原创粉丝点击