Good morning
I would like to have clarifications regarding the mechanism for locking records in a DBF file.
Based on the lock scheme
DBFLOCK_DEFAULT 0
DBFLOCK_CLIP 1
DBFLOCK_CL53 2
DBFLOCK_VFP 3
DBFLOCK_CL53EXT 4
DBFLOCK_XHB64 5
are seen as different Loked records,
is the list of locked records memorized in the file header?
How can you reset the list of locked records?
It happens that due to network disconnections I still have files
with record locked while closing and reopening the file.
Thanks all.
Mechanism for locking records in a DBF file
- mauri.menabue
- Posts: 89
- Joined: Thu Apr 17, 2008 2:38 pm
-
- Posts: 988
- Joined: Thu Nov 24, 2005 3:01 pm
- Location: Madrid, España
Re: Mechanism for locking records in a DBF file
Hi,
File locks are not stored anywhere. They are kept in memory by the filesystem in the server OS. The dbf headers are always of the same size, they cannot change size because that is not easy to handle among several users.
In normal files, a file lock in a given region doesnt allows other users to even read that. Thats not what DBF does: You are alloed to read even a record is locked by someone else. ¿How to do that? The filesystem allows you to set locks outside the used space by the file. For locking record 1, you put a lock in the byte 1,000,000 + 1 with lenght 1. That allows the file to be read but LOGICALLY set a lock to other users. That position, starting in 1000000 in the sample. is arbitrary, and different among NTX, CDX1, CDX2, etc. In the begining, 1 000 000 may seemed ok, but now is a little bit low, falling into the real used space, so different schemes appear, that are what you see.
Reagrding your issue of lock kept after the application disconnect, it is a matter of the OS. You can inspect the Open Files in the Disk Manager and disconnect all the users that appear to have the file open even when the connection is broken. There is nothing easy to be done, except doing that manually or reboot the server.
KR
File locks are not stored anywhere. They are kept in memory by the filesystem in the server OS. The dbf headers are always of the same size, they cannot change size because that is not easy to handle among several users.
In normal files, a file lock in a given region doesnt allows other users to even read that. Thats not what DBF does: You are alloed to read even a record is locked by someone else. ¿How to do that? The filesystem allows you to set locks outside the used space by the file. For locking record 1, you put a lock in the byte 1,000,000 + 1 with lenght 1. That allows the file to be read but LOGICALLY set a lock to other users. That position, starting in 1000000 in the sample. is arbitrary, and different among NTX, CDX1, CDX2, etc. In the begining, 1 000 000 may seemed ok, but now is a little bit low, falling into the real used space, so different schemes appear, that are what you see.
Reagrding your issue of lock kept after the application disconnect, it is a matter of the OS. You can inspect the Open Files in the Disk Manager and disconnect all the users that appear to have the file open even when the connection is broken. There is nothing easy to be done, except doing that manually or reboot the server.
KR
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"