lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Otis Gospodnetic <otis_gospodne...@yahoo.com>
Subject Re: Cloning of RAMDirectory.
Date Mon, 13 Oct 2003 13:37:56 GMT
Thanks, I added this to our 'patch queue'.

Otis

--- Nick Smith <nick.smith@techop.ch> wrote:
> 
> Hi Lucene Developers,
>    Thanks for a great product!
>    
> I need to be able to 'snapshot' our in-memory indices (RAMDirectory
> instances).
> 
> I have been using :
> 
> RAMDirectory activeDir = new RAMDirectory();
> // many inserts, deletes etc
> RAMDirectory cloneDir = new RAMDirectory(activeDir);
> 
> but unfortunately this is rather slow for large indices.
> 
> I have a suggestion - implement java.lang.Cloneable interface
> in RAMDirectory.  I.e to be able to call :
> 
> RAMDirectory cloneDir = (RAMDirectory)activeDir.clone();
> 
> This bypasses the input/output stream handling of the
> copy constructor by cloneing the underlying buffers that
> form the directory and is much faster. (Diff attached).
> 
> Any comments?
> 
> Regards,
> 
> Nick
> > Index: RAMDirectory.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/store/RAMDirectory.java,v
> retrieving revision 1.8
> diff -r1.8 RAMDirectory.java
> 72c72
> < public final class RAMDirectory extends Directory {
> ---
> > public final class RAMDirectory extends Directory implements
> Cloneable {
> 210a211,223
> > 
> >   public Object clone() {
> >     RAMDirectory clone = new RAMDirectory();
> >     // *deep* copy files.
> >     for (java.util.Iterator
> it=files.entrySet().iterator();it.hasNext();)
> >     {
> >         java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
> >         String name = (String)entry.getKey();
> >         RAMFile file = (RAMFile)entry.getValue();
> >         clone.files.put(new String(name), file.clone());
> >     }
> >     return clone;
> >   }
> 302c315
> < final class RAMFile {
> ---
> > final class RAMFile implements Cloneable {
> 305a319,327
> > 
> >   public Object clone() {
> >     RAMFile clone = new RAMFile();
> >     clone.buffers = (Vector)buffers.clone();
> >     clone.length = length;
> >     clone.lastModified = lastModified;
> >     return clone;
> >   }
> > 
> 
> >
---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message