use FLOCK()

Re: use FLOCK()

Postby hmpaquito » Fri Jan 30, 2015 5:20 pm

James Bott wrote:I was referring to a hang, not a crash. When the computer hangs the file is still locked. It will only be unlocked when the computer is rebooted or turned off. I'm not sure there is anyway to handle a hang.


Application is hang... All in application is hang... so it's very normally handles files too hang... where is a problem ?
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: use FLOCK()

Postby James Bott » Fri Jan 30, 2015 5:32 pm

Hmpaquito,

Application is hang... All in application is hang... so it's very normally handles files too hang... where is a problem ?


I'm not sure I understand what you are saying. Did you mean that if the application hangs it will always hang on all users computers at the same time? If so, I don't think I have ever seen this.

By "hang" I mean that one computer freezes up and won't respond. This can happen due to a number of reasons having nothing to do with the app that is currently in focus. And as long as that computer is frozen, any semaphone lock files would remain.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: use FLOCK()

Postby hmpaquito » Fri Jan 30, 2015 6:10 pm

Code: Select all  Expand view
And as long as that computer is frozen, any semaphone lock files would remain.


Yes, and...

If computer is frozen, application is frozen, all in application is frozen, dbfs frozen, conexion frozen, gdis recurses frozen, application handles files are frozen and of course semaphore files is frozen... where is the problem ?
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: use FLOCK()

Postby James Bott » Fri Jan 30, 2015 8:43 pm

The problem is that as long as the computer is frozen, no one else on the network can access the locked file(s).

I'm not saying this is a big issue, but I have had clients that just left it frozen until I came in to fix it. This left everyone else without access to the file. It only happens rarely, but you mentioned your system handled it, so I was curious if you had a trick. The only trick is to reboot or turn it off. At least with your system other users can still tell whose computer has the file locked so they can investigate.
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: use FLOCK()

Postby mgsoft » Fri Jan 30, 2015 8:59 pm

Hello,

And how do You Manage record locks?.

Thank You
Saludos,

Eduardo
User avatar
mgsoft
 
Posts: 422
Joined: Mon Aug 17, 2009 12:18 pm
Location: España

Re: use FLOCK()

Postby James Bott » Fri Jan 30, 2015 10:02 pm

Eduardo,

Did you mean file locks or record locks?

Either way, I use database objects. I wrote a subclass to TDatabase which adds many enhancements.

I added some enhancements for record locking including automatic retries if a record is already locked. Personally, I aways use optimistic locking so a record is only locked for a second, so locked records are not really an issue.

I rarely use file locking and I have not really needed to know who has a file locked. I am interested in this topic since it would be easy to add this feature to my database class. For anyone currently using a database class, this would then only require a recompile to add the new feature to an existing program. This is one of the great advantages of using classes.

If you are interested in more info about my TData class go here:

http://gointellitech.com/program.htm

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: use FLOCK()

Postby hmpaquito » Fri Jan 30, 2015 11:19 pm

James Bott wrote:The problem is that as long as the computer is frozen, no one else on the network can access the locked file(s).

I'm not


what is a blocked file ? Is it a file opened in shared mode ?
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: use FLOCK()

Postby James Bott » Fri Jan 30, 2015 11:29 pm

You used the term "blocked," I used the term "locked." I presumed by blocked you meant locked. They are very similar. A locked file blocks write access. Maybe this is a language translation thing.

From the Clipper help file:

FLOCK() is a database function used in network environments to lock an
open and shared database file, preventing other users from updating the
file until the lock is released. Records in the locked file are
accessible for read-only operations.


I am getting the impression that I offended you, Hmpaquito, and if so, it was not intentional. I was just asking about the hang issue to find out how you handled it. I appreciate you sharing your code, and I was not criticizing it.

So, if I did offend you, I apologize.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: use FLOCK()

Postby Gale FORd » Fri Jan 30, 2015 11:43 pm

File locks are issued all the time behind the scenes. Every skip on a shared dbf with an index locks the index file until after skip is complete. This is to ensure that the index tree has not changed until after the next record is resolved. Having the locks cached is not the best idea when each users machine is managing the indexes. If you are using client/server then there is no problem.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: use FLOCK()

Postby hmpaquito » Sat Jan 31, 2015 7:50 am

I am getting the impression that I offended you

no problem at all

My before code shows how to file system handle can lock or only mark as used... all depend... the key is how use it. Other key is open files of named system 'in use mark' in fopen shared mode. This permit to other users collect info from all users.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests