Smart Table Locking is a technique available to Databases that use table-locking. Record locking Database, do not need to use this feature.
The default behavior of saving or deleting is to lock and reread all open tables in the Filelist for the time required to affect the save to disk. In a structure of many related tables, with many rereads in parent, and sometimes child, tables, this can disrupt saving or deleting activities by other users seriously (it does not inhibit finding or editing activities).
DDOs support a feature named “smart filemode” that can substantially improve the performance of saves and deletes. This is controlled by a DDO property named Smart_Filemode_State. When all DDOs in a Data Dictionary structure set this property to true, only the tables that will actually participate in the operation will be locked and reread. This can significantly improve performance on the workstation performing the operation, as well as on workstations not performing the operation at that particular time (there is less network traffic).
It is very easy to implement smart filemode. When a save or delete occurs, the DDO performing this operation will scan all participating DDOs in the structure. If Smart_Filemode_State is true for all of these DDOs, the DDO will use smart-filemode locking.
By default, smart-filemode is enabled in Data Dictionary objects and no change is required. If for some reason your DDO structure cannot support smart-filemode, you may disable this by setting Smart_Filemode_State to false. You would set this inside the Construct_Object procedure in the subclass. You should avoid doing this, and should instead apply your efforts in creating a table structure that supports smart filemode.
Class Myfile_DataDictionary is a DataDictionary
Procedure Construct_Object
Forward Send Construct_Object
Set Main_File to MyFile.File_Number
Set Smart_Filemode_State to False
:
End_Procedure
:
End_Class
When a save or delete request is sent to a DDO, the following occurs:
Check if smart filemode should be used.
The Smart_Filemode_State property of all participating DDOs is checked. If any DDO’s Smart_Filemode_State property is false, smart table locking will not be employed (and the following steps will not be executed).
Record the current filemodes of all tables.
The filemodes of all tables are recorded in an internal array.
Set filemodes of all tables to read-only.
Actually, the tables are set to the value of the Smart_Filemode_For_No_Lock property (which is DF_FILEMODE_READONLY by default), thus making them exempt from locking from the program in which this is happening.
Set all participating tables’ filemodes to read/write.
The message Reset_Filemodes_For_Lock is sent to all participating DDOs, where it sets the filemodes of participating tables to the value of the Smart_Filemode_For_Lock property (the original mode, by default). Any custom augmentations occur at this point (such as marking a system table for participation).
The save/delete itself proceeds.
Only the tables with filemode other than DF_FILEMODE_READONLY are locked and reread.
The filemodes of all tables are restored to their original states.
Smart Filemode’s default behavior takes account of alias tables (filemode of alias or master_alias) that are participating in the save/delete. The master table is set to the mode of Smart_Filemode_For_Lock, but with the DF_FILEMODE_NO_LOCKS bit turned off (thus the master-alias table is always locked). The alias tables are all set according to whether they are participating in the save/delete, but with the DF_FILEMODE_NO_LOCKS bit turned on (thus alias tables are never locked). Master-alias tables are locked and reread, while participating alias tables are reread but not locked, which avoids a deadlock condition. Smart filemode uses the value of the table’s DF_FILE_ALIAS attribute to decide what to do.
The default value of Smart_Filemode_State is true. You can set the state false in individual Data Dictionary subclasses, or even DDOs. Keep in mind that smart filemode will not occur if any DDO participating in the save or delete has Smart_Filemode_State false.