Google App Engine:Lucene org.apache.lucene.store.LockObtainFailedException:Lock获取超时

时间:2013-01-30 07:47:29

标签: google-app-engine lucene

Google APP engine,我正在使用Lucene 4.1

我能够在本地生成索引文件,但在谷歌服务器上我得到以下异常(虽然相同的代码在本地机器上工作正常):

org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
   com.googlecode.lucene.appengine.GaeLockFactory$1@104a681

这是我的代码:


package com.search.domain;

import java.io.IOException;
import java.util.Set;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.util.Version;

import com.domain.dataobjects.Item;
import com.googlecode.lucene.appengine.GaeDirectory;
import com.googlecode.lucene.appengine.GaeLuceneUtil;


public class ItemDataIndexWriter {

public String createIndexes(){
    IndexWriter indexWriter = null;
    GaeDirectory indexDirectory = null;
try{    
        indexDirectory = new GaeDirectory();

        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_41 );

        IndexWriterConfig config = GaeLuceneUtil.getIndexWriterConfig(Version.LUCENE_41, analyzer);//get configuration

        config.setOpenMode(OpenMode.CREATE_OR_APPEND);
        indexWriter = new IndexWriter(indexDirectory, config);

        addToDoc(indexWriter,"test");
 }catch(Exception e){
     e.printStackTrace();
     System.out.println(e.getMessage());
     return e.toString();
 }
 finally{
     try {
        if(indexWriter!=null)
             indexWriter.close();
        if(indexDirectory!=null)
             indexDirectory.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println(e.getMessage());
    }        
 }
return "Good";
}


private static void addToDoc(IndexWriter w, String item) throws IOException {

    Document doc = new Document();
    doc.add(new TextField("item", item, Field.Store.YES));
    w.addDocument(doc);
}
}

任何人都可以指导我吗?怎么了?

2 个答案:

答案 0 :(得分:2)

只需进入Google AppEngine administration -> Datastore viewer,选择GaeLock实体并删除所有实体,通过这样做,您将解锁因任何原因而被锁定的每个Lucene索引。

小心!可能您的数据存储区已陷入脏状态,因此您必须通过删除以下所有条目来手动删除索引:LuceneIndexSegmentSegmentHunkGaeLock

当Lucene AppEngine配置不正确时,您遇到的问题可能会发生。检查lucene-appengine site上的配置说明。

答案 1 :(得分:1)

我遇到了同样的问题,但在测试中,云中的效果非常好。 我在groovy中做到了这一点:

    final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService()
    final PreparedQuery pq = datastore.prepare(new Query())
    def list = pq.asList(FetchOptions.Builder.withDefaults())
    datastore.delete(list.collect {it.key})

    GetIndexesRequest builder = GetIndexesRequest.newBuilder().build()
    GetResponse<Index> indexes = SearchServiceFactory.getSearchService().getIndexes(builder)

    for (Index index : indexes) {

        Results<ScoredDocument> result = index.search("")

        for (Document document : result) {
            index.deleteAsync(document.id)
        }
    }

它应该在每次测试之前清理数据存储区中的所有数据和所有索引。 但是在 index.deleteAsync(document.id)行中抛出错误