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
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 theLivenessInfo
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
Fields Modifier and Type Field Description static LivenessInfo
EMPTY
static int
EXPIRED_LIVENESS_TTL
Used as flag for representing an expired liveness.static long
NO_EXPIRATION_TIME
static long
NO_TIMESTAMP
static int
NO_TTL
protected long
timestamp
-
Constructor Summary
Constructors Modifier Constructor Description protected
LivenessInfo(long timestamp)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LivenessInfo
create(long timestamp, int ttl, long nowInSec)
static LivenessInfo
create(long timestamp, long nowInSec)
int
dataSize()
The size of the (useful) data this liveness information contains.void
digest(Digest digest)
Adds this liveness information to the provided digest.boolean
equals(java.lang.Object other)
static LivenessInfo
expiring(long timestamp, int ttl, long nowInSec)
int
hashCode()
boolean
isEmpty()
Whether this liveness info is empty (has no timestamp).protected boolean
isExpired()
boolean
isExpiring()
Whether the info has a ttl.boolean
isLive(long nowInSec)
Whether that info is still live.long
localExpirationTime()
The expiration time (in seconds) if the info is expiring (NO_EXPIRATION_TIME
otherwise).boolean
supersedes(LivenessInfo other)
Whether this liveness information supersedes another one (that is whether is has a greater timestamp than the other or not).long
timestamp()
The timestamp for this liveness info.java.lang.String
toString()
int
ttl()
The ttl (if any) on the row primary key columns orNO_TTL
if it is not expiring.long
unsharedHeapSize()
void
validate()
Validate the data contained by this liveness information.static LivenessInfo
withExpirationTime(long timestamp, int ttl, long localExpirationTime)
LivenessInfo
withUpdatedTimestamp(long newTimestamp)
Returns a copy of this liveness info updated with the provided timestamp.LivenessInfo
withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, long newLocalDeletionTime)
LivenessInfo
withUpdatedTimestampAndLocalDeletionTime(long newTimestamp, long newLocalDeletionTime, boolean applyOverflowPolicy)
-
-
-
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 long 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, 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 orNO_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. ALivenessInfo
is 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#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
- theLivenessInfo
to compare this info to.- Returns:
- whether this
LivenessInfo
supersedesother
.
-
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
unsharedHeapSize
public long unsharedHeapSize()
- Specified by:
unsharedHeapSize
in 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.
-
-