Class ModificationTally
java.lang.Object
org.tentackle.dbms.ModificationTally
Counter to track modifications for a class/table.
The ModificationTracker maintains a list of ModificationTally-objects, one for each tracked name.
The ModificationTracker maintains a list of ModificationTally-objects, one for each tracked name.
ModificationTallies are only used in local sessions, never remote.
- Author:
- harald
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectTransaction property to rollback pending counts.
Set toBoolean.TRUEwhen the session performed a countPending within a transaction, and that pending count must be adjusted when the transaction is rolled back. -
Constructor Summary
ConstructorsConstructorDescriptionModificationTally(DbModificationTracker tracker, String trackedName) Creates a modification counter for a given tracked name. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDeletion(Session session, IdSerialTuple tuple) Adds a deletion.
A deletion is represented by anIdSerialTuplewhile the serial is the tableserial indicating the modification count of the whole table.
If the table provides a tableserial column, deletions are memorized in theTableSerialHistory, since they cannot be derived from the table itself.voidAdds this counter to the modification table.longcountPending(Session session) Adds a pending modification count.Gets the modification PO.longgetId()Gets the ID of the counter.longGets the latest serial updated by this counter.longGets the current modification count by tablename.longGets the pending count.Gets the tracked name.booleanReturns whether this tally is retired and has no pending counts left.voidPerforms the physical pending count if pending count > 0.
This is only done if no transactions related to the data monitored by this ModificationTally are currently running.voidretire()Retires this tally.
Used by the tracker when replacing its tallies, while other threads may still hold a reference to this one.voidrollbackPending(Session session, long txNumber) Rolls back the pending count and deletions for a given session.
Avoids invalidation of the associated caches when a transaction is rolled back that caused all the modifications.voidsetLastSerial(long lastSerial) Sets the last serial.
The serial never decreases: in local client mode,performPendingCount()advances it before the flush is committed, so the committed serial read by the tracker meanwhile may still be lower.
-
Field Details
-
SESSION_COUNT_PENDING
Transaction property to rollback pending counts.
Set toBoolean.TRUEwhen the session performed a countPending within a transaction, and that pending count must be adjusted when the transaction is rolled back.
-
-
Constructor Details
-
ModificationTally
Creates a modification counter for a given tracked name.- Parameters:
tracker- the modification trackertrackedName- the tracked name
-
-
Method Details
-
getTrackedName
Gets the tracked name.- Returns:
- the symbolic name of the tracked entity
-
getDbModification
-
getId
public long getId()Gets the ID of the counter.- Returns:
- the unique id
-
countPending
Adds a pending modification count.- Parameters:
session- the session persisting the modification, null if thread-local session- Returns:
- the serial assigned to the modification, unique for this counter, 0 if retired and the modification must be counted by its successor
-
retire
public void retire()Retires this tally.
Used by the tracker when replacing its tallies, while other threads may still hold a reference to this one. From now on, no more counts are accepted, but the pending counts are still performed. -
isRetiredAndDone
public boolean isRetiredAndDone()Returns whether this tally is retired and has no pending counts left.- Returns:
- true if the tally can be dropped
-
addDeletion
Adds a deletion.
A deletion is represented by anIdSerialTuplewhile the serial is the tableserial indicating the modification count of the whole table.
If the table provides a tableserial column, deletions are memorized in theTableSerialHistory, since they cannot be derived from the table itself.- Parameters:
session- the session associated with the deletion; it determines the transaction contexttuple- the ID and negative(!) tableserial that represents the deletion to be added
-
rollbackPending
Rolls back the pending count and deletions for a given session.
Avoids invalidation of the associated caches when a transaction is rolled back that caused all the modifications.- Parameters:
session- the sessiontxNumber- the transaction number
-
getPendingCount
public long getPendingCount()Gets the pending count.- Returns:
- the pending count, 0 for none
-
setLastSerial
public void setLastSerial(long lastSerial) Sets the last serial.
The serial never decreases: in local client mode,performPendingCount()advances it before the flush is committed, so the committed serial read by the tracker meanwhile may still be lower. Setting it back would hand out the same table serial twice.- Parameters:
lastSerial- the serial
-
getLatestSerial
public long getLatestSerial()Gets the latest serial updated by this counter.- Returns:
- the latest serial from the last update plus pending count
-
performPendingCount
public void performPendingCount()Performs the physical pending count if pending count > 0.
This is only done if no transactions related to the data monitored by this ModificationTally are currently running. This also implies that all modifications have been committed to the database.The database update is performed without holding the monitor of this tally. In local client mode, the update runs within the transaction of the counting session and locks the modification rows until the end of that transaction. A thread blocked by such a lock while holding the monitor would deadlock with the lock owner counting its next modification. The counts taken over are moved to the last serial, so that the serials assigned in the meantime by
countPending(Session)continue seamlessly. If the update fails, they are given back. -
addToModificationTable
public void addToModificationTable()Adds this counter to the modification table. -
getModificationCount
public long getModificationCount()Gets the current modification count by tablename.- Returns:
- the modification count
-