Class CollectionRmdTimestamp<DELETED_ELEMENT_TYPE>


  • @NotThreadSafe
    public class CollectionRmdTimestamp<DELETED_ELEMENT_TYPE>
    extends java.lang.Object
    This class centralizes the logic of creating a collection replication metadata schema and providing a POJO representation upon a collection replication metadata generic record. Its purpose is to abstract details of collection replication metadata schema and its generic record away for users.
    • Field Detail

      • TOP_LEVEL_TS_FIELD_NAME

        public static final java.lang.String TOP_LEVEL_TS_FIELD_NAME
        See Also:
        Constant Field Values
      • TOP_LEVEL_COLO_ID_FIELD_POS

        public static final int TOP_LEVEL_COLO_ID_FIELD_POS
        See Also:
        Constant Field Values
      • TOP_LEVEL_COLO_ID_FIELD_NAME

        public static final java.lang.String TOP_LEVEL_COLO_ID_FIELD_NAME
        See Also:
        Constant Field Values
      • PUT_ONLY_PART_LENGTH_FIELD_POS

        public static final int PUT_ONLY_PART_LENGTH_FIELD_POS
        See Also:
        Constant Field Values
      • PUT_ONLY_PART_LENGTH_FIELD_NAME

        public static final java.lang.String PUT_ONLY_PART_LENGTH_FIELD_NAME
        See Also:
        Constant Field Values
      • ACTIVE_ELEM_TS_FIELD_POS

        public static final int ACTIVE_ELEM_TS_FIELD_POS
        Client readable elements that haven't been deleted yet.
        See Also:
        Constant Field Values
      • ACTIVE_ELEM_TS_FIELD_NAME

        public static final java.lang.String ACTIVE_ELEM_TS_FIELD_NAME
        See Also:
        Constant Field Values
      • DELETED_ELEM_FIELD_NAME

        public static final java.lang.String DELETED_ELEM_FIELD_NAME
        See Also:
        Constant Field Values
      • DELETED_ELEM_TS_FIELD_POS

        public static final int DELETED_ELEM_TS_FIELD_POS
        See Also:
        Constant Field Values
      • DELETED_ELEM_TS_FIELD_NAME

        public static final java.lang.String DELETED_ELEM_TS_FIELD_NAME
        See Also:
        Constant Field Values
      • COLLECTION_TS_ARRAY_SCHEMA

        public static final org.apache.avro.Schema COLLECTION_TS_ARRAY_SCHEMA
    • Constructor Detail

      • CollectionRmdTimestamp

        public CollectionRmdTimestamp​(org.apache.avro.generic.GenericRecord collectionRmdRecord)
    • Method Detail

      • getTopLevelFieldTimestamp

        public long getTopLevelFieldTimestamp()
      • getTopLevelColoID

        public int getTopLevelColoID()
      • getPutOnlyPartLength

        public int getPutOnlyPartLength()
      • isInPutOnlyState

        public boolean isInPutOnlyState()
      • getActiveElementTimestamps

        public java.util.List<java.lang.Long> getActiveElementTimestamps()
      • removeActiveTimestampsLowerOrEqualTo

        public int removeActiveTimestampsLowerOrEqualTo​(long minTimestamp)
        Parameters:
        minTimestamp - Remove all active timestamps that are smaller or equal to minTimestamp.
        Returns:
        number of active timestamps removed from the beginning (index 0).
      • removeDeletionInfoWithTimestampsLowerOrEqualTo

        public void removeDeletionInfoWithTimestampsLowerOrEqualTo​(long minTimestamp)
      • getDeletedElementTimestamps

        public java.util.List<java.lang.Long> getDeletedElementTimestamps()
      • setTopLevelFieldTimestamp

        public void setTopLevelFieldTimestamp​(long topLevelFieldTimestamp)
      • setTopLevelColoID

        public void setTopLevelColoID​(int topLevelColoID)
      • setPutOnlyPartLength

        public void setPutOnlyPartLength​(int putOnlyPartLength)
      • setActiveElementTimestamps

        public void setActiveElementTimestamps​(java.util.List<java.lang.Long> collectionActiveTimestamps)
      • setDeletedElementsAndTimestamps

        public void setDeletedElementsAndTimestamps​(java.util.List<DELETED_ELEMENT_TYPE> deletedElements,
                                                    java.util.List<java.lang.Long> deletedTimestamps)
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • createCollectionTimeStampSchema

        public static org.apache.avro.Schema createCollectionTimeStampSchema​(java.lang.String metadataRecordName,
                                                                             java.lang.String namespace,
                                                                             org.apache.avro.Schema elemSchema)
        Create a RECORD that keeps track of collection field's update metadata. There are 4 sub-fields here. TOP_LEVEL_TS_FIELD_NAME The top level timestamp. This field is updated when the whole collections is replaced/removed (via partial update) ACTIVE_ELEM_TS_FIELD_NAME A timestamp array that holds the timestamps for each elements in the collection. DELETED_ELEM_FIELD_NAME A tombstone array that holds deleted elements. If this collection is an ARRAY, the array will hold elements the same type as the original array. If this collection is a MAP, the array will hold string elements (keys in the original map). DELETED_ELEM_TS_FIELD_NAME A timestamp array that holds the timestamps for each deleted element in the tombstone array
         Example value schema:
         {
           "type" : "record",
           "name" : "testRecord",
           "namespace" : "avro.example",
           "fields" : [ {
             "name" : "intArray",
             "type" : {
               "type" : "array",
               "items" : "int"
             },
             "default" : [ ]
           } ]
         }
        
         Corresponding TS schema
         {
           "type" : "record",
           "name" : "ARRAY_CollectionTimestampMetadata_1",
           "doc" : "structure that maintains all of the necessary metadata to perform deterministic conflict resolution on collection fields.",
           "fields" : [ {
             "name" : "topLevelFieldTimestamp",
             "type" : "long",
             "doc" : "Timestamp of the last partial update attempting to set every element of this collection.",
             "default" : 0
           },{
             "name" : "topLevelColoID",
             "type" : "int",
             "doc" : "ID of the colo from which the last successfully applied partial update was sent.",
             "default" : -1
           },{
             "name" : "putOnlyPartLength",
             "type" : "int",
             "doc" : "Length of the put-only part of the collection which starts from index 0.",
             "default" : 0
           },
           {
             "name" : "activeElementsTimestamps",
             "type" : {
               "type" : "array",
               "items" : "long"
             },
             "doc" : "Timestamps of each active element in the user's collection. This is a parallel array with the user's collection.",
             "default" : [ ]
           }, {
             "name" : "deletedElementsIdentities",
             "type" : {
               "type" : "array",
               "items" : "int"
             },
             "doc" : "The tomestone array of deleted elements. This is a parallel array with deletedElementsTimestamps",
             "default" : [ ]
           }, {
             "name" : "deletedElementsTimestamps",
             "type" : {
               "type" : "array",
               "items" : "long"
             },
             "doc" : "Timestamps of each deleted element. This is a parallel array with deletedElementsIdentity.",
             "default" : [ ]
           }
         }