Author | Message |
---|---|
HelloWorld
Posts: 88
|
Posted 09:47 Aug 15, 2009 |
I'm trying to implement the forward iteration. I understand that LogRecordIterator is what makes the iteration backward, but when I looked at the class implementation (which implements the Iterator interface), I'm not sure on where it exactly go into the log and reads it backward? I'm basically trying to find: * A class that provides the ability to read records Where it exactly provides that "ability"..? |
cysun
Posts: 2935
|
Posted 10:12 Aug 15, 2009 |
LogRecordIterator uses a LogIterator, which does the actual iteration. |
HelloWorld
Posts: 88
|
Posted 15:28 Aug 16, 2009 |
I still don't understand on how it exactly works.. For example: 42 a b 0 c d 14 e f 28 (Figure 13-7, Page 354) public BasicLogRecord next() { what is the currentrec? I thought it's the pointer position along the block, where block is divided into 4 bytes pages, which is the INT_SIZE but i'm not sure.. when is it that it reaches moveToNextBlock(); in this example? where does it move next? when does it read the "a b", "c d", etc..?? Thanks Last edited by HelloWorld at
16:38 Aug 16, 2009.
|
cysun
Posts: 2935
|
Posted 16:46 Aug 16, 2009 |
I think Figure 13-7 is wrong - it shows that the position of the last record is after the current record, while I think it should be before the current record. If you use the example in the lecture notes instead, you should be able to follow the LogIterator code. |
HelloWorld
Posts: 88
|
Posted 17:15 Aug 16, 2009 |
Hmm.. So I'm using the example of your lecture note: 16 0 1 Hi 4 2 32 i understand how it works, 16 will moves it to position 16, then get the content of the 16, which is 4, and then i'm assuming that it should read 2 and 32, but i still don't get this part:
Thanks
|
cysun
Posts: 2935
|
Posted 18:25 Aug 16, 2009 |
OK, I think my example is wrong, and the one in the textbook is correct. Here's how the example in the textbook works: 1. When a new block is loaded in memory, read from position 0, so currentrec=42. 2. When next() is called, read an int from currentrec position so currentrec=28, then return the position currentrec+INT_SIZE, i.e. the starting position of ["e","f"]. 3. When next() is called again, read an int from currentrec position so currentrec=14, then return the position currentrec+INT_SIZE, i.e. the starting position of ["c","d"]. 4. When next() is called again, read an int from currentrec position so currentrec=0, then return the position currentrec+INT_SIZE, i.e. the starting position of ["a","b"]. 5. When next() is called again, currentrec is 0 which means all the records in the page have been read, so load another block. BasicLogRecord is simply a block and the starting position of a record in the block. It's up to the recovery manager to read and interpret the record - see the next() method of LogRecordIterator. |
HelloWorld
Posts: 88
|
Posted 18:33 Aug 16, 2009 |
Thanks a lot! This is very helpful! |