Robin Tucker (idontwanttobespammedanymore@reallyidont.com) writes:[color=blue]
> Now, the problem comes when I consider concurrency with respect to this
> scheme. It seems to me, that locking the record I am updating is not
> sufficient to ensure clients are kept synchronised or the integrity of
> the tree structure is correct. I think I need to lock all ancestors of
> the tree (HOLDLOCK) before performing any operation on a given node. Is
> this reasonable?[/color]
UPDLOCK would be better. Else you could run into conversion deadlocks.
An UPDLOCK is a shared lock, so other processes can read. But only one
can have an UPDLOCK.
[color=blue]
> Also, consider the "delete" problem given above. I
> really should HOLDLOCK on the entire subtree of any node I wish to
> delete as I am going to set the entire subtrees parent values to NULL.
> I don't want another client to perform a read on part of the subtree
> while the nodes are "parentless" pending deletion.[/color]
I'm not really sure why you need to do this set NULL thing. In fact
that is something I would avoid like the plague. But then I know
very little of your actual business problem.
I think Joe Celko's trick for tress is to number each node in a way so
that a subtree is a contiguous range. Then you can blow away to whole
subtree in one delete.
Then again, you already had that path. Would not:
DELETE tbl WHERE path = 'a/b/c' or path LIKE 'a/b/c/%'
work?
Of course, even with set-based statements, you can have interesting
effects if two clients are it at the same time.
[color=blue]
> Secondly, I am not sure how to handle synchronization of the tree for
> each client. How does each client know when a change has been made to
> the tree?[/color]
You will have to ask you tech lead about that. :-) Seriously, with
no knowledge of the requirements etc, it is very difficult to answer.
As Thomas said, you can refresh automatically with some frequency.
For more bells and whistle you could push the change by activating
some signaling mechanism from a trigger. But you make have to ask for
a bigger budget to do this.
--
Erland Sommarskog, SQL Server MVP,
esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp