Thank you very much for even looking at it. I realise it's not down to
Mobilink as such, but rather because of a DB architecture that is not the
best suited for Mobilink.
Quote:
If this is a true representation of how the counter is incremented...
...then if you may run the risk of two users calculating the same
value li_seq_no. A alternative approach is to UPDATE COUNTERS to
increment sequence_no first, then retrieve and use the incremented
value; that way, a second user will be blocked until the first user
commits, rather than getting the same value.
-You're spot on. Yesterday I was just explaining the logic how it works, I
|
guess I didn't get the sequence of events right. It is in fact exactly as
you said:
1) Retrieved first
2) Incremented
3) Updated to database
4) Use incremented value
But anyway, as you said yourself, that would not cause the problem that
we're getting.
DB schema I presented yesterday was modified, basically stripped of all
other fields that are not necessary for this process. There is a table that
stores two latest numbers for two automatic sequences, per code provided
table dba.counters(
code char(4) not null,
sequence_no1 integer,
sequence_no2 integer,
last_modified datetime default timestamp,
primary key(code)
);
Download cursor:
'SELECT CODE, SEQUENCE_NO1, SEQUENCE_NO2 FROM counters WHERE last_modified
Upload Update:
'UPDATE counters SET SEQUENCE_NO1 = ?, SEQUENCE_NO2 = ? WHERE CODE = ?');
Quote:
Remember that the upload happens first, then the download, and the
entire row is uploaded if anything changes. So, it is possible for old
data on the remote to clobber newer data on the consolidated if you
don't have conflict resolution scripts (this might be a conflict
situation).
My thoughts exactly. That is why I think I should introduce something in the
|
script that will overwrite the "sequence_no2" value only if the new value is
larger.
The most puzzling issue is that this did not happen between two syncs, which
would make sense. If value is 9501315, consolidated inserts 5 new records,
but remote only one before the next sync, then 9501320 in consolidated COULD
get overwritten with 9501316 from remote. But from my second post yesterday,
it can be seen that "guilty" update from the remote DB, setting the value to
9501316, came 13 DAYS after 9501316 was written down first in consolidated
DB.
---7th of July---
UPDATE DBA.counters
SET sequence_no2=9501316,
last_modified='2006-07-07 10:34:12.515001'
WHERE CODE='05';
....
....
....
---14th of July---
UPDATE DBA.counters
SET sequence_no2=9501320,
last_modified='2006-07-14 11:42:08.125'
WHERE CODE='05'
---20th of July---
UPDATE DBA.counters
SET sequence_no1=4500776,
sequence_no2=9501316,
last_modified='2006-07-20 13:25:11.046001'
WHERE CODE='05';
???... Now, how could that happen, how can remote have the value of 9501316
for 13 days in between there have been countless syncs and quite a few
records going in between?