Sqlite locks errors and other good stuff…

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Sqlite locks errors and other good stuff…

  • Creator
    Topic
  • #53295
    Gary Atkinson
    Participant

      Hi all-

      We are doing some sqlite implementations here and I we have had some challanges when it comes to database locks and error handling.  I am curious to know what others have done with these issues?  BTW, we are on 5.6 on a UNIX platform.

      thx,

      Gary  8)

    Viewing 8 reply threads
    • Author
      Replies
      • #77177
        Doug Essner
        Participant

          We are on AIX with CL5.8

          Use “DBCMD timeout 10000”  to retry for 10000 milliseconds if/when database is locked.

        • #77178
          Gary Atkinson
          Participant

            What do you do if a timeout is reached?

          • #77179
            Jeff Dinsmore
            Participant

              You can use the busy method.

              Open the database:

               sqlite3 $dbName $dbFilePath -readonly $readonly

              Assign the procedure to run if busy:

               $dbName busy $dbBusyProc

              Our typical wait/busy proc looks like this

              Code:

              proc crmcSmatIndexDb::openWait { a } {

              variable nsDbName

               set waitMsec 2000
               
              # will only email if attempt number (a) is greater than zero – added 09/22/2011 – jld
              #   first attempt is zero and increments from there – so, attempt 2 (a=1) will be
              #   the first to be emailed
              crmcSqliteUtils::log $nsDbName “Attempt [expr $a + 1] – Database $nsDbName is locked – waiting $waitMsec milliseconds” $a
               
               after $waitMsec
               
               return 0
               
              }

              This will wait for two seconds (2000 ms) and then return – and the open will try again – continuously until the DB is available.

              If you want to bail on the open after so many unsuccessful attempts, you can check if $a > 10, for example, then return a “1” instead of “0”.

              … more detail at http://www.sqlite.org/tclsqlite.html

              Jeff Dinsmore
              Chesapeake Regional Healthcare

            • #77180
              Jim Kosloskey
              Participant

                Is that action the equivalance of a Tcl ‘Sleep’ such that the Cloverleaf process is affected?

                email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

              • #77181
                Jeff Dinsmore
                Participant

                  Yes – after, as it’s used in my busy proc, is blocking.

                  That’s why you may want/need to bail after some number of attempts.

                  The tradeoff is that you may not get the info you’re after to/from the database.

                  Either way, locking must be handled – especially if you’re accessing a database from two different processes.

                  Jeff Dinsmore
                  Chesapeake Regional Healthcare

                • #77182
                  Gary Atkinson
                  Participant

                    In our case we will be writing to and selecting from several processes.  We ended up writing our own package and handled the locking and errors inside the package.

                  • #77183
                    Jeff Dinsmore
                    Participant

                      Yep. That’s a good approach.

                      This is one of SQLite’s weaker points. It’s a great little database engine, but works best with a single point of access. If you need multi-user access with a large number of users and/or transactions, you may want to look to a different database.

                      Jeff Dinsmore
                      Chesapeake Regional Healthcare

                    • #77184
                      Gary Atkinson
                      Participant

                        Agreed but sqlite is free  ðŸ™‚

                      • #77185
                        Jeff Dinsmore
                        Participant

                          Yes. I agree – free is good. And, it’s nicely integrated with Tcl, so it’s the perfect fit for Cloverleaf.

                          I use SQLite a lot.

                          Jeff Dinsmore
                          Chesapeake Regional Healthcare

                      Viewing 8 reply threads
                      • The forum ‘Cloverleaf’ is closed to new topics and replies.