FAQ
Hi,

My understanding is that I can have an IndexReader open for searching
(as long as it doesn't delete) while an IndexWriter is updating the index.


I wrote a simple test app to prove this and it works great on Mac OS
X, Java 1.4.2 and Lucene 1.4.2. It fails on Windows XP, Java 1.4.2 and Lucene
1.4.2. I tried other versions of Lucene and it failed in those too.

This
is the app that fails on Windows:

public static void main(String[] args)

throws Exception {
String indexFolder = "/TestIndex";

// add
a document to the index
IndexWriter indexWriter = new IndexWriter

(indexFolder,
new StandardAnalyzer(), true);
Document document =
new Document();
Field field = new Field("foo", "bar",

true, true, true)
document.add(field);
indexWriter.addDocument(document);

indexWriter.close();

// open an index reader but don't close it

IndexReader indexReader =
IndexReader.open(indexFolder);

// open
an index writer
indexWriter = new IndexWriter
(indexFolder,

new StandardAnalyzer(), true);
indexWriter.close();
}

On Windows XP
this throws an Exception as soon as it tries to open the IndexWriter after
the IndexReader has been opened.

Here's the stack trace:
Exception in
thread "main" java.io.IOException: Cannot delete _1.cfs
at org.apache.lucene.store.FSDirectory.create(FSDirectory.java:144)

at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:105)

at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:83)

at org.apache.lucene.index.IndexWriter.(TestLuceneLocks.java:17)

Is this a bug?


Thanks.

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

Search Discussions

  • Justin Swanhart at Nov 8, 2004 at 6:42 pm
    The reason this is failing is because you are trying to create a new
    index in the directory. It works on *nix file systems because you can
    delete an open file on those operating systems, something you can't do
    under Windows.

    If you change the create parameter to false on your second call
    everything should work as you expect it to.


    On 8 Nov 2004 18:27:12 -0000, yahootintin.1247688@bloglines.com
    wrote:
    Hi,

    My understanding is that I can have an IndexReader open for searching
    (as long as it doesn't delete) while an IndexWriter is updating the index.

    I wrote a simple test app to prove this and it works great on Mac OS
    X, Java 1.4.2 and Lucene 1.4.2. It fails on Windows XP, Java 1.4.2 and Lucene
    1.4.2. I tried other versions of Lucene and it failed in those too.

    This
    is the app that fails on Windows:

    public static void main(String[] args)

    throws Exception {

    String indexFolder = "/TestIndex";

    // add
    a document to the index

    IndexWriter indexWriter = new IndexWriter

    (indexFolder,

    new StandardAnalyzer(), true);

    Document document =
    new Document();

    Field field = new Field("foo", "bar",

    true, true, true)

    document.add(field);

    indexWriter.addDocument(document);

    indexWriter.close();

    // open an index reader but don't close it

    IndexReader indexReader =

    IndexReader.open(indexFolder);

    // open
    an index writer

    indexWriter = new IndexWriter

    (indexFolder,

    new StandardAnalyzer(), true);

    indexWriter.close();

    }

    On Windows XP
    this throws an Exception as soon as it tries to open the IndexWriter after
    the IndexReader has been opened.

    Here's the stack trace:

    Exception in
    thread "main" java.io.IOException: Cannot delete _1.cfs

    at org.apache.lucene.store.FSDirectory.create(FSDirectory.java:144)

    at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:105)

    at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:83)

    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:173)

    at scratch.TestLuceneLocks.main(TestLuceneLocks.java:17)

    Is this a bug?

    Thanks.

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-user-help@jakarta.apache.org
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
    For additional commands, e-mail: lucene-user-help@jakarta.apache.org
  • Yahootintin 1247688 at Nov 8, 2004 at 6:51 pm
    Thanks! I just figured that out. I was passing true by mistake.

    --- Lucene
    Users List" wrote:
    The reason this is failing
    is because you are trying to create a new
    index in the directory. It works
    on *nix file systems because you can
    delete an open file on those operating
    systems, something you can't do
    under Windows.

    If you change the
    create parameter to false on your second call
    everything should work as
    you expect it to.

    On 8 Nov 2004 18:27:12 -0000, yahootintin.1247688@bloglines.com
    wrote:
    Hi,

    My understanding
    is that I can have an IndexReader open for searching
    (as long as it doesn't
    delete) while an IndexWriter is updating the index.
    I wrote a simple
    test app to prove this and it works great on Mac OS
    X, Java 1.4.2 and
    Lucene 1.4.2. It fails on Windows XP, Java 1.4.2 and Lucene
    1.4.2.
    I tried other versions of Lucene and it failed in those too.
    This
    is the app that fails on Windows:

    public static void main(String[]
    args)
    throws Exception {

    String indexFolder = "/TestIndex";
    // add
    a document to the index

    IndexWriter
    indexWriter = new IndexWriter
    (indexFolder,

    new
    StandardAnalyzer(), true);
    Document document =
    new Document();
    Field field = new Field("foo", "bar",

    true,
    true, true)
    document.add(field);

    indexWriter.addDocument(document);
    indexWriter.close();

    // open an index reader but
    don't close it
    IndexReader indexReader =

    IndexReader.open(indexFolder);
    // open
    an index writer

    indexWriter = new IndexWriter
    (indexFolder,

    new StandardAnalyzer(), true);
    indexWriter.close();

    }

    On Windows XP
    this throws an Exception as soon as it tries to open the IndexWriter after
    the IndexReader has been opened.

    Here's the stack trace:

    Exception in
    thread "main" java.io.IOException: Cannot delete
    _1.cfs
    at org.apache.lucene.store.FSDirectory.create(FSDirectory.java:144)
    at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:105)
    at org.apache.lucene.store.FSDirectory.getDirectory(FSDirectory.java:83)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:173)
    at scratch.TestLuceneLocks.main(TestLuceneLocks.java:17)
    Is this a bug?

    Thanks.

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

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedNov 8, '04 at 6:27p
activeNov 8, '04 at 6:51p
posts3
users2
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase