Package org.apache.cassandra.db
Class LivenessInfo
- java.lang.Object
-
- org.apache.cassandra.db.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
LivenessInfocan 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 theLivenessInfoalso 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).
-
-
Field Summary
Fields Modifier and Type Field Description static LivenessInfoEMPTYstatic intEXPIRED_LIVENESS_TTLUsed as flag for representing an expired liveness.static intNO_EXPIRATION_TIMEstatic longNO_TIMESTAMPstatic intNO_TTLprotected longtimestamp
-
Constructor Summary
Constructors Modifier Constructor Description protectedLivenessInfo(long timestamp)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LivenessInfocreate(long timestamp, int nowInSec)static LivenessInfocreate(long timestamp, int ttl, int nowInSec)intdataSize()The size of the (useful) data this liveness information contains.voiddigest(Digest digest)Adds this liveness information to the provided digest.booleanequals(java.lang.Object other)static LivenessInfoexpiring(long timestamp, int ttl, int nowInSec)inthashCode()booleanisEmpty()Whether this liveness info is empty (has no timestamp).protected booleanisExpired()booleanisExpiring()Whether the info has a ttl.booleanisLive(int nowInSec)Whether that info is still live.intlocalExpirationTime()The expiration time (in seconds) if the info is expiring (NO_EXPIRATION_TIMEotherwise).booleansupersedes(LivenessInfo other)Whether this liveness information supersedes another one (that is whether is has a greater timestamp than the other or not).longtimestamp()The timestamp for this liveness info.java.lang.StringtoString()intttl()The ttl (if any) on the row primary key columns orNO_TTLif it is not expiring.longunsharedHeapSize()voidvalidate()Validate the data contained by this liveness information.static LivenessInfowithExpirationTime(long timestamp, int ttl, int localExpirationTime)LivenessInfowithUpdatedTimestamp(long newTimestamp)Returns a copy of this liveness info updated with the provided timestamp.LivenessInfowithUpdatedTimestampAndLocalDeletionTime(long newTimestamp, int newLocalDeletionTime)
-
-
-
Field Detail
-
NO_TIMESTAMP
public static final long NO_TIMESTAMP
- See Also:
- Constant Field Values
-
NO_TTL
public static final int NO_TTL
- See Also:
- Constant Field Values
-
EXPIRED_LIVENESS_TTL
public static final int EXPIRED_LIVENESS_TTL
Used as flag for representing an expired liveness. TTL per request is at most 20 yrs, so this shouldn't conflict (SeeAttributes.MAX_TTL)- See Also:
- Constant Field Values
-
NO_EXPIRATION_TIME
public static final int NO_EXPIRATION_TIME
- See Also:
- Constant Field Values
-
EMPTY
public static final LivenessInfo EMPTY
-
timestamp
protected final long timestamp
-
-
Method Detail
-
create
public static LivenessInfo create(long timestamp, int nowInSec)
-
expiring
public static LivenessInfo expiring(long timestamp, int ttl, int nowInSec)
-
create
public static LivenessInfo create(long timestamp, int ttl, int nowInSec)
-
withExpirationTime
public static LivenessInfo withExpirationTime(long timestamp, int ttl, int 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_TIMESTAMPif 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 orNO_TTLif it is not expiring. Please note that this value is the TTL that was set originally and is thus not changing.
-
localExpirationTime
public int localExpirationTime()
The expiration time (in seconds) if the info is expiring (NO_EXPIRATION_TIMEotherwise).
-
isLive
public boolean isLive(int nowInSec)
Whether that info is still live. ALivenessInfois live if it is either not expiring, or if its expiration time if afternowInSec.- 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 asConflicts#resolveRegularIf 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. If the localDeletion times are the same, prefer the lower TTL to make the merge deterministic (it is likely that the row has been rewritten with USING TTL/TIMESTAMP with an updated TTL that computes to the same local deletion time -- perhaps from rerunning a process to migrate user data between clusters or tables).- Parameters:
other- theLivenessInfoto compare this info to.- Returns:
- whether this
LivenessInfosupersedesother.
-
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
newTimestampas timestamp. If it has no timestamp however, this liveness info is returned unchanged.
-
withUpdatedTimestampAndLocalDeletionTime
public LivenessInfo withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, int newLocalDeletionTime)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
unsharedHeapSize
public long unsharedHeapSize()
- Specified by:
unsharedHeapSizein interfaceIMeasurableMemory- 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.
-
-