Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

(B&S)Validating Records

 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
In my data.java, i have a method that validates whether a record is still valid in the cache, as i intend to keep the cache in sync with the actual data file. I however sync on the cache once the method is called.
My question is this: In the update(), when i call the validate() method, is it valid that i still sync in the read() method?
My scenario goes thus:


Then in the update(), one could have a call to the the validate(). It is still valid to sync on the record cache before attempting to read() update() delete() cause i imagine only one thread would access the validate() hence only one thread will access either read() delete() update()?

A scenario that would help out in my flow would be appreciated. Thanks all
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saheed,

It looks like you have the potential for a gap in your logic here. For example, what happens if someone calls update() at the same time another client calls delete()? The sequence could go like:
  • From within update(), thread 1 calls validate() - all OK
  • from within delete(), thread 2 removes the record
  • thread 1 now continues with updating a record that has since been deleted.
  • Or do you have this scenario covered in some other way?

    Regards, Andrew
     
    Saheed Adepoju
    Ranch Hand
    Posts: 267
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Andrew Monkhouse:
    Hi Saheed,

    It looks like you have the potential for a gap in your logic here. For example, what happens if someone calls update() at the same time another client calls delete()? The sequence could go like:
  • From within update(), thread 1 calls validate() - all OK
  • from within delete(), thread 2 removes the record
  • thread 1 now continues with updating a record that has since been deleted.
  • Or do you have this scenario covered in some other way?

    Regards, Andrew

    Thanks Andrew, but i would still like to push abit further.
    Suppose i sync on the ContractorRecords within the validateRecord() and allow only one thread access and do a check? I was thinking it is too much "sync"ing.So my new validateRecord() would be something like this(Pseudocode):



    But i still think this is too much "sync"ing. So what you are saying is that, once one discovers that there might be corruption of data, one should sync, even though it might be too much.
    So for example, in my update, i should make sure i sync on the recordData before attempting to update a particular record. My own thinking is that since I would have an adapter class that would have a Business method and call them in a particular sequence, then i dont really need to "sync" within these methods(validateRecord(),Update()). Please correct me if i am wrong an push me in the right direction all.

     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Saheed,

    Lets take it back a step - if you have locked a record (using the lock() methods), then no other user can modify or delete the record. So is the synchronization here necessary?

    Regards, Andrew
     
    Bob Nedwor
    hangman
    Ranch Hand
    Posts: 215
    Eclipse IDE Oracle Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Andrew, the more I think about your response above, the more it seems like we really do NOT even need synchronization AT ALL if we correctly use the lockRecord() and unlockRecord() methods together with the other methods, right?
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Bob,

    The lock() and unlock() methods will probably need some synchronization, and you will probably need some form of synchronization around any disk operations (and data retrieval if you are working with a cache). But the synchronization in the method Saheed is discussing might be unnecessary. Likewise method synchronization may be unnecessary.

    Regards, Andrew
     
    Bob Nedwor
    hangman
    Ranch Hand
    Posts: 215
    Eclipse IDE Oracle Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ok, thanks, Andrew. I will go with that.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic