Re: w3c.tools.dbm.jdbm for large data

> >  > I used w3c.tools.dbm.jdbm for very large data(size > 7000).
> >  > Then w3c.tools.dbm.jdbm#lookup(key) cause
> > That's a difficult bug to track, I haven't tried storing such big
> > objects within that database. You may want to turn traces on (set
> > debug = true, in jdbm.java).

At least I fixed jdbm's bug.
It is very simple.
jdbm saves and restores only a part of diridx. (256bytes)

A patch for this bug is following.

So we can restore very large data in jdbm.

diff -c -r -N w3c.orig/tools/dbm/jdbm.java w3c/tools/dbm/jdbm.java
*** w3c.orig/tools/dbm/jdbm.java	Sat Sep 28 01:52:36 1996
--- w3c/tools/dbm/jdbm.java	Wed Apr  2 14:53:08 1997
***************
*** 462,468 ****
      private void restoreDirectory(DataInputStream in)
  	throws IOException
      {
! 	this.diridx = new int[block_size/4] ;
  	for (int i = 0 ; i < diridx.length ; i++)
  	    diridx[i] = in.readInt() ;
      }
--- 462,468 ----
      private void restoreDirectory(DataInputStream in)
  	throws IOException
      {
! 	this.diridx = new int[dir_size] ;
  	for (int i = 0 ; i < diridx.length ; i++)
  	    diridx[i] = in.readInt() ;
      }
***************
*** 811,821 ****
  	// Write the directory if needed:
  	if ( dir_changed ) {
  trace ("saving directory.") ;
  	    DataOutputStream out = (new DataOutputStream
! 				    (new FastByteArrayOutputStream(buffer))); 
  	    saveDirectory(out) ;
  	    fd.seek(dir_adr) ;
! 	    fd.write(buffer) ;
  	    dir_changed = false ;
  	}
  	// Write any modified bucket
--- 811,822 ----
  	// Write the directory if needed:
  	if ( dir_changed ) {
  trace ("saving directory.") ;
+ 	    byte dir_buffer[] = new byte[dir_size*4];
  	    DataOutputStream out = (new DataOutputStream
! 				    (new FastByteArrayOutputStream(dir_buffer))); 
  	    saveDirectory(out) ;
  	    fd.seek(dir_adr) ;
! 	    fd.write(dir_buffer) ;
  	    dir_changed = false ;
  	}
  	// Write any modified bucket
***************
*** 841,850 ****
  			  (new ByteArrayInputStream(buffer)));
  	    // Restore the directory:
  	    fd.seek(dir_adr) ;
! 	    if (fd.read(buffer) != buffer.length) 
  		throw new IOException("unable to restore DB directory.");
  	    restoreDirectory(new DataInputStream
! 			     (new ByteArrayInputStream(buffer))) ;
  	    // Initialize other fields:
  	    int dir_size        = (1<<dir_bits) ;
  	    this.loaded_buckets = 0 ;
--- 842,855 ----
  			  (new ByteArrayInputStream(buffer)));
  	    // Restore the directory:
  	    fd.seek(dir_adr) ;
! 	    byte dir_buffer[] = new byte[dir_size*4];
! 	    try {
! 		fd.readFully(dir_buffer);
! 	    } catch (IOException e) {
  		throw new IOException("unable to restore DB directory.");
+ 	    }
  	    restoreDirectory(new DataInputStream
! 			     (new ByteArrayInputStream(dir_buffer))) ;
  	    // Initialize other fields:
  	    int dir_size        = (1<<dir_bits) ;
  	    this.loaded_buckets = 0 ;

--
                                     --------------------------------------
                                                             Toshiki Murata
                                            Oki Electric Industry Co., Ltd.
                                                          Kansai Laboratory
                                                      mura@kansai.oki.co.jp
                                     --------------------------------------

Received on Wednesday, 2 April 1997 01:25:45 UTC