Forum OpenACS Q&A: How does OpenACS deal with tree_sortkeys the child-key length changes?

Hi Tree-Experts,

we are checking the tree_sortkey code and have already adapted it for our Project objects.

However, I'm wondering after reading all the documentation, comments etc. how the system deals with the case that a parent gets the 257th child.

According to the new varbit approach, children's subkeys are stored in a single-byte value (max. 256). So when the 257th child is being added, the encoding length needs to become two bytes instead of one byte, right? (It seems to get to 4 bytes though...)

However, in the same moment when adding the 257th child you need to upgrade all the other children of the same parent to work with a new two-byte key instead of a one-byte value.

We are experiencing some strange effects with our Projects when adding more then 127 subprojects. It seems to be 127 instead of 256 because the system seems to revert to a 4 byte representation with a negative sign for some reasons. Please find below a listing.

We have checked the code then and I haven't seen any code in the acs_objects_insert_tr that would deal the cases above. Also, acs_objects_update_tr contains some code that deals with the case that the object_id or the context_id change of an object, but no about the case of a code length change.

Maybe I missed something...

Bests,
Frank

http://www.project-open.com/



project_id | parent_id |                          tree_sortkey
------------+-----------+------------------------------------------------------------------
      2095 |          | 10000000000000000000110000010111
      2112 |      2095 | 1000000000000000000011000001011100000000
      2113 |      2095 | 1000000000000000000011000001011100000001
      2114 |      2095 | 1000000000000000000011000001011100000010
      2115 |      2095 | 1000000000000000000011000001011100000011
      2116 |      2095 | 1000000000000000000011000001011100000100
      2117 |      2095 | 1000000000000000000011000001011100000101
      2118 |      2095 | 1000000000000000000011000001011100000110
      2119 |      2095 | 1000000000000000000011000001011100000111

...

      2237 |      2095 | 1000000000000000000011000001011101111101
      2238 |      2095 | 1000000000000000000011000001011101111110
      2239 |      2095 | 1000000000000000000011000001011101111111
      2240 |      2095 | 1000000000000000000011000001011110000000000000000000000010000000
      2241 |      2095 | 1000000000000000000011000001011110000000000000000000000010000001
      2242 |      2095 | 1000000000000000000011000001011110000000000000000000000010000010
      2243 |      2095 | 1000000000000000000011000001011110000000000000000000000010000011
      2244 |      2095 | 1000000000000000000011000001011110000000000000000000000010000100
      2245 |      2095 | 1000000000000000000011000001011110000000000000000000000010000101
      2246 |      2095 | 1000000000000000000011000001011110000000000000000000000010000110
      2247 |      2095 | 1000000000000000000011000001011110000000000000000000000010000111
      2248 |      2095 | 1000000000000000000011000001011110000000000000000000000010001000
      2249 |      2095 | 1000000000000000000011000001011110000000000000000000000010001001