Interface TableSegment

  • All Superinterfaces:
    java.lang.AutoCloseable

    public interface TableSegment
    extends java.lang.AutoCloseable
    Defines all operations that are supported on a Table Segment. Types of updates: * Unconditional Updates will insert and/or overwrite any existing values for the given Key, regardless of whether that Key previously existed or not, and regardless of what that Key's version is. * Conditional Updates will only overwrite an existing value if the specified version matches that Key's version. If the key does not exist, the TableSegmentKey or TableSegmentEntry must have been created with TableSegmentKeyVersion.NOT_EXISTS in order for the update to succeed. * Unconditional Removals will remove a Key regardless of what that Key's version is. The operation will also succeed (albeit with no effect) if the Key does not exist. * Conditional Removals will remove a Key only if the specified TableSegmentKey.getVersion() matches that Key's version. It will also fail (with no effect) if the Key does not exist and Version is not set to TableSegmentKeyVersion.NOT_EXISTS. A note about ByteBufs. All the methods defined in this interface make use of ByteBuf either directly or via TableSegmentKey/TableSegmentEntry. It is expected that no implementation of the TableSegment interface will either retain (ByteBuf.retain()) or release (ReferenceCounted.release()) these buffers during execution. The lifecycle of these buffers should be maintained externally by the calling code, using the following guidelines: * For methods that accept externally-provided ByteBufs, the calling code should call ByteBuf.retain() prior to invoking the method on TableSegment and should invoke ReferenceCounted.release() afterwards. * For methods that return internally-generated ByteBufs (such as get(io.netty.buffer.ByteBuf)), the calling code should invoke ReferenceCounted.release() as soon as it is done with processing the result. If the result needs to be held onto for a longer duration, the caller should make a copy of it and release the ByteBuf that was provided from the call.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MAXIMUM_BATCH_KEY_COUNT
      Maximum number of Entries that can be updated, removed or retrieved with a single request.
      static int MAXIMUM_BATCH_LENGTH
      Maximum total serialization length of all keys and values for any given request.
      static int MAXIMUM_KEY_LENGTH
      The maximum length of a Table Segment Key.
      static int MAXIMUM_VALUE_LENGTH
      The maximum length of a Table Segment Value.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void close()  
      io.pravega.common.util.AsyncIterator<IteratorItem<TableSegmentEntry>> entryIterator​(io.pravega.client.tables.impl.SegmentIteratorArgs args)
      Creates a new Iterator over all the Entries in the Table Segment.
      default java.util.concurrent.CompletableFuture<TableSegmentEntry> get​(io.netty.buffer.ByteBuf key)
      Gets the latest value for the given Key.
      java.util.concurrent.CompletableFuture<java.util.List<TableSegmentEntry>> get​(java.util.Iterator<io.netty.buffer.ByteBuf> keys)
      Gets the latest values for the given Keys.
      java.util.concurrent.CompletableFuture<java.lang.Long> getEntryCount()
      Gets the number of entries in the Table Segment.
      long getSegmentId()
      Gets a value indicating the internal Id of the Table Segment, as assigned by the Controller.
      io.pravega.common.util.AsyncIterator<IteratorItem<TableSegmentKey>> keyIterator​(io.pravega.client.tables.impl.SegmentIteratorArgs args)
      Creates a new Iterator over all the Keys in the Table Segment.
      default java.util.concurrent.CompletableFuture<TableSegmentKeyVersion> put​(TableSegmentEntry entry)
      Inserts a new or updates an existing Table Entry into this Table Segment.
      java.util.concurrent.CompletableFuture<java.util.List<TableSegmentKeyVersion>> put​(java.util.Iterator<TableSegmentEntry> entries)
      Inserts new or updates existing Table Entries into this Table Segment.
      default java.util.concurrent.CompletableFuture<java.lang.Void> remove​(TableSegmentKey key)
      Removes the given key from this Table Segment.
      java.util.concurrent.CompletableFuture<java.lang.Void> remove​(java.util.Iterator<TableSegmentKey> keys)
      Removes one or more keys from this Table Segment.
    • Field Detail

      • MAXIMUM_KEY_LENGTH

        static final int MAXIMUM_KEY_LENGTH
        The maximum length of a Table Segment Key. Synchronized with io.pravega.segmentstore.contracts.tables.TableStore.MAXIMUM_KEY_LENGTH.
        See Also:
        Constant Field Values
      • MAXIMUM_VALUE_LENGTH

        static final int MAXIMUM_VALUE_LENGTH
        The maximum length of a Table Segment Value. Synchronized with io.pravega.segmentstore.contracts.tables.TableStore.MAXIMUM_VALUE_LENGTH.
        See Also:
        Constant Field Values
      • MAXIMUM_BATCH_KEY_COUNT

        static final int MAXIMUM_BATCH_KEY_COUNT
        Maximum number of Entries that can be updated, removed or retrieved with a single request.
        See Also:
        Constant Field Values
      • MAXIMUM_BATCH_LENGTH

        static final int MAXIMUM_BATCH_LENGTH
        Maximum total serialization length of all keys and values for any given request.
        See Also:
        Constant Field Values
    • Method Detail

      • put

        java.util.concurrent.CompletableFuture<java.util.List<TableSegmentKeyVersion>> put​(java.util.Iterator<TableSegmentEntry> entries)
        Inserts new or updates existing Table Entries into this Table Segment. All changes are performed atomically (either all or none will be accepted).
        Parameters:
        entries - An Iterator containing the entries to insert or update. If for at least one such entry, TableSegmentEntry.getKey()TableSegmentKey.getVersion() indicates a conditional update, this will perform an atomic Conditional Update conditioned on the server-side version for each such entry matching the provided one. See TableSegment doc for more details on Types of Updates.
        Returns:
        A CompletableFuture that, when completed, will contain a List of TableSegmentKeyVersion instances which represent the versions for the inserted/updated keys. The returned list will contain the same number of elements as are remaining in the entries iterator and the resulting versions will be in the same order. Notable exceptions:
      • remove

        default java.util.concurrent.CompletableFuture<java.lang.Void> remove​(TableSegmentKey key)
        Removes the given key from this Table Segment.
        Parameters:
        key - The Key to remove. If TableSegmentKey.getVersion() indicates a conditional update, this will perform an atomic removal conditioned on the server-side version matching the provided one. See TableSegment doc for more details on Types of Updates.
        Returns:
        A CompletableFuture that, when completed, will indicate the Key has been removed. Notable exceptions:
      • remove

        java.util.concurrent.CompletableFuture<java.lang.Void> remove​(java.util.Iterator<TableSegmentKey> keys)
        Removes one or more keys from this Table Segment. All removals are performed atomically (either all keys or no key will be removed).
        Parameters:
        keys - An Iterator containing the keys to remove. If for at least one such key, TableSegmentKey.getVersion() indicates a conditional update, this will perform an atomic removal conditioned on the server-side version matching the provided one. See TableSegment doc for more details on Types of Updates.
        Returns:
        A CompletableFuture that, when completed, will indicate that the keys have been removed. Notable exceptions:
      • get

        default java.util.concurrent.CompletableFuture<TableSegmentEntry> get​(io.netty.buffer.ByteBuf key)
        Gets the latest value for the given Key.
        Parameters:
        key - A ByteBuf representing the Key to get the value for.
        Returns:
        A CompletableFuture that, when completed, will contain the requested result. If no such Key exists, this will be completed with a null value.
      • get

        java.util.concurrent.CompletableFuture<java.util.List<TableSegmentEntry>> get​(java.util.Iterator<io.netty.buffer.ByteBuf> keys)
        Gets the latest values for the given Keys.
        Parameters:
        keys - An Iterator of ByteBuf instances representing the Keys to get values for.
        Returns:
        A CompletableFuture that, when completed, will contain a List of TableSegmentEntry instances for the requested keys. The returned list will contain the same number of elements as are remaining in the keys iterator and the results will be in the same order as the requested keys. Any keys which do not have a value will have a null entry at their index.
      • keyIterator

        io.pravega.common.util.AsyncIterator<IteratorItem<TableSegmentKey>> keyIterator​(io.pravega.client.tables.impl.SegmentIteratorArgs args)
        Creates a new Iterator over all the Keys in the Table Segment.
        Parameters:
        args - A SegmentIteratorArgs that can be used to configure the iterator.
        Returns:
        An AsyncIterator that can be used to iterate over all the Keys in this Table Segment.
      • entryIterator

        io.pravega.common.util.AsyncIterator<IteratorItem<TableSegmentEntry>> entryIterator​(io.pravega.client.tables.impl.SegmentIteratorArgs args)
        Creates a new Iterator over all the Entries in the Table Segment.
        Parameters:
        args - A SegmentIteratorArgs that can be used to configure the iterator.
        Returns:
        An AsyncIterator that can be used to iterate over all the Entries in this Table Segment.
      • getEntryCount

        java.util.concurrent.CompletableFuture<java.lang.Long> getEntryCount()
        Gets the number of entries in the Table Segment. NOTE: this is an "eventually consistent" value:
        • In-flight (not yet acknowledged) updates and removals are not included.
        • Recently acknowledged updates and removals may or may not be included (depending on whether they were conditional or not). As the index is updated (in the background), this value will eventually converge towards the actual number of entries in the Table Segment.
        Returns:
        A CompletableFuture that, when completed, will contain the number of entries in the Table Segment.
      • getSegmentId

        long getSegmentId()
        Gets a value indicating the internal Id of the Table Segment, as assigned by the Controller.
        Returns:
        The Table Segment Id.
      • close

        void close()
        Specified by:
        close in interface java.lang.AutoCloseable