Skip to content

Operations

Xiahua Liu edited this page Jul 5, 2025 · 5 revisions

Operations

PawnDB provides a comprehensive set of operations for database transactions. Each table can choose to implement these operations based on its specific requirements.

Transaction Management

Start Transaction

Initiates a new transaction in the database.

Lock Operations

PawnDB uses Two-Phase Locking (2-PL), which requires read operations to follow lock operations.

After any lock & read operation completes:

  • Rollback Action: Append "Unlock the tuple" actions.
  • Commit Action: Append "Unlock the tuple" actions.

Blocking Lock Operations

These operations block until the record becomes available or fail after a timeout period.

Wait ANY Record with Shared/Exclusive Lock

Acquires a shared/exclusive lock on any/given available record.

Response Message
Error Code Data
No Error Locked Record Key
Timeout None

Wait ALL Records with Shared/Exclusive Lock

Acquires shared/exclusive locks on all records in the table.

Response Message
Error Code Data
No Error Locked Record Keys
Timeout None

Non-blocking Lock Operations

These operations do not block. If the record is unavailable, the database returns an error instead of waiting.

Immediately Lock A Record with Shared/Exclusive Lock (Specific Key)

Acquires an shared/exclusive lock on a record with a specific key.

Response Message
Error Code Data
No Error Record Key
Unavailable Record Key
Record Not Found Record Key

Immediately Lock ALL Records with Shared/Exclusive Lock

Acquires shared/exclusive locks on all available records in a table. Any record locked elsewhere is ignored.

Response Message
Error Code Data
No Error Record Key List

Read Operations

This operation fails if the record does not exist or is not currently locked by the transaction.

They do not generate any rollback and commit actions.

Read A Record with Key

Read a record with given key.

Response Message
Error Code Data
No Error Serialized Record Data
Not Locked Record Key
Not Found Record Key

Lock Management Operations

Yield a Shared Lock

This operation transitions a transaction from the Growing to the Shrinking phase, removing a shared lock from an acquired record.

PawnDB's strict 2-PL forbids yielding exclusive locks; such locks are only released upon commit or rollback.

Lock Table Action

The lock on the lock table will be removed immediately.

Rollback Action

The existing rollback action for the shared lock is removed.

Commit Action

The existing commit action for the shared lock is removed.

Response Message
Error Code Data
No Error Record Key
Not Locked Record Key
Not Found Record Key

Promote a Shared Lock

This operation promotes a shared lock to exclusive and can only be used in the Growing phase.

Warning: This operation should be used with caution as it does not guarantee the promotion can be completed. If two transactions call this simultaneously, it will create a deadlock. Ensure only one transaction uses this operation at any time on a given table.

Rollback Action

The existing rollback action for the shared lock is upgraded to exclusive unlock.

Commit Action

The existing commit action for the shared lock is upgraded to exclusive unlock.

Response Message
Error Code Data
No Error Record Key
Timeout Record Key

Insert Operations

These operations create records that are not visible to other transactions until the creating transaction commits.

After an insert is completed successfully, the new tuple is held by an exclusive lock automatically.

Rollback Action

Append a "Delete the inserted tuple" action.

Commit Action

Append an "Unlock the inserted tuple" action.

Response Message
Error Code Data
No Error Record Key
Timeout Record Key

Insert a Record with Given Key

Creates a record with a specified key.

PawnDB rejects duplicate keys, so this operation fails if the key already exists.

Insert a Record with Auto-Generated Key

Creates a record without specifying the key.

PawnDB automatically generates a unique key for the inserted record.

Update Operations

Records can only be updated if they are acquired with an exclusive lock.

Rollback Action

Append an "Update the tuple back to the original data" action.

Response Message
Error Code Data
No Error Record Key
Record Not Found Record Key

Update a Record with Given Key

Updates the record with the specified key.

Deletion Operations

Records can only be deleted if they are acquired with an exclusive lock.

Delete operations generate rollback data.

Delete a Record with Given Key

Removes the record with the specified key from the table. This operation is lazy in most cases, meaning the data is simply labeled as deleted, making both commit and rollback operations easier.

Rollback Action

Append an "Insert the orginal tuple back" action.

Response Message
Error Code Data
No Error Record Key
Record Not Locked Record Key
Record Not Found Record Key
Clone this wiki locally