On Tue, May 20, 2008 at 2:49 AM, Matthew Toseland
<toad at amphibian.dyndns.org> wrote:
> On Friday 16 May 2008 16:15, j16sdiz at freenetproject.org wrote:
>> Author: j16sdiz
>> Date: 2008-05-16 15:15:24 +0000 (Fri, 16 May 2008)
>> New Revision: 19954
>>
>> Modified:
>> trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
>> Log:
>> BDBFS: reconstruct() - read data only when needed
>>
>>
>> Modified: trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
>> ===================================================================
>> --- trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
>> 2008-05-16
> 02:45:51 UTC (rev 19953)
>> +++ trunk/freenet/src/freenet/store/BerkeleyDBFreenetStore.java
>> 2008-05-16
> 15:15:24 UTC (rev 19954)
>> @@ -987,11 +987,9 @@
>> System.err.println("File pointer is
>> "+storeRAF.getFilePointer()+" but
> should be "+((headerBlockSize + dataBlockSize)));
>>
>> System.exit(NodeInitException.EXIT_STORE_RECONSTRUCT);
>> }
>> - // FIXME only do the read if we need the data,
>> and if we do, do a seek
> first.
>> - // Post 0.7.0; only a useful optimisation if
>> we have a good .keys file,
> but should
>> - // save some I/O when we do.
>> storeRAF.readFully(header);
>> - storeRAF.readFully(data);
>
> Why read the header?
>
>> + boolean dataRead = false;
>> + try {
>> if(lruRAFLength > (l+1)*8) {
>> try {
>> lruVal = lruRAF.readLong();
>> @@ -1030,6 +1028,10 @@
>> routingkey = newkey;
>> }
>> }
>> + if (!dataRead) {
>> + storeRAF.readFully(data);
>> + dataRead = true;
>> + }
>
> Why not seek here?
>
>> if (routingkey == null &&
>> !isAllNull(header) && !isAllNull(data)) {
>> keyFromData = true;
>> try {
>> @@ -1061,6 +1063,10 @@
>> if(!keyFromData) {
>> byte[] oldRoutingkey =
>> routingkey;
>> try {
>> + if (!dataRead) {
>> + storeRAF.readFully(data);
>> + dataRead = true;
>> + }
>
> Likewise.
>
>> StorableBlock
>> block = callback.construct(data, header, null,
> keyBuf);
>> routingkey =
>> block.getRoutingKey();
>>
>> if(Arrays.equals(oldRoutingkey, routingkey)) {
>> @@ -1115,6 +1121,11 @@
>> } finally {
>> if(t != null) t.abort();
>> }
>> + } finally {
>> + if (!dataRead) {
>> +
>> storeRAF.skipBytes(data.length);
>> + }
>> + }
>
> An interesting solution to not having to seek ... but surely it would be
> better to seek when needed, and not read the header?
>
fixed in r19963
>> }
>> } catch (EOFException e) {
>> long size = l * (dataBlockSize + headerBlockSize);
>