db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Matos <razieluk...@gmail.com>
Subject How to create a ContainerHandle from a given LogRecord
Date Thu, 20 Dec 2007 18:22:56 GMT
Hello!
I've been studying derby's logging system. I want to parse the log files 
on disk extract its LogRecord(s) and write those
to an arbitrary stream to do some post-processing latter on.
I am using LogFactory.openForwardsScan() to traverse the log between the 
desired LogInstant(s).
This works well except for the log records on the group 
Loggable.RAWSTORE (and ContainerOperation instances in particular).
The problem is that when I try to invoke writeExternal on LogRecords of 
that group I get an NPE because
some fields of the Loggable are null (due to being transient and hence 
not saved to disk).
I will try to explain better with a small code snippet:

//<java>
void parseLog(){
        StreamLogScan redoScan;
            try {
            LogInstant a = ...
           LogInstant b = ...
           //go from LogInstant 'a' to 'b'
                redoScan = (StreamLogScan) logFactory.openForwardsScan(a,b);
                LogRecord record;
                while ((record = redoScan.getNextRecord(logIn, null, 0)) 
!= null) {
                           
 writeLog(record.getTransactionId(),record.getLoggable(),redoScan.getInstant());
                }
                return ;
}
                
//write the LogRecord to a stream ...                
void writeLog(TransactionId transactionId,Loggable operation, long 
instant) throws IOException, StandardException {

            DynamicByteArrayOutputStream logOutputBuffer = new 
DynamicByteArrayOutputStream(1024);

            FormatIdOutputStream logicalOut = new 
FormatIdOutputStream(logOutputBuffer);
            ArrayInputStream logIn = new ArrayInputStream();
            LogRecord logRecord = new LogRecord();
            logRecord.setValue(transactionId, operation);

            //ERROR here when logrecord group is Loggable.RAWSTORE
            logicalOut.writeObject(logRecord);  
            
            byte[] data = logOutputBuffer.getByteArray();
            //do something with the data ...
    }
//</java>
Let's focus on the particular case that the LogRecord's Loggable is a 
ContainerOperation.
The line "logicalOut.writeObject(logRecord)" eventually invokes 
ContainerOperation.writeExternal() and because that object
is not correctly instantiated it throws an NPE when trying to access the 
RawContainerHandle containerHdl.
I think that I must create a ContainerOperation object with an adequate 
RawContainerHandle
but I am unable to do it from the information contained _only_ in the 
LogRecord.
I have been playing around with RawStoreFactory and TransactionFactory 
but without any success.
What am I  missing ? Is my reasoning correct ? And if so how can I solve 
this problem?

Thanks for you time.

Miguel

Mime
View raw message