Advanced Revelation Network Locking

Published ByDateVersionKnowledge LevelKeywords
Revelation Technologies28 JUL 19881.XEXPERTSHARED, EXCLUSIVE, RBASIC, R/BASIC, LOCK, UNLOCK

Local area networks allow individual workstations in the network to share data. In order to preserve the integrity of data, a locking protocol is employed to assure that only one workstation may modify a given piece of information at a time. Locks set logical 'flags' at the fileserver that are tested as other locks are attempted. The status of these flags determines if subsequent lock requests will be granted.

It is important to note that a lock does not protect data from being updated. It is simply a mechanism to maintain and report the status of files and records. Locked data may still be corrupted by simultaneous update attempts if all workstations do not adhere to the locking protocol.

Advanced Revelation supports exclusive, shared, exclusive coordinated, and exclusive shared locks. Specific networks, however, may or may not support all of these lock types. Shared locking is supported only in the Novell Netware 1.0 and Novell Advanced Netware 2.0 drivers. As of this writing, all other drivers employ on the default exclusive lock.

Lock Types Supported by Advanced Revelation An exclusive lock gives exclusive rights to locking the station. Locks are assigned on a first come, first serve basis. Any other exclusive lock attempted on an entity (record, file, etc.) already locked will be unsuccessful.

An exclusive lock is used while updating to prevent other stations from making changes simultaneously. It is important to note that file and record locks are independent. An exclusive record lock can be placed on a record in a file already locked with an exclusive lock, and vice versa.

A shared lock is uesed for 'view only' applications where the locking station will not be updating. Attempts to put an exclusive lock on an item while a shared lock is set wwill be unsuccessful. This is used to prevent updates to items being viewed by another station. Not all netwoeks support a shared lock. Refer to the network documentation for locking types available on your network.

An exclusive coordinated lock will attempt to set a shared lock on the file before setting an exclusive lock on the record. The record will be locked only if the shared file lock is successful. Any subsequent attempts to set an exclusive lock on the file will be unsuccessful.

This would typically be used to prevent updates to any record in a file by another station while the coordinated lock is set (for example, during a batch update). The exclusive coordinated lock is used in record locking only - see the chart of valid lock types. Since this lock relies upon a shared file lock, it is possible only on those networks supporting shared locks.

A shared coordinated lock will attempt to set a shared lock on the file before setting a shared lock on the record. The record will be locked only if the shared file lock is successful. Subsequent attempts to set an exclusive lock on the file will be unsuccessful.

This lock type would be used to prevent updates to any record in a file while records are being viewed. It is used in record locking onlly - see the chart of vaild lock types. Since this lock relies upon a shared file lock and a shared record lock, it is possible only on those networks supporting shared locks.

The default lock type is set by the presence or absence of the DEFAULT.LOCK record in the SYSTEM file. The contents of the record do not affect the default lock type. If the DEFAULT.LOCK record is present, the default lock type is coordinated. All record locks executed will be of the coordinated type. If the DEFAULT.LOCK is not present, no coordinated lock default is active.

The default lock type is established upon initializatin. Adding or deleting the DEFAULT.LOCK record will have no effect until a RESET or system restart is executed. The presence of the DEFAULT.LOCK record will have no effect on networks that do not support shared locks.

Locks in R/BASIC are executed by the LOCK and UNLOCK statements. The syntax is:

{UN}LOCK file.var, {rec.id},{lock.type} THEN/ELSE

The literal ALL can be used for rec.id in UNLOCK:

UNLOCK ALL

lock.type may be specified by either a mnemonic type code or a two digit type code. The mnemonic type codes are valid for file and record locks. These should not be enclosed in squotes. Valid mnemonic codes are:

Alpha CodesMeaning
XeXclusive lock
SShared lock
XCeXclusive Coordinated lock (record lock only)
SCShared Coordinated lock (record lock only)

lock.type may also be a two digit code YX where:

Y ValueMeaning
0Exclusive lock
1Shared lock
2Coordinated (Exclusive Record/Shared File)
3Coordinated (Shared Record/Shared File)
X ValueMeaning
0All (UNLOCK ALL only)
1File Lock
2Record Lock
3(Not Implemented)
4Group Lock (group number specified as rec.id)
5Overflow Frame Freelist Lock

