mu_ch2.htm
来自「db.* (pronounced dee-be star) is an adva」· HTM 代码 · 共 247 行
HTM
247 行
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"><meta http-equiv="content-type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 97"><title>db.* Multi-User Guide Chapter 2</title></head><body><h1><a name="Operation"></a>Chapter 2<br>Lock Manager Operation</h1><h2><a name="Introduction"></a>2.1 Introduction</h2><p><font size="2">This chapter describes lock manager operation andexplains how to choose a protocol, how to use the lock managercommand line, and how to configure your application to use the lockmanager.</font></p><h2><a name="LMOperation"></a>2.2 Lock Manager Operation</h2><p><font size="2">The lock manager must communicate with eachapplication accessing your database files. On some platforms<b><i>db.*</i></b> can use any of several network protocols toperform this communication. You must decide which network protocolto use, and configure each of your applications to communicate withthe lock manager.</font></p><p>Your lock manager and application must be started separately. Tostart your lock manager, you must give it a name and tell it whatnetwork protocol to use. When you start your application, you mustprovide a user ID, specify a lock manager name, and tell theapplication which network protocol to use.</p><p>Not every <b><i>db.*</i></b> multi-user environment requires theuse of a separate lock manager process. The term "lock manager" isused to describe the component of <b><i>db.*</i></b> that managesfile locks, even though this may not be a separate process. Thusthe General and Internal lock managers do not use a separateprocess to coordinate data access – they use a shared file,or shared memory, to store lock status information. These lockmanagers (if present) are built into the <b><i>db.*</i></b> runtimelibrary, so there is no separate lock manager program to bestarted. For details, see the specific sections below on theGeneral lock manager and Internal lock manager.</p><p>Two <b><i>db.*</i></b> utilities are used with the lock manager:<b>console</b> and <b>lmclear</b>. The <b>console</b> programallows you to monitor and control the lock manager from a remotemachine. The <b>lmclear</b> utility is used to clean up afterunexpected communication loss between a lock manager and anapplication. Both utilities are documented in the referencechapter, Chapter 4, of this manual.</p><p>In addition, two functions provided by the <b><i>db.*</i></b>runtime library allow you to monitor the operation of the lockmanager: <b>d_lmstat</b> and <b>d_lmclear</b>. These functions aredocumented in Chapter 3 of this manual.</p><h3><a name="Protocol"></a>2.2.1 Choosing a Network Protocol</h3><p><font size="2">The platform you are running on determines yourchoices for network protocols. You must use the same networkprotocol at both ends of any communication; this means choosing anetwork protocol including its lock manager and switches, and thentelling the runtime to use the same network protocol. The tablesbelow list the available lock managers, switches, runtimeidentifiers, and platforms.</font></p><table cellspacing="0" border="0" cellpadding="7" width="355"><tr><td width="44%" valign="top"><p><b><font size="2">UNIX/Linux IPC</font></b></p></td><td width="56%" valign="top"><p><b><font size="2">Lock Manager</font></b></p></td></tr><tr><td width="44%" valign="top"><p><font size="2">UNIX Domain Sockets</font></p></td><td width="56%" valign="top"><p><font size="2">lm -mp</font></p></td></tr><tr><td width="44%" valign="top"><p><font size="2">TCP and UNIX<br>Domain Sockets</font></p></td><td width="56%" valign="top"><p><font size="2"><br>lm -mt</font></p></td></tr></table><table cellspacing="0" border="0" cellpadding="7" width="355"><tr><td width="44%" valign="top"><p><b><font size="2">Other Protocols</font></b></p></td><td width="56%" valign="top"><p><b><font size="2">Lock Manager</font></b></p></td></tr><tr><td width="44%" valign="top"><p><font size="2">General Lock Manager</font></p></td><td width="56%" valign="top"><p><font size="2">no lock manager process</font></p></td></tr><tr><td width="44%" valign="top"><p><font size="2">Internal Lock Manager</font></p></td><td width="56%" valign="top"><p><font size="2">no lock manager process</font></p></td></tr></table><p><font size="2">Once you select an appropriate network protocol,you are ready to start the lock manager.</font></p><h3><a name="starting"></a>2.2.2 Starting the Lock Manager</h3><p><font size="2">Initiate the lock manager through one of thefollowing commands:</font></p><pre><font color="#0000FF">lm [-mc] [-a <i>name</i>] [-u <i>ddd</i>] [-f <i>ddd</i>] [-q <i>ddd</i>] [-n] [-z <i>dir</i>] [-l [<i>fname</i>]]</font></pre><p><font size="2"><strong>-a<br></strong> Specifies the lockmanager name, which is case-sensitive. The default name is"lockmgr". Names other than network addresses are alpha-numericstrings up to 16 characters long. For TCP, a name of the form:<b><i>ddd</i></b> sets the listening socket number.</font></p><p><strong>-f<br></strong> Specifies the maximum number of databasefiles to be under lock manager control (for example, <b>-f 175</b>specifies a maximum of 175 files), which should be at least aslarge as the total number of files in all databases managedconcurrently by the lock manager. The default is 256 files. If settoo low, your application may receive the error statusS_UNAVAIL.</p><p><strong>-l<br></strong> Turns on error logging. You can specifya logfile name. If no filename is specified the default is"lockmgr.log". This option can significantly degrade lock managerperformance.</p><p><strong>-mc</strong><br>Specifies the network protocol. Replace c with <b>t</b> for TCP, or<strong>p</strong> for UNIX domain sockets.</p><p><strong>-n</strong><br>Instructs the process not to daemonize itself.</p><p><strong>-q</strong><br>Specifies the maximum size of the file lock request queue (forexample, <b>-q 200</b> specifies that a maximum of 200 requests canbe queued). The default is 128 entries. If this is set too small,your application may receive an error status of S_LMCERROR.</p><p><strong>-u<br></strong> Specifies the maximum number of users(<b><i>ddd</i></b>). For example, <b>-u 15</b> indicates that themaximum number of users is 15. The default is 20. Note that everyDB_TASK created with d_opentask() with the db.* runtime counts as aseparate user. If this is set too small, your application mayreceive an error status of S_UNAVAIL on <b>d_open</b>.</p><p><strong>-z<br></strong> Sets the DBTMP directory.</p><p>For example, to start a Linux TCP lock manager, with extrausers, files and queues, type the following:</p><pre><font color="#0000FF">lm -mt -u 60 -f 300 -q 190</font></pre><h3><a name="Finding"></a>2.2.3 Finding the Lock Manager from Your<i>db.*</i> Application</h3><p><font size="2">When connecting your application to the lockmanager, you must specify two things before opening the database:the network protocol, and the lock manager name. Specification ofthe protocol is discussed elsewhere in this chapter, but note thatit can affect the choice and use of a lock manager name.</font></p><p>The lock manager name will uniquely identify a single lockmanager in an environment that may host several. Normally the nameused with the <b>-a</b> parameter for the lock manager is exactlythe same as the one you will use in your application. See theTCP/IP network protocol section in this reference manual forexceptions.</p><p>There are three ways the application can specify the lockmanager name: The application can call the <b>d_lockmgr</b>function prior to calling <b>d_open</b>; set the operating systemenvironment variable LOCKMGR; or specify the lock manager name inthe <b>db.star.ini</b> file. A lock manager name set by calling<b>d_lockmgr</b> will always be used. The <b>db.star.ini</b> fileis checked only if <b>d_lockmgr</b> is not called and there is noLOCKMGR environment variable.</p><p>In the following examples, assume the lock manager was startedwith the name "lmtest".</p><p>To set the lock manager name, the application can call the<b>d_lockmgr</b> function:</p><pre><font color="#0000FF">d_lockmgr( "lmtest", task );</font></pre><p><font size="2">Or the environment variable can be set asfollows:</font></p><p>In UNIX (csh):</p><pre><font color="#0000FF">setenv <i>LOCKMGR</i> lmtest</font></pre><p><font size="2">In UNIX (sh):</font></p><pre><font color="#0000FF">LOCKMGR=lmtestexport LOCKMGR</font></pre><p><font size="2">Finally, you can set the lock manager name in the<b>db.star.ini</b> file, assigning a value to "name" in the LOCKMGRsection:</font></p><pre><font color="#0000FF">[LOCKMGR]name=lmtest</font></pre><p><font size="2">Having set the name, you will also need todesignate a network protocol to match the lock manager you areusing. The network protocol can be specified to the runtime in twoways: through an entry in <b>db.star.ini</b>, or through a call to<b>d_lockcomm</b>.</font></p><p>The constants used in both cases are listed in section 2.2.1,"Choosing a Network Protocol." A call to <b>d_lockcomm</b> takesprecedence over an entry in <b>db.star.ini</b>, just as with thelock manager name.</p><p>The following line of code chooses the TCP lock manager and mustprecede the call to <b>d_open</b>:</p><pre><font color="#0000FF">d_lockcomm( psp_lmcFind("TCP"), task );</font></pre><p><font size="2">See the example entry below, which chooses TCP asthe network protocol in <b>rdm.ini</b>:</font></p><pre><font color="#0000FF">[LOCKMGR]type=TCP</font></pre><p><font size="2">An attempt to use <b><i>db.*</i></b> in shared orexclusive mode without a call to <b>d_lockcomm</b> or an entry in<b>db.star.ini</b> produces the user error S_NOLOCKCOMM, indicatingthat the lock manager communication layer was notselected.</font></p><h3><a name="Losing"></a>2.2.4 Losing the Lock Manager from Your<i>db.*</i> Application</h3><p><font size="2">In the event of a lock manager communicationfailure, your application will receive an S_LMCERROR return codefrom the <b><i>db.*</i></b> runtime. There is no point inattempting to continue to use the database once this error hasoccurred. You should immediately call <b>d_close</b>. If the errorwas transient, you may be able to successfully call <b>d_open</b>immediately.</font></p><p><font size="2"> </font><a href="MU_Ch3.htm">NextPage</a></p></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?