Class LivenessInfo

  • All Implemented Interfaces:
    IMeasurableMemory

    public class LivenessInfo
    extends java.lang.Object
    implements IMeasurableMemory
    Stores the information relating to the liveness of the primary key columns of a row.

    A LivenessInfo can first be empty. If it isn't, it contains at least a timestamp, which is the timestamp for the row primary key columns. On top of that, the info can be ttl'ed, in which case the LivenessInfo also has both a ttl and a local expiration time.

    Please note that if a liveness info is ttl'ed, that expiration is only an expiration of the liveness info itself (so, of the timestamp), and once the info expires it becomes EMPTY. But if a row has a liveness info which expires, the rest of the row data is unaffected (of course, the rest of said row data might be ttl'ed on its own but this is separate).

    • Constructor Detail

      • LivenessInfo

        protected LivenessInfo​(long timestamp)
    • Method Detail

      • create

        public static LivenessInfo create​(long timestamp,
                                          long nowInSec)
      • expiring

        public static LivenessInfo expiring​(long timestamp,
                                            int ttl,
                                            long nowInSec)
      • create

        public static LivenessInfo create​(long timestamp,
                                          int ttl,
                                          long nowInSec)
      • withExpirationTime

        public static LivenessInfo withExpirationTime​(long timestamp,
                                                      int ttl,
                                                      long localExpirationTime)
      • isEmpty

        public boolean isEmpty()
        Whether this liveness info is empty (has no timestamp).
        Returns:
        whether this liveness info is empty or not.
      • timestamp

        public long timestamp()
        The timestamp for this liveness info.
        Returns:
        the liveness info timestamp (or NO_TIMESTAMP if the info is empty).
      • isExpiring

        public boolean isExpiring()
        Whether the info has a ttl.
      • ttl

        public int ttl()
        The ttl (if any) on the row primary key columns or NO_TTL if it is not expiring. Please note that this value is the TTL that was set originally and is thus not changing.
      • localExpirationTime

        public long localExpirationTime()
        The expiration time (in seconds) if the info is expiring (NO_EXPIRATION_TIME otherwise).
      • isLive

        public boolean isLive​(long nowInSec)
        Whether that info is still live. A LivenessInfo is live if it is either not expiring, or if its expiration time if after nowInSec.
        Parameters:
        nowInSec - the current time in seconds.
        Returns:
        whether this liveness info is live or not.
      • digest

        public void digest​(Digest digest)
        Adds this liveness information to the provided digest.
        Parameters:
        digest - the digest to add this liveness information to.
      • validate

        public void validate()
        Validate the data contained by this liveness information.
        Throws:
        MarshalException - if some of the data is corrupted.
      • dataSize

        public int dataSize()
        The size of the (useful) data this liveness information contains.
        Returns:
        the size of the data this liveness information contains.
      • supersedes

        public boolean supersedes​(LivenessInfo other)
        Whether this liveness information supersedes another one (that is whether is has a greater timestamp than the other or not). If timestamps are the same and none of them are expired livenessInfo, livenessInfo with greater TTL supersedes another. It also means, if timestamps are the same, ttl superseders no-ttl. This is the same rule as Conflicts#resolveRegular If timestamps are the same and one of them is expired livenessInfo. Expired livenessInfo supersedes, ie. tombstone supersedes. If timestamps are the same and both of them are expired livenessInfo(Ideally it shouldn't happen), greater localDeletionTime wins.
        Parameters:
        other - the LivenessInfo to compare this info to.
        Returns:
        whether this LivenessInfo supersedes other.
      • isExpired

        protected boolean isExpired()
      • withUpdatedTimestamp

        public LivenessInfo withUpdatedTimestamp​(long newTimestamp)
        Returns a copy of this liveness info updated with the provided timestamp.
        Parameters:
        newTimestamp - the timestamp for the returned info.
        Returns:
        if this liveness info has a timestamp, a copy of it with newTimestamp as timestamp. If it has no timestamp however, this liveness info is returned unchanged.
      • withUpdatedTimestampAndLocalDeletionTime

        public LivenessInfo withUpdatedTimestampAndLocalDeletionTime​(long newTimestamp,
                                                                     long newLocalDeletionTime)
      • withUpdatedTimestampAndLocalDeletionTime

        public LivenessInfo withUpdatedTimestampAndLocalDeletionTime​(long newTimestamp,
                                                                     long newLocalDeletionTime,
                                                                     boolean applyOverflowPolicy)
      • toString

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

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

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

        public long unsharedHeapSize()
        Specified by:
        unsharedHeapSize in interface IMeasurableMemory
        Returns:
        the amount of on-heap memory retained by the object that might be reclaimed if the object were reclaimed, i.e. it should try to exclude globally cached data where possible, or counting portions of arrays that are referenced by the object but used by other objects only (e.g. slabbed byte-buffers), etc.