A new function to get the current date and time, ctdbServerDateTime(), was implemented in the Java class CTSession as CTSession::GetServerDateTime();
To acquire a file (table) lock using c-treeACE call LOKREC() with a new ctLOCK_FILE mode as follows:
LOKREC(datno, ctLOCK_FILE, lockmode);
where:
ctREADREC - Acquire a file read lock. If the lock cannot be immediately acquired because a file write lock or record write locks exist on the file, then return an error.
ctREADREC_BLK - Acquire a file read lock. If the lock cannot be immediately acquired because a file write lock or record write locks exist on the file, then block until those locks are released and the lock can be acquired.
ctENABLE - Acquire a file write lock. If the lock cannot be immediately granted because file or record locks exist on the file, then return an error.
ctENABLE_BLK - Acquire a file write lock. If the lock cannot be immediately acquired because file or record locks exist on the file, then block until those locks are released and the lock can be acquired.
To free a file lock, call LOKREC() as follows:
LOKREC(datno, ctUNLOCK_FILE, 0);
A file lock request can fail with the following errors:
A record lock request that fails due to a table lock may encounter:
A connection can only acquire one file lock on a particular file at a time.
A connection can acquire a table write lock when:
and
and
A connection can acquire a table read lock when:
and
When a table write lock request is granted, the requesters write and read locks are released. All lock waiters are made to wait for the table to be unlocked.
Record lock and unlock requests for a connection that holds a table write lock have no effect.
A connection that has acquired a table read lock can promote the table read lock to a table write lock by requesting a table write lock. The request is granted if:
and
and
Notes
Table lock behavior with transactions
If a table write lock is in effect when a record is updated in a transaction, the table write lock cannot be removed until the transaction commits or aborts. Note that the call to free the table write lock returns success (NO_ERROR) and sysiocod is set to UDLK_TRN (-3) in this situation, indicating that the table write lock was not released.
A table lock cannot be released even if the transaction is restored to a savepoint that precedes the first update of a record in the locked table.
The ctMARK_XFREED and ctKEEP_XFREED transaction modes, used in calls to start and commit a transaction respectively, cause the commit to keep only the locks that were explicitly freed during the transaction. When these modes are used and a table lock is acquired before the transaction commits, the mode applies to the table lock: if a call is made to free the table lock before the transaction commits, the commit releases the table lock; otherwise, the commit keeps the table lock.
This feature is only available with the c-treeACE Server operational model.