3 Replies Latest reply: Oct 10, 2012 9:14 PM by userBDBDMS-Oracle RSS

    do you have some tips on deadlock avoidence for TDS?

    tiplip
      Hi All,

      I developed a small BBS(multi-threaded web app) using BDB as backend database, providing view/post/update messages which will accordingly invoke operations on databases like forum.db/thread.db/post.db in one thread, however, I find a tip as follows in BDB document to Avoid Blocks

      Reduce the length of time your application holds locks

      does it mean I should do (in one thread)
      start transaction
      update forum.db
      end transaction
      start transaction
      update thread.db
      end transaction
      start transaction
      update post.db
      end transaction

      instead of
      start transaction
      update forum.db
      update thread.db
      update post.db
      end transaction

      do I understand that?
        • 1. Re: do you have some tips on deadlock avoidence for TDS?
          userBDBDMS-Oracle
          It depends on what the rest of the application is doing. If you only have 1 thread doing the updates then doing it this way:

          start transaction
          update forum.db
          update thread.db
          update post.db
          end transaction



          would be perfectly fine.

          Also, to avoid deadlocks you want to make sure you are accessing your objects in the same order all the time. If one thread does update forum/thread/post and another does update post/thread/forum you are creating an opportunity for deadlocks.

          thanks
          mike
          • 2. Re: do you have some tips on deadlock avoidence for TDS?
            tiplip
            Hi, thanks for your quick response.

            Maybe there are many threads at the same time, not only one. In such situation, should I make transaction granularity smaller? like

            start transaction
            update forum.db
            end transaction
            start transaction
            update thread.db
            end transaction
            start transaction
            update post.db
            end transaction

            this will comply with that rule, Reduce the length of time your application holds locks? can make possibility of deadlock as low as possible?

            Another, I can make sure the access order.
            • 3. Re: do you have some tips on deadlock avoidence for TDS?
              userBDBDMS-Oracle
              yes that should work for you. the only thing that I can think of is if there is some sort of dependency amongst the different .dbs. By updating them in their own separate txns, is it acceptable one update fail and the others continue? If this is ok, then doing separate txns is ok.


              thanks
              mike