Synchronization - Race Condition

Synchronization - Race Condition

  

Hi there,

How is an Identifier created in server and local? If we get a record  from a server, is there a chance it will be the same Id with the new created record in the local?

regards,

A

Hi Anonymous,

Afaik identifiers Server Side are created with an IDENTITY set on the column to make it an auto number. Client side, since the local database is using SQLite, my best bet is AUTOINCREMENT. There is no sharing of this information between Server and Client. This means that a) you must never rely on Ids being equal on Server and Client and b) if both Server and Client can create records, you need conflict resolution when synchronizing.

Hi Killian,

Thank you for quick reply.

I am thinking about the exercise (Read/Write Data Last Write Wins):

Say: From sync to Local Storage from Server, there are records with id: 1,2,3...

then when offline, a new record is created in the local (see the red path above).. what is the new identifier? will it be 1 that will update the record from the server or it will be 4 that will create a new one?


regards,

A


Hi A (you really should give yourself a better name :)),

If you can add records to local, you should have both a local auto number identifier, and use a reference to the server entity (Id, GUID, whatever you chose and makes sense for your situation), which may be empty. Then on sync you can check whether it's an existing record (has a reference) or not (no reference).

Solution

It increment from the max number, so in this case is 4. I have tried it.


Regards,

A

Solution