Announcement

Collapse
No announcement yet.

PowerTree question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PowerTree question

    From the documentation...
    Before you can delete a key value, you must first use one of
    the ptFx functions to find the record...
    In a transaktion that went wrong, I want to delete added keys.
    Is it not proper to take accessblock returned by ptAdd
    and use that accessblock in ptDel?



    ------------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

  • #2
    Fred, that should work ok... basically a Delete relies on the block containing valid pointer and record information to clearly identify the key it is about to delete.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Thanks Lance,
      Now to the intriguing question.
      I want this to be Thread safe and fast....
      For the data file this is no problem as it is opened at application start
      and closed at application exit. The handle is GLOBAL
      -----------
      From the index point of view it is accessed from multiple apps, and from
      multiple threads in the app.
      I want the Index opened the same way at app-start and closed at exit.
      This can be accomplished with a GLOBAL access block.
      Index file is on a network path so making them thread safe via open/close
      with LOCAL access blocks will be s l o w ...
      -----------
      If I use a GLOBAL access block obtained at app-start with "IndexInit GLOBAL access block"
      Is it then possible to let 'THREADS' get a LOCAL copy of this initial access block
      to use for calls to misc. powertree-routines?
      Obviously this local copy will reflect the index as it was at app-start
      -
      Or is there another way to make it threadsafe?



      ------------------
      Fred
      mailto:[email protected][email protected]</A>
      http://www.oxenby.se

      Fred
      mailto:[email protected][email protected]</A>
      http://www.oxenby.se

      Comment


      • #4
        Essentially, each thread must OPEN the index file through the PowerTREE API, or the internal file handling will fail. This ensures that each thread will get it's own internal file handle for the index file, so using a global access block (or more precisely, a thread-local copy) will pass the file handle of the primary thread to another PowerTREE thread since the handle is held the block.

        Consider it like this: if you have a thread that reads data from a random access file with the statement 'GET #x, recnum, udt', how will that thread know what the file access mode and record length size is for handle opened in another thread, unless that thread actually opened the file itself? This situation applies to any threaded app the reads files, not specifically PowerTREE.

        I guess the real question is this: How are you planning to start and stop threads? On a per-query basis, or will the threads exist for the duration of the app?

        For the former, the overhead of opening the index with PowerTREE in each thread is quite low, so opening a PowerTREE index at the start of each thread will probably have very little impact (bar network speed, which is probably the largest portion of any overhead). For the latter, the Index OPEN overhead occurs once per thread at app startup, so the overall impact is almost irrelevant.

        Anyway, there could be another way to implement what you need, but since I'd have to post specific code to show you how I think it could be done, we'll have to take this over to email (due to the PowerTREE license terms). Please remember to include your Serial Number if you wish to contact me at Tech Support to discuss this further.

        I hope this helps!


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Lance,
          I have performed some live tests on a 'networked index'
          WIN2000/PRO PIII/500 Ethernet 100, light load on network.
          Open Index, Find Key, Close Index performed everything beetween
          0.0100000000000000000 and 0.000000000000000000 seconds
          on random keys 1-100000
          I was really stunned, really stunned.(Is this a plug for PTREE?)
          Lance, with your permission I will send you "my threadsafe code"
          using above technic.
          Sure woud like to see your twist on it.
          But if I will get close to 0.1 in real life, I will play the safe melody



          ------------------
          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Comment


          • #6
            Absolutely! Now you know exactly what I mean about the "low overhead" of PowerTREE.

            And yes, feel free to plug away!

            I look forward to reviewing your code.

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              How many open index is supported by Powertree.
              Is there a limit?
              I cannot find it in the documentation.
              --
              I have 5 index and 8 threads = 40 opens
              All threads have their on handle to the index.
              Multiuser is on
              --
              If Thread 1 adds a key to the index, will thread 2-8 see this key
              without closing/reopen the index ?
              I remember back 2 years ago when I purchased PowerTree that I had
              this problem. Thats why I put it aside......
              I hope I am wrong...

              --
              and what is blockheader (from PT32inc)

              ------------------
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se



              [This message has been edited by Fred Oxenby (edited May 16, 2001).]
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se

              Comment


              • #8
                The limit is the amount of memory and file handles available - rather a lot! Basically, there is no arbitary limit imposed by PowerTREE.

                When using multi-user mode (which you'll need if you are using multiple threads to access/modify an index) buffering is disabled within PowerTREE, so added and deleted index entries should appear seamlessly across threads without having to close and reopen the index.

                The block header is used internally... I'm not sure why it is even included in the INC file.

                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment

                Working...
                X