473,657 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concurrency (recap and idea).....

With respect to my (now not so recent) thread on Concurrency, I would like
to run my idea past you gurus to see if its a runner. First, a brief recap:

I have a single user system (one user, one copy of the software, one copy of
MSDE, one machine) that I wish to convert into a multi-user/single database
networked system. The problem I had was that a lot of information is
fetched from the database and cached in the client program (the program
implements a tree structure, similar to a file system, and each of the nodes
in the system has properties). The concurrency issue revolved around having
multiple users updating these properties and possibly able to modify the
tree structure and there being no way to notify the other clients that they
need to refresh their data structures. Consider the system to be similar to
VSS to look at (and in VSS, people can make modifications to the tree
structure also!).

Ok, one of the suggestions was time stamping each record. So, when one user
modifies the record, a second user can detect whether their timestamp is
different and thus whether or not their update is invalid (and also whether
or not the client program needs to refresh the properties of the given
node). How about instead of a timestamp I simply use a reference counter.
ie. an integer that increments every time the record is modified (same
principle). I don't need to know when it was changed, just that the two
reference counters are different between when I fetched and when I am
updating the record.

Secondly, I think I have to distinguish between a change in properties and a
change in structure. For example, User A doesn't need to know about a
change in properties for a node he is not currently looking at. However,
that same user will want to be told about any change to the overall tree
structure. So, I was thinking that any operations involving modifications
to the tree structure should set a "structure changed" flag in the database
(increment a counter). After any operation is performed, the client
compares its "changed" flag to the database value to see if it needs to
reload the tree structure.
Do you think this is workable?
Thanks.

Robin
Jul 23 '05 #1
2 1269
Regarding your first question, this is known as optimistic concurrency and
is usually implemented with a timestamp data type, not to be confused with a
datetime column. The timestamp datatype contains a binary value unrelated
to date/time and is automatically updated by SQL Server whenever the row is
updated. Consequently, you can use a technique like:

UPDATE MyTable
SET MyData = @NewMyDataValue
WHERE MyID = @MyID AND
MyTimestamp = @OldMyTimestamp
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ('Data has been deleted or updated by another user', 16, 1)
END

You can use a similar technique to detect structure changes to your tree.
Save the current timestamp value in a program variable and check
periodically as desired.

SELECT LastUpdatedByUs er, LastUpdateTime, TreeTimeStamp
FROM MyTrees
WHERE MyTreeID = 1

The above table can be updated as follows. You can also include this in
triggers or procs for convenience, depending on how you perform data
manipulation in your app.

UPDATE MyTrees
SET LastUpdatedByUs er = SUSER_SNAME(),
LastUpdateTime = CURRENT_TIMESTA MP
WHERE MyTreeID = 1

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:cp******** ***********@new s.demon.co.uk.. .
With respect to my (now not so recent) thread on Concurrency, I would like
to run my idea past you gurus to see if its a runner. First, a brief
recap:

I have a single user system (one user, one copy of the software, one copy
of MSDE, one machine) that I wish to convert into a multi-user/single
database networked system. The problem I had was that a lot of
information is fetched from the database and cached in the client program
(the program implements a tree structure, similar to a file system, and
each of the nodes in the system has properties). The concurrency issue
revolved around having multiple users updating these properties and
possibly able to modify the tree structure and there being no way to
notify the other clients that they need to refresh their data structures.
Consider the system to be similar to VSS to look at (and in VSS, people
can make modifications to the tree structure also!).

Ok, one of the suggestions was time stamping each record. So, when one
user modifies the record, a second user can detect whether their timestamp
is different and thus whether or not their update is invalid (and also
whether or not the client program needs to refresh the properties of the
given node). How about instead of a timestamp I simply use a reference
counter. ie. an integer that increments every time the record is modified
(same principle). I don't need to know when it was changed, just that the
two reference counters are different between when I fetched and when I am
updating the record.

Secondly, I think I have to distinguish between a change in properties and
a change in structure. For example, User A doesn't need to know about a
change in properties for a node he is not currently looking at. However,
that same user will want to be told about any change to the overall tree
structure. So, I was thinking that any operations involving modifications
to the tree structure should set a "structure changed" flag in the
database (increment a counter). After any operation is performed, the
client compares its "changed" flag to the database value to see if it
needs to reload the tree structure.
Do you think this is workable?
Thanks.

