Class ClaimLease
A row claimed for work carries owner, claimToken and claimedAt: who
holds it, which claim this is, and since when. The last is what makes the claim a lease rather
than a flag -- a node that dies holding a row does not take the work with it, because the row can
be told from its timestamp to have been abandoned and handed to somebody else.
Only the columns live here, not the policy. What predicate wins the row, what status it moves through, how long a lease may run and what happens when one expires all differ per table and belong with the table's own code. What must not differ is the shape, so a table that grows a lease copies a name rather than a convention.
The maps are meant to be handed to GuardedUpdate.setAll(java.util.Map<java.lang.String, java.lang.Object>) alongside whatever else the
caller is writing -- the claim and the status change are one statement, or they are not atomic.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final StringThe parameterOUTLIVEDreads its lease from.static final StringTrue when a claim has outlived a lease ofLEASE_SECONDSseconds, measured by the database.static final StringColumn names, for callers writing their own predicates over them. -
Method Summary
Modifier and TypeMethodDescriptionstatic longleaseSeconds(Duration lease) The leaseOUTLIVEDmeasures against, in seconds.released()Let the row go, so the next caller to try may have it.renewed()Say the holder is still alive, without changing whose claim it is.Take the row forowner, stamped now, under a claim of its own.
-
Field Details
-
OUTLIVED
True when a claim has outlived a lease ofLEASE_SECONDSseconds, measured by the database. Says nothing about an unclaimed row: whether a nullclaimedAtcounts as available differs per table, so each predicate keeps its own answer to that.- See Also:
-
LEASE_SECONDS
The parameterOUTLIVEDreads its lease from.- See Also:
-
OWNER
Column names, for callers writing their own predicates over them.- See Also:
-
CLAIM_TOKEN
- See Also:
-
CLAIMED_AT
- See Also:
-
-
Method Details
-
taken
Take the row forowner, stamped now, under a claim of its own. -
renewed
Say the holder is still alive, without changing whose claim it is.A lease measured from when the row was claimed expires on work that simply takes longer than the lease -- and the row is then handed to somebody else while the first holder is still going. Renewing moves the clock forward so the lease measures liveness rather than duration.
-
released
Let the row go, so the next caller to try may have it. -
leaseSeconds
The leaseOUTLIVEDmeasures against, in seconds.Measured from when the row was claimed, never from when the work became due: a row claimed a moment ago but overdue by a day -- a backlog after downtime -- is being worked on, not abandoned, and reaping it would take it away from the node that holds it.
-