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

URLyBird create method

 
Alexandre Baldo
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys!

My create method is as follow:



1) It must return the record number just created;
2) It must reuse a deleted entry (the specification says 'possibly reusing a deleted entry', but I'm taking it as a must);

I dont't have a field 'recNum', so I'm using the order the records are created as my 'recNum'...

The question is about the way I'll get the 'recNum'.
I thought about two ways:

1) Every time I create a new record I'll iterate over my database looking for a deleted record or EOF. This way I can get the 'recNum';

OR

2) When the program starts I'll iterate over my database just once and build a Map (recNum, locationInFile) of deleted records. So, every time I create a new record I'll update this Map.

What do you think? What is the best choice?
Did you guys used a different approuch?

Thank you all!
 
Alenkhe David
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i am working on Urlybird 1.1.1.

my spec says :





I think you should implement Approach number 1, it would be more efficient than approach number 2. Approach number 2 has a drawback:

1. It would increase start up time(Say the db file is large, start up time of your program would incrase because you would be accessing db file at startup of application).
[ August 14, 2008: Message edited by: Alenkhe David ]
 
Niels van Eeden
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I choose option two.

At startup i have my server not running.
Clicking start on the server UI will then start validating the DB file set.
I check for magic number and column info, after that i read all records deleted flags and skipping alll other bytes of the records.
It's no big performance deal (As performance isn't an issue in the exam at all).
Storing them in map works quite well and speeds up create method. Index started at 0. this makes the offset calculation for the RandomAccessFile easier.
You can lock on id -1 for your create method as you still have to get the first reusable id (As i did) and then use it to store a record.

If you choose the other option you would have to lock many records while searching for a deleted one. This could slow down many clients booking orders or searching for them. I found that way more unacceptable then having startup time at the server.

But then again, this is just my opinion.
 
Alenkhe David
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use caching i.e approach number 2. since performance is not a big deal .
 
Alexandre Baldo
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Niels van Eeden:
I choose option two.
If you choose the other option you would have to lock many records while searching for a deleted one. This could slow down many clients booking orders or searching for them. I found that way more unacceptable then having startup time at the server.


That's a good point! I did not think about that.
I think I'll take option 2.

Thank you, guys!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic