Hi Thomas,
> It is first writing all deleted blocks, and then the blocks that are
> not deleted. However for a given position, only the last entry is
> written.
This does not seem to be the case though... In the algorithm above
each recordId can be written once for deleted and once for non-deleted
loop.
Below is the test-case program that shows two effects:
1. For each batch each record can be written twice ( the order is
correct though)
2. Between batches the same row is also can be written many times.
==========================================================================================
import java.util.ArrayList;
public class testFlush {
public ArrayList redoBuffer;
/**
* @param args
*/
public static void main(String[] args)
{
testFlush t = new testFlush();
t.execute();
}
public void execute()
{
redoBuffer = new ArrayList();
redoBuffer.add(new RedoLogRecord(1, "OneOne"));
redoBuffer.add(new RedoLogRecord(1, null));
redoBuffer.add(new RedoLogRecord(1, "OneThree"));
redoBuffer.add(new RedoLogRecord(2, "TwoOne"));
redoBuffer.add(new RedoLogRecord(2, null));
redoBuffer.add(new RedoLogRecord(2, "TwoThree"));
flushRedoLog();
redoBuffer.add(new RedoLogRecord(1, "OneOne"));
redoBuffer.add(new RedoLogRecord(1, "OneTwo"));
redoBuffer.add(new RedoLogRecord(1, null));
redoBuffer.add(new RedoLogRecord(1, "OneFour"));
redoBuffer.add(new RedoLogRecord(1, "OneFive"));
redoBuffer.add(new RedoLogRecord(2, "TwoOne"));
redoBuffer.add(new RedoLogRecord(2, "TwoTwo"));
redoBuffer.add(new RedoLogRecord(2, null));
redoBuffer.add(new RedoLogRecord(2, "TwoFour"));
redoBuffer.add(new RedoLogRecord(2, "TwoFive"));
flushRedoLog();
}
public void flushRedoLog()
{
System.out.println("Start flushRedoLog");
if (redoBuffer.size() == 0)
{
return;
}
// first write all deleted entries
RedoLogRecord last = null;
for (int i = 0; i < redoBuffer.size(); i++)
{
RedoLogRecord entry = (RedoLogRecord)redoBuffer.get(i);
if (entry.data != null) {
continue;
}
if (last != null && entry.recordId != last.recordId) {
writeRedoLog(last);
}
last = entry;
}
if (last != null) {
writeRedoLog(last);
}
// now write the last entry, skipping deleted entries
last = null;
for (int i = 0; i < redoBuffer.size(); i++) {
RedoLogRecord entry = (RedoLogRecord) redoBuffer.get(i);
if (last != null && entry.recordId != last.recordId) {
if (last.data != null) {
writeRedoLog(last);
}
}
last = entry;
}
if (last != null && last.data != null) {
writeRedoLog(last);
}
redoBuffer.clear();
}
private void writeRedoLog(RedoLogRecord rec)
{
System.out.println("Rec="+rec.recordId+" Data="+rec.data);
}
class RedoLogRecord
{
int recordId;
Object data;
public RedoLogRecord(int recordId, Object data)
{
this.recordId = recordId;
this.data = data;
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---