W3C home > Mailing lists > Public > www-jigsaw@w3.org > March to April 1997

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

From: Toshiki Murata <mura@kansai.oki.co.jp>
Date: Wed, 02 Apr 1997 15:25:45 +0900
Message-Id: <199704020625.PAA01519@emerald.carrot.kansai.oki.co.jp>
To: www-jigsaw@w3.org
> >  > 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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:26 GMT