google-app-engine - Google App Engine : Lucene org. apache.lucene.store.LockObtainFailedException:锁定获取超时

标签 google-app-engine lucene

Google APP 引擎中,我使用的是 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);
}
}

有人可以指导我吗?怎么了?

最佳答案

只需进入 Google AppEngine 管理 -> 数据存储查看器,选择 GaeLock 实体并删除所有实体,这样您就可以解锁因任何原因锁定的每个 Lucene 索引。

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

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

关于google-app-engine - Google App Engine : Lucene org. apache.lucene.store.LockObtainFailedException:锁定获取超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14598958/

相关文章:

java - 使用 Google 应用引擎或 Lucene 通过关键字映射进行搜索

java - Lucene:IndexSearcher.search() 在非常大的数据库上导致 java 堆空间错误

java - 找不到 ElasticSearch Lucene UnicodeUtil

java - Lucene IndexWriter线程安全

lucene - 提升多值字段

python - 我需要在 Google App Engine 中使用线程同步工具吗?

google-app-engine - 如何着手更新 GAE SDK?

python - 在 GQL (Google App Engine) 上获取 4 个不重复的最新结果

java - 如何在命名空间之间复制数据存储实体

java - Lucene 从索引更新文档字段,没有松散信息