See Chart 1, "Valid Lock Type Combinations" for valid combinations of Y and X.

If the lock attempt is successful, the THEN clause of the LOCK statement will be executed. If it is not successful, the ELSE clause will be executed. The STATUS() flag will be set according to the results of the lock attempt. STATUS() will be returned as follows:

THEN / ELSESTATUS() ValueMeaning
THEN0Successful lock-on network
ELSE0Unsuccessful lock-not stations own lock
ELSE1Unsuccessful lock - station's own lock
ELSE2Unsupported lock type

Chart 1 indicates the valid lock.type combinations for YX values outlined in the previous section.

Chart 1

Valid lock.type Combinations

                     X Values
                  0    1    2    3    4    5    6
  Values     0    no   yes  yes  no   yes  yes  yes
             1    no   yes  yes  no   no   no   no
             2    no   no   yes  no   no   no   no
             3    no   no   yes  no   no   no   no
             
             X = 0 valid only for UNLOCK

Chart 2

Chart 2 indicates the success/failure result of combinations of lock types. The columns indicate the initial lock type. The rows indicate the subsequent lock type, whose results are indicated at the point of intersection.

Note: If the DEFAULT.LOCK record is found in the SYSTEM file during initialization, all record locks will be coordinated, whether specified as such or not. In this case, only the last two columns and rows of the chart would be valid for record locks.

Success/Failure with Lock Types

                          Lock Set

                    XFL  SFL  XRL  SRL  XCRL  SCRL
             XFL     N    N    Y    Y    N     N
Lock         SFL     N    Y    Y    Y    Y     Y
Attempted    XRL     Y    Y    N    N    N     N
             SRL     Y    Y    N    Y    N     Y
             XCRL    N    Y    N    N    N     N
             SCRL    N    Y    N    Y    N     Y

Lock    Abbreviations
XLF     eXclusive File Lock
SFL     Shared File Lock
XRL     eXclusive Record Lock
SRL     Shared Record Lock
XCRL    eXclusive Coordinated Record Lock
SCRL    Shared Coordinated Record Lock
*/ executes exclusive coordinated record lock /*
OPEN FILE TO FILE.VAR ELSE STOP
LOCK FILE.VAR, REC.ID, XC THEN
  CALL MSG(REC.ID:'LOCKED','','','')
END ELSE
  CALL MSG('CANNOT LOCK -- STATUS = ':STATUS(),'','','')
END
*/ Rest of program.../*

*/ executes exclusive record lock /*
OPEN FILE TO FILE.VAR ELSE STOP
LOCK FILE.VAR, REC.ID,02 THEN
  CALL MSG(REC.ID:' LOCKED','','','')
END ELSE
  CALL MSG('CANNOT LOCK -- STATUS = ':STATUS(),'','','')
END
*/Rest of program /*

*/ executes exclusive file lock /*
OPEN FILE TO FILE.VAR ELSE STOP
LOCK FILE.VAR,"",01 THEN
  CALL MSG('LOCKED','','','')
END ELSE
  CALL MSG('CANNOT LOCK -- STATUS = ':STATUS(),'','','')
END
*/Rest of program /*

*/ executes a group lock /*
*/ group locks must be exclusive /*
OPEN FILE TO FILE.VAR ELSE STOP
GROUP.NO = 4
LOCK FILE.VAR,GROUP.NO,04 THEN
  CALL MSG('LOCKED','','','')
END ELSE
  CALL MSG('CANNOT LOCK -- STATUS = ':STATUS(),'','','')
END
*/Rest of program /*

*/ executes an Overflow Frame Freelist lock /*
*/ O.F.F. locks must be exclusive /*
OPEN FILE TO FILE.VAR ELSE STOP
LOCK FILE.VAR,"",05 THEN
  CALL MSG('LOCKED','','','')
END ELSE
  CALL MSG('CANNOT LOCK -- STATUS = ':STATUS(),'','','')
END
*/Rest of program /*
  • tips/revmedia/r2.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1