IDAuthority

来源:互联网 发布:淘宝男士防晒衣 编辑:程序博客网 时间:2024/06/01 08:50

Let’s look at the class used in IDAuthority.

public interface IDBlockSizer {    /**     * The size of the id block to be returned by calls {@link com.baidu.hugegraph.diskstorage.IDAuthority#getIDBlock(int,int, Duration)}     * for the given id namespace.     * In other words, for the returned array of the above mentioned call, it must hold that the difference between the second     * and first value is equal to the block size returned by this method (for the same partition id).     *     * @param idNamespace     * @return     */    public long getBlockSize(int idNamespace);    /**     * Returns the upper bound for any id block returned by {@link com.baidu.hugegraph.diskstorage.IDAuthority#getIDBlock(int,int, Duration)}     * for the given id namespace.     * In other words, it must hold that the second value of the returned array is smaller than this value for the same partition id.     *     * @param idNamespace     * @return     */    public long getIdUpperBound(int idNamespace);}
  • class IDBlock
/** * Represents a block of ids. {@link #numIds()} return how many ids are in this block and {@link #getId(long)} retrieves * the id at the given position, where the position must be smaller than the number of ids in this block (similar to array access). * </p> * Any IDBlock implementation must be completely thread-safe. * */public interface IDBlock {    /**     * Number of ids in this block.     *     * @return     */    public long numIds();    /**     * Returns the id at the given index. Index must be non-negative and smaller than {@link #numIds()}.     *     * @param index     * @return     */    public long getId(long index);}
  • KeyRange
/** * A range of bytes between start and end where start is inclusive and end is exclusive. * */public class KeyRange {    private final StaticBuffer start;    private final StaticBuffer end;    public KeyRange(StaticBuffer start, StaticBuffer end) {        this.start = start;        this.end = end;    }    @Override    public String toString() {        return String.format("KeyRange(left: %s, right: %s)", start, end);    }    public StaticBuffer getAt(int position) {        switch(position) {            case 0: return start;            case 1: return end;            default: throw new IndexOutOfBoundsException("Exceed length of 2: " + position);        }    }    public StaticBuffer getStart() {        return start;    }    public StaticBuffer getEnd() {        return end;    }}

Now, lets see idAuthority.

idAuthority = new ConsistentKeyIDAuthority(idStore, storeManager, config);

ConsistentKeyIDAuthority Architecture
ConsistentKeyIDAuthority Architecture

/** * Handles the unique allocation of ids. Returns blocks of ids that are * uniquely allocated to the caller so that * they can be used to uniquely identify elements. */public interface IDAuthority {
  • getIDBlock
/**     * Returns a block of new ids in the form of {@link IDBlock}. It is guaranteed that     * the block of ids for the particular partition id is uniquely assigned,     * that is, the block of ids has not been previously and will not     * subsequently be assigned again when invoking this method on the local or     * any remote machine that is connected to the underlying storage backend.     * <p/>     * In other words, this method has to ensure that ids are uniquely assigned     * per partition.     * <p/>     * It is furthermore guaranteed that any id of the returned IDBlock is smaller than the upper bound     * for the given partition as read from the {@link IDBlockSizer} set on this IDAuthority and that the     * number of ids returned is equal to the block size of the IDBlockSizer.     *     * @param partition     *            Partition for which to request an id block     * @param idNamespace namespace for ids within a partition     * @param timeout     *            When a call to this method is unable to return a id block     *            before this timeout elapses, the implementation must give up     *            and throw a {@code StorageException} ASAP     * @return a range of ids for the {@code partition} parameter     */    public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout)            throws BackendException;
  /**     * Returns the lower and upper limits of the key range assigned to this local machine as an array with two entries.     *     * @return     * @throws BackendException     */    public List<KeyRange> getLocalIDPartition() throws BackendException;
  • setIDBlockSizer
 /**     * Sets the {@link IDBlockSizer} to be used by this IDAuthority. The IDBlockSizer specifies the block size for     * each partition guaranteeing that the same partition will always be assigned the same block size.     * <p/>     * The IDBlockSizer cannot be changed for an IDAuthority that has already been used (i.e. after invoking {@link #getIDBlock(int)}.     *     * @param sizer The IDBlockSizer to be used by this IDAuthority     */    public void setIDBlockSizer(IDBlockSizer sizer);
  • close
    /**     * Closes the IDAuthority and any underlying storage backend.     *     * @throws BackendException     */    public void close() throws BackendException;
  • getUniqueID
    /**     * Return the globally unique string used by this {@code IDAuthority}     * instance to recognize its ID allocations and distinguish its allocations     * from those belonging to other {@code IDAuthority} instances.     *     * This should normally be the value of     * {@link GraphDatabaseConfiguration#UNIQUE_INSTANCE_ID}, though that's not     * strictly technically necessary.     *     * @return unique ID string     */    public String getUniqueID();
  • supportsInterruption
 /**     * Whether {@link #getIDBlock(int, int, Duration)} may be safely interrupted.     *     * @return true if interruption is allowed, false if it is not     */    public boolean supportsInterruption();
0 0
原创粉丝点击