Robin

Jul 23 '05 #2
Thanks, this is useful stuff.

"Dan Guzman" <gu******@nospa m-online.sbcgloba l.net> wrote in message
news:rH******** **********@news svr12.news.prod igy.com...
Regarding your first question, this is known as optimistic concurrency and
is usually implemented with a timestamp data type, not to be confused with
a datetime column. The timestamp datatype contains a binary value
unrelated to date/time and is automatically updated by SQL Server whenever
the row is updated. Consequently, you can use a technique like:

UPDATE MyTable
SET MyData = @NewMyDataValue
WHERE MyID = @MyID AND
MyTimestamp = @OldMyTimestamp
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ('Data has been deleted or updated by another user', 16, 1)
END

You can use a similar technique to detect structure changes to your tree.
Save the current timestamp value in a program variable and check
periodically as desired.

SELECT LastUpdatedByUs er, LastUpdateTime, TreeTimeStamp
FROM MyTrees
WHERE MyTreeID = 1

The above table can be updated as follows. You can also include this in
triggers or procs for convenience, depending on how you perform data
manipulation in your app.

UPDATE MyTrees
SET LastUpdatedByUs er = SUSER_SNAME(),
LastUpdateTime = CURRENT_TIMESTA MP
WHERE MyTreeID = 1

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:cp******** ***********@new s.demon.co.uk.. .
With respect to my (now not so recent) thread on Concurrency, I would
like to run my idea past you gurus to see if its a runner. First, a
brief recap:

I have a single user system (one user, one copy of the software, one copy
of MSDE, one machine) that I wish to convert into a multi-user/single
database networked system. The problem I had was that a lot of
information is fetched from the database and cached in the client program
(the program implements a tree structure, similar to a file system, and
each of the nodes in the system has properties). The concurrency issue
revolved around having multiple users updating these properties and
possibly able to modify the tree structure and there being no way to
notify the other clients that they need to refresh their data structures.
Consider the system to be similar to VSS to look at (and in VSS, people
can make modifications to the tree structure also!).

Ok, one of the suggestions was time stamping each record. So, when one
user modifies the record, a second user can detect whether their
timestamp is different and thus whether or not their update is invalid
(and also whether or not the client program needs to refresh the
properties of the given node). How about instead of a timestamp I simply
use a reference counter. ie. an integer that increments every time the
record is modified (same principle). I don't need to know when it was
changed, just that the two reference counters are different between when
I fetched and when I am updating the record.

Secondly, I think I have to distinguish between a change in properties
and a change in structure. For example, User A doesn't need to know
about a change in properties for a node he is not currently looking at.
However, that same user will want to be told about any change to the
overall tree structure. So, I was thinking that any operations involving
modifications to the tree structure should set a "structure changed" flag
in the database (increment a counter). After any operation is performed,
the client compares its "changed" flag to the database value to see if it
needs to reload the tree structure.
Do you think this is workable?
Thanks.

Robin


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1269
by: Shawn B. | last post by:
Greetings, First of all, I'm not exactly sure how seriously to take the C-Omega project (http://research.microsoft.com/Comega/). It appears to be a potential glimpse into what C# 3.0 might become. It has had some press recently and I have taken a small interest in it. Particularily, I am interested in the embedded SQL-like syntax that it provides for accessing objects and to a lessor extent (with regards to my interst in it)...
4
1552
by: Bob | last post by:
While testing my my program I came up with a consistency exception. My program consists of three datagridviews, One called dgvPostes which is the parent grid and its two children,one called dgvPlans and the other dgvTanks. What happens is as follows. I will either create or edit a record in the datagridview dgvPlans and call the Updatedb procedure (code below). The first save works OK. Then when that is done, on the same record I will try...
1
1894
by: davy zhang | last post by:
first here is my basic idea is every actor holds their own msg queue, the process function will handle the message as soon as the dispatcher object put the message in. This idea naturally leads me to place every actor in a separate thread waiting for msg but the rumor has it, stackless python with tasklet and channel can do much more better in concurrency program, so I dive my head into it.
0
364
by: James Mills | last post by:
On Tue, Nov 11, 2008 at 3:57 PM, davy zhang <davyzhang@gmail.comwrote: You could try circuits - An event driven way to concurrency. --JamesMills http://trac.softcircuit.com.au/circuits/ --
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.