ES出现异常:

failed to notify ClusterStateListener
java.lang.IllegalStateException: environment is not locked

定位代码:

下载ES 5.5源码,在main/java/org/elasticsearch/env/NodeEnvironment.java 里可以看到:

    private void assertEnvIsLocked() {
if (!closed.get() && locks != null) {
for (Lock lock : locks) {
try {
lock.ensureValid();
} catch (IOException e) {
logger.warn("lock assertion failed", e);
throw new IllegalStateException("environment is not locked", e);
}
}
}
}
assertEnvIsLocked调用地方,可以看到在检测ES node数据路径、index路径使用:
    /**
* Returns an array of all of the nodes data locations.
* @throws IllegalStateException if the node is not configured to store local locations
*/
public Path[] nodeDataPaths() {
assertEnvIsLocked();
Path[] paths = new Path[nodePaths.length];
for(int i=0;i<paths.length;i++) {
paths[i] = nodePaths[i].path;
}
return paths;
} /**
* Returns an array of all of the {@link NodePath}s.
*/
public NodePath[] nodePaths() {
assertEnvIsLocked();
if (nodePaths == null || locks == null) {
throw new IllegalStateException("node is not configured to store local location");
}
return nodePaths;
} public int getNodeLockId() {
assertEnvIsLocked();
if (nodePaths == null || locks == null) {
throw new IllegalStateException("node is not configured to store local location");
}
return nodeLockId;
} /**
* Returns all index paths.
*/
public Path[] indexPaths(Index index) {
assertEnvIsLocked();
Path[] indexPaths = new Path[nodePaths.length];
for (int i = 0; i < nodePaths.length; i++) {
indexPaths[i] = nodePaths[i].resolve(index);
}
return indexPaths;
}
而locks变量的赋值在:
 public NodeEnvironment(Settings settings, Environment environment) throws IOException {

        if (!DiscoveryNode.nodeRequiresLocalStorage(settings)) {
nodePaths = null;
sharedDataPath = null;
locks = null;
nodeLockId = -1;
nodeMetaData = new NodeMetaData(generateNodeId(settings));
logger = Loggers.getLogger(getClass(), Node.addNodeNameIfNeeded(settings, this.nodeMetaData.nodeId()));
return;
}
final NodePath[] nodePaths = new NodePath[environment.dataWithClusterFiles().length];
final Lock[] locks = new Lock[nodePaths.length];
boolean success = false;
。。。

查了下Lock这个类:

import org.apache.lucene.store.Lock

作用:

  • org.apache.lucene.store.Lock
  • An interprocess mutex lock.

    Typical use might look like:

     new Lock.With(directory.makeLock("my.lock")) {
    public Object doBody() {
    ... code to execute while locked ...
    }
    }.run(); 一些加锁、解锁例子 https://www.programcreek.com/java-api-examples/index.php?api=org.apache.lucene.store.Lock
    lucene锁的作用,写保护:在Lucene中,打开一个IndexWrite之后,就会自动在索引目录中生成write.lock文件,这个文件中并不会有内容,不管是在索引打开期间还是在索引关闭之后,其大小都为0KB,并且在IndexWriter关闭之后,并不会删除该文件。如果同时打开多个IndexWriter的话,后打开的IndexWriter就会抛出LockObtainFailedException异常。这是个很重要的保护机制,因为若针对同一索引打开两个writer的话,会导致索引损坏。所以Lucene中的锁主要针对并发写的情况,在写的过程中并不会影响到并发读操作。

    1. lucene并发规则

    a,任意数量的只读属性IndexReader类都可以同时打开一个索引。

    b,对于一个索引来说,一次只能打开一个IndexWriter对象。lucene采用锁来提供保障。

    c,IndexReader可以在indexwriter正在修改索引时打开。该对象只有在IndexWriter提交修改或自己重新打开后才能获知索引的修改情况。

    d,任意多个线程可以共享同一个indexreader或indexwriter。

    2. lucene锁机制

    为了实现单一的writer,lucene采用了基于文件的锁,如果锁文件(默认writer.lock)存在于你的索引所在目录内,说明此时正在打开一个writer。此时若企图对同一个索引文件创建其他的writer的话,将产生一个LockObtainFailedException异常。

    而由assertEnvIsLocked看,抛出的异常应该是锁出现了问题,文件损坏或者目录损坏、或者文件系统损坏导致。

ES failed to notify ClusterStateListener java.lang.IllegalStateException: environment is not locked的更多相关文章

  1. Request processing failed; nested exception is java.lang.IllegalStateException: getOutputStream() has already been called for this response

    问题分析: 在ServletRequest servletRequest中已经存在一个项目名称,此时,又用项目名称访问 http://localhost:8080/rent/pdf/preview r ...

  2. 异常解决:java.lang.IllegalStateException: Failed to introspect Class

    java.lang.IllegalStateException: Failed to introspect Class 异常详情 原因 解决办法 异常详情 Exception encountered ...

  3. Caused by: java.lang.IllegalStateException: RedisConnectionFactory is required

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisTemplat ...

  4. Spring Scheduled定时任务报错 java.lang.IllegalStateException: Encountered invalid @Scheduled method 'xxx': For input string: "2S"

    报错信息如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ding ...

  5. java.lang.IllegalStateException: Cannot run without an instance id.

    启动springboot,报错:quartz集群报错: Sep 09, 2016 5:33:47 AM org.apache.catalina.core.ApplicationContext log ...

  6. nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...

  7. spring mvc处理http请求报错:java.lang.IllegalStateException: getInputStream() has already been called for this request

    发送post请求到controller处理失败,报错日志如下: java.lang.IllegalStateException: getInputStream() has already been c ...

  8. Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

    java.lang.IllegalStateException: Failed to load ApplicationContext    at org.springframework.test.co ...

  9. junit测试时,出现java.lang.IllegalStateException: Failed to load ApplicationContext

    课程设计要求进行junit测试,我是在已经做好的ssh项目上做的测试,测试类代码如下 package com.zhang.web.services; import static org.junit.A ...

随机推荐

  1. 134. Gas Station leetcode

    134. Gas Station 不会做. 1. 朴素的想法,就是针对每个位置判断一下,然后返回合法的位置,复杂度O(n^2),显然会超时. 把这道题转化一下吧,求哪些加油站不能走完一圈回到自己,要求 ...

  2. Hadoop MapReduce编程 API入门系列之自定义多种输入格式数据类型和排序多种输出格式(十一)

    推荐 MapReduce分析明星微博数据 http://git.oschina.net/ljc520313/codeexample/tree/master/bigdata/hadoop/mapredu ...

  3. NFS 开机自动挂载共享目录

    开机自动挂载: 如果服务端或客户端的服务器重启之后需要手动挂载,我们可以加入到开机自动挂载 在服务端/客户端的/etc/fstab里添加 192.168.22.204:/opt/filestore  ...

  4. linux下使用bcp备份sybase数据

    命令|数据库名|表名|导出到|文件名|格式|sybase服务名|数据库登录名 |字符集 bcp dbname..tablename out filename -n -Sgfdmhk -UISISMan ...

  5. os.clock()导致的bug

    os.clock () 功能:返回一个程序使用CPU时间的一个近似值 最近做了一个功能,这个功能需要统计时间间隔,例如每隔0.5秒做一次调用. 我用了os.clock()去统计时间,结果在pc机上都没 ...

  6. NOSQL:redis mongodb

    redis 1 概念及其基本操作:http://blog.nosqlfan.com/html/3139.html 2 安装配置及其操作:http://blog.fens.me/linux-redis- ...

  7. 学习SQL笔记

    SQL 语句 语法 AND / OR SELECT column_name(s)FROM table_nameWHERE conditionAND|OR condition ALTER TABLE A ...

  8. (转)基于MVC4+EasyUI的Web开发框架经验总结(4)--使用图表控件Highcharts

    http://www.cnblogs.com/wuhuacong/p/3736564.html 在我们做各种应用的时候,我们可能都会使用到图表统计,以前接触过一些不同的图表控件,在无意中发现了图表控件 ...

  9. 脚本编写 nginx 启动

    #!bin/bash#功能:本脚本编写完成后,放置在/etc/init.d/目录下,就可以被 Linux 系统自动识别到该脚本.#如果本脚本命名为/etc/init.d/nginx,则 service ...

  10. Mysql 5.7 for windows 免安装版(解压版)安装和配置

    网上写的不近详细,这里重新整理下. 准备: 1.windows操作系统 2.mysql 的解压版压缩文件 第一步: 解压mysql的压缩包到你的安装目录,因为是虚拟机,这里我就安装在C盘下:C:\my ...