• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read Magic Cookie Every Time ?

 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone think it is overkill to check the magic Cookie everytime you write to the database ?
I thought about it but then thought I'd have to lock the whole DB read the cookie, write my record( an atomic action that didn't need a lock) and then unlock the DB again. I don't want to lock the whole DB every time I write to the db file.
Tony
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
Yes, it's overkill. The magic cookie is read-only, except when you create a new table of course. It's simply there to be checked once when you open the file, to make sure (I mean nearly sure) the file you open is a data file. After that first check you never need to access it again.
Cheers,
Phil.
 
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 Tony,
You might want to check for the statement in your instructions: "You may assume that at any moment, at most one program is accessing the database file" - if you have that, then reading the cookie value is guaranteed to be a waste of time: your application would be the only application that could ever change it.
Even without that statement, I would not want to check the cookie every time you performed a write - the interface provided does not allow any way of changing the cookie value, so I think that Sun intend that this value would not be changed once it has been set.
Regards, Andrew
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic