7 Replies Latest reply on May 5, 2016 4:25 AM by mike.goss@citta.co.uk

    Multi-User Lock

    mike.goss@citta.co.uk

      I have an application that runs in a multi-user environment, all working well except that now I find I need to have a couple of scripts run exclusively, that is, if one user is already running the script, then a second user must wait until the first is finished, before they can start, so that I enforce the rule that only one user is ever running the script.

      I can think of several ways to implement this using a flag in a global variable, or in a shared file, but what would the experts in here recommend?

       

      Mike

        • 1. Re: Multi-User Lock
          Mike_Mitchell

          You can't do it in a global variable, or a global field, because those are user-specific. User A won't see user B's globals.

           

          You'll need to do it either via a flag in a common table somewhere (a one-record table), or use a logging function to record the start / end of the script, and not allow a user to start the script if an open (i.e., start with no end) instance is present. You'll have to be very careful about this, though; if a user force-quits or otherwise gets kicked out (like because of a network interruption), you'll have the possibility of an open instance being indicated when none actually exists.

           

          May I ask: What is the function that you want to restrict to exclusive processing? There may be another way to approach it.

          • 2. Re: Multi-User Lock
            mike.goss@citta.co.uk

            Thanks Mike, useful info there. I know about the recovery position if a user fails to complete a script, and I can handle that.

             

            Now why do want to do this?

             

            I have a number of "counters" in the system, visible to the user that must maintain an unbroken series. I tried using FileMaker to do this automagically, but there were too many circumstance where I would end up with gaps in the sequence, so I developed scripts to obtain the next in sequence, and to allow numbers tp be returned to  a pool and issued to the next requester if the user aborts a process. The problems appear where two users start working simultaneously.

             

            On your first suggestion I already have a single record table in the system that can be used to hold the flags.

            • 3. Re: Multi-User Lock
              Johan Hedman

              I would consider redo the script so that there is no way any kind of record looking would happen. If that is no option I always have a Global table with only one record that I can create a new field on that we can call Flag_ScriptName and that you do Set Field to "TimeStamp & UserName" in the beginning of the script and the you always check that field the first you do in the script and tell User 2 that this User is already running this script and started it TimeStamp. When User 1 finish script, last script step should be Set Field "".

              • 4. Re: Multi-User Lock
                Mike_Mitchell

                I'm assuming you're referring to using auto-enter serial IDs, and the gaps that result when someone deletes a record. May I suggest that, instead of trying to cobble with scripting, you simply prohibit deletion of records?

                 

                Another source of gaps is when you clone the file and import records. This can be managed. Just make sure to reset the serial IDs using Set Next Serial Value.

                 

                Or is there another circumstance where gaps are a problem?

                 

                Johan is right about the record locking issue. You can't use a true "global" table (no fields that aren't globals), because, again, each user has his own set of globals, so if you do use a single-record table and two users attempt to get there at the same time, you'll get a record lock error (301).

                • 5. Re: Multi-User Lock
                  mike.goss@citta.co.uk

                  I can’t remember the details now, but I know I worked on auto-enter Serial Ids, and there were other problems.

                   

                   

                   

                  Mike

                  • 6. Re: Multi-User Lock
                    electon

                    I don't know what the "counters" are and how crucial they are to the user at the time they're working with the data.

                    Maybe It would be an idea to have a temporary table that mimics the process and when the user is done just post the data to the actual table with a transactional script.

                     

                    You can pretty much touch the related existing data that needs to be updated so you lock those records first.

                    Once you own them you can be sure to go on and create new records as needed, and commit in one go.

                     

                    The nice thing is it runs quite fast ( record locking is reduced to minimum ), is reversible and totally under your control.

                    • 7. Re: Multi-User Lock
                      mike.goss@citta.co.uk

                      That approach has possibilities, thanks, I’ll look at that.

                       

                       

                       

                      Mike