Package org.apache.cassandra.db
Class LivenessInfo
java.lang.Object
org.apache.cassandra.db.LivenessInfo
- All Implemented Interfaces:
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).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LivenessInfostatic final intUsed as flag for representing an expired liveness.static final longstatic final longstatic final intprotected final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LivenessInfocreate(long timestamp, int ttl, long nowInSec) static LivenessInfocreate(long timestamp, long nowInSec) intdataSize()The size of the (useful) data this liveness information contains.voidAdds this liveness information to the provided digest.booleanstatic LivenessInfoexpiring(long timestamp, int ttl, long nowInSec) inthashCode()booleanisEmpty()Whether this liveness info is empty (has no timestamp).protected booleanbooleanWhether the info has a ttl.booleanisLive(long nowInSec) Whether that info is still live.longThe 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).longThe timestamp for this liveness info.toString()intttl()The ttl (if any) on the row primary key columns orNO_TTLif it is not expiring.longvoidvalidate()Validate the data contained by this liveness information.static LivenessInfowithExpirationTime(long timestamp, int ttl, long localExpirationTime) withUpdatedTimestamp(long newTimestamp) Returns a copy of this liveness info updated with the provided timestamp.withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, long newLocalDeletionTime) withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, long newLocalDeletionTime, boolean applyOverflowPolicy)
-
Field Details
-
NO_TIMESTAMP
public static final long NO_TIMESTAMP- See Also:
-
NO_TTL
public static final int NO_TTL- See Also:
-
EXPIRED_LIVENESS_TTL
public static final int EXPIRED_LIVENESS_TTLUsed 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:
-
NO_EXPIRATION_TIME
public static final long NO_EXPIRATION_TIME- See Also:
-
EMPTY
-
timestamp
protected final long timestamp
-
-
Constructor Details
-
LivenessInfo
protected LivenessInfo(long timestamp)
-
-
Method Details
-
create
-
expiring
-
create
-
withExpirationTime
-
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 long localExpirationTime()The expiration time (in seconds) if the info is expiring (NO_EXPIRATION_TIMEotherwise). -
isLive
public boolean isLive(long 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
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
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
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, long newLocalDeletionTime) -
withUpdatedTimestampAndLocalDeletionTime
public LivenessInfo withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, long newLocalDeletionTime, boolean applyOverflowPolicy) -
toString
-
equals
-
hashCode
public int hashCode()
-