📄 lockingandmulti_useraccess.htm
字号:
<html>
<head>
<title>Locking and Multi-User Access</title>
</head>
<!--#include virtual="/inc/header.php"-->
<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF">
<tr>
<td align="left">
<span style="font-family:Helvetica,Arial; font-size:12pt; color:#000000"><b>Locking and Multi-User Access
<br>
</b></span>
</td>
<td align="right">
<font face="Arial" size="2">
<a href="sortingrecordswithindexes.htm">Previous</a>
<a href="overview.htm">Top</a>
<a href="transactions.htm">Next</a>
</font>
</td>
</tr>
</table>
<br><br>
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">
<br>
Absolute Database is designed to do simplify development of multi-user database application as much as possilbe.
<br>
Locking is performed only when database is open in multi-user mode. To gain multi-user access to a database, <b>set TABSDatabase.</b><b><a href=tabsdatabase_multiuser.htm>MultiUser</a></b><b> to True</b> before opening a database file.
<br>
<br>
<b>Locking
<br>
<br>
</b>Absolute Database uses locking to ensure transactional integrity and database consistency. Locking prevents users from reading data being changed by other users, and prevents multiple users from changing the same data at the same time. If locking is not used, data within the database may become logically incorrect, and queries executed against that data may produce unexpected results.
<br>
<br>
<br>
<b>How Absolute Database Engine Performs Locking</b>
<br>
<br>
Absolute Database acquire locks using calls to the operating system, which could be Windows 95/98/ME/NT/2000/XP. If database file is placed on file sever and accessed via network, these calls are handled by the client operating system to the file server's operating system, which could be Netware, Windows NT, Windows 95/98/ME, etc.
<br>
<a href=tabsdatabase_maxconnections.htm>MaxConnections</a> property of TABSDatabase allows to adjust the number of maximal users the database engine can handle simultaneously.This number should be specified before the database file creation to allocate locking area in a database file.
<br>
Set <i>MaxConnections</i> so that it is high enough to avoid exceptions when the large number of users are connecting to the database, but low enough not to degrade performance too severely by forcing database engine to check too many simultaneous connections. The larger value of <i>MaxConnections</i> also causes the larger size of a database file.
<br>
<br>
<br>
<b>Locking Architecture
<br>
</b>
<br>
Absolute Database uses locks to implement pessimistic concurrency control among multiple users performing modifications in a database at the same time. Database engine manages both transactions and locks on a per connection basis. For example, if an application opens two database connections using two TABSDatabase components, locks acquired by one connection cannot be shared with the other connection. Neither connection can acquire locks that would conflict with locks held by the other connection.
<br>
<br>
Absolute Database locks are applied at various levels of granularity in the database. Locks can be acquired on rows, tables, or databases. Absolute Database dynamically determines the appropriate level at which to place locks for each operation. The level at which locks are applied does not have to be specified by users and needs no configuration by administrator. Each instance of Absolute Database engine ensures that locks granted at one level of granularity respect locks granted at another level. For example, if <b>User1</b> attempts to acquire an update lock on a row, the instance of Absolute Database also attempts to acquire intent update lock on the table. If <b>User2</b> has an exclusive lock at table level, <b>User1</b> is blocked from acquiring locks until the lock held by <b>User2</b> is freed.
<br>
<br>
<br>
<b>Record Locks
<br>
<br>
</b>Absolute Database engine uses record locks to prevent multiple users or threads from editing, deleting or posting the same record at the same time. Record lock blocks other attempts of locking this record, but do not block read of the locked record.
<br>
<br>
Record locking is important in the following opearations:
<br>
<br>
<table border="0" cellpadding="1"><tr><td align="left" valign="top" width="116">
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Inserting a record
<br>
</span></td><td align="left" valign="top" width="553">
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">When calling Insert/Append method of TABSTable or TABSQuery, nothing is locked until Post method is called. While posting a new record only intension table lock is acquired to prevent table from simultaneous postings of another users. If table lock fails, then a ABS_ERR_TABLE_LOCKED error will be triggered by the database engine. You can handle this error using TABSTable.OnPostError, see Absolute DB Reference and source code of DBManager utility for more details.
<br>
</span></td></tr><tr><td align="left" valign="top" width="116">
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Updating a record
<br>
</span></td><td align="left" valign="top" width="553">
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">When calling Edit method of TABSTable or TABSQuery, database engine attempts to acquire intension table lock and then record lock and then database engine checks if the record was not modified or deleted by another user since last read. If table lock fails, then a ABS_ERR_TABLE_LOCKED error will be triggered by the database engine. If record lock fails, then a ABS_ERR_RECORD_LOCKED error will be triggered by the database engine. If record was modified since last read, then a ABS_ERR_UPDATE_RECORD_MODIFIED error will be triggered by the database engine. If record was deleted since last read, then a ABS_ERR_UPDATE_RECORD_DELETED error will be triggered by the database engine. You can handle ths error using TABSTable.OnEditError, see Absolute DB Reference and source code of DBManager utility for more details.
<br>
</span></td></tr><tr><td align="left" valign="top" width="116">
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">Deleting a record
<br>
</span></td><td align="left" valign="top" width="553">
<span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">When calling Delete method of TABSTable or TABSQuery, database engine attempts to acquire intension table lock and then record lock and then database engine checks if the record was not modified or deleted by another user since last read. If table lock fails, then a ABS_ERR_TABLE_LOCKED error will be triggered by the database engine. If record lock fails, then a ABS_ERR_RECORD_LOCKED error will be triggered by the database. If record was modified since last read, then a ABS_ERR_DELETE_RECORD_MODIFIED error will be triggered by the database engine. If record was deleted since last read, then a ABS_ERR_DELETE_RECORD_DELETED error will be triggered by the database engine. You can handle ths error using TABSTable.OnDeleteError, see Absolute DB Reference and source code of DBManager utility for more details.
<br>
</span></td></tr></table>
<br>
<br>
<br>
<b>Table Locks
<br>
</b>
<br>
Absolute Database engine acquires table locks internally and determines the appropriate level at which to place locks for each operation.
<br>
There are several lock modes: shared, update, exclusive and intent. The lock mode indicates the level of dependency the connection has on the locked object. Absolute Database controls how the lock modes interact. For example, an exclusive lock cannot be obtained if other connections hold shared locks on the resource.
<br>
<br>
<br>
<b>Lock Time-out
<br>
<br>
</b>Locks are held for the length of time needed to protect the resource at the level requested.
<br>
If a connection attempts to acquire a lock that conflicts with a lock held by another connection, the connection attempting to acquire the lock is blocked until:
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">The conflicting lock is freed and the connection acquires the lock it requested.
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td width="14"><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"><font face="Symbol" size="2" color="#000000">·</font></span></td><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">The time-out interval for the connection expires.
<br>
</span></td></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000"></span></td><td></td></tr></table><span style="font-family:Helvetica,Arial; font-size:10pt; color:#000000">The default time-outs: 1.5 second for record level locking, 90 seconds for table locking.
<br>
Registered users of Absolute Database with source code can customize locking time-outs.
<br>
<br>
</span></span>
<!--#include virtual="/inc/footer.php"-->
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -