【问题标题】:Index creation error when starting embedded Neo4j HA Slave启动嵌入式 Neo4j HA 从属时的索引创建错误
【发布时间】:2014-04-10 15:56:18
【问题描述】:

我正在尝试创建运行嵌入式 Neo4J HA 服务器的 Java 应用程序集群,但在启动任何从属服务器时出现错误

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement CREATE INDEX ON :`DeviceNode`(`deviceType`); nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement CREATE INDEX ON :`DeviceNode`(`deviceType`); nested exception is org.neo4j.cypher.CypherExecutionException: Modifying the database schema can only be done on the master server, this server is a slave. Please issue schema modification commands directly to the master.
        at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:56) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.schema.SchemaIndexProvider.createIndex(SchemaIndexProvider.java:36) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.EntityIndexCreator$1.doWithPersistentProperty(EntityIndexCreator.java:45) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.EntityIndexCreator$1.doWithPersistentProperty(EntityIndexCreator.java:41) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:261) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.EntityIndexCreator.ensureEntityIndexes(EntityIndexCreator.java:41) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.updateStoredEntityType(Neo4jMappingContext.java:77) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.addPersistentEntity(Neo4jMappingContext.java:71) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.addPersistentEntity(Neo4jMappingContext.java:49) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:170) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:139) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:65) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.query.CypherQueryBuilder.<init>(CypherQueryBuilder.java:37) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:72) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.query.CypherQueryCreator.create(CypherQueryCreator.java:35) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.query.DerivedCypherRepositoryQuery.<init>(DerivedCypherRepositoryQuery.java:59) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.query.GraphQueryMethod.createQuery(GraphQueryMethod.java:146) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.GraphRepositoryFactory$1.resolveQuery(GraphRepositoryFactory.java:113) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210) ~[spring-data-commons-1.7.0.RELEASE.jar:na]
        at org.springframework.data.neo4j.repository.GraphRepositoryFactoryBean.afterPropertiesSet(GraphRepositoryFactoryBean.java:69) ~[spring-data-neo4j-3.0.0.RELEASE.jar:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) ~[spring-beans-3.2.8.RELEASE.jar:3.2.8.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) ~[spring-beans-3.2.8.RELEASE.jar:3.2.8.RELEASE]
        ... 38 common frames omitted

最重要的一点似乎是Modifying the database schema can only be done on the master server, this server is a slave. Please issue schema modification commands directly to the master。我相信索引正在创建,因为存储库接口由 SDN 解析。

我是否在某个地方做了一些疯狂的事情,我可以告诉奴隶们稍等一下,然后从最终到达那里的 Master 那里提取他们的架构吗?我相信我的配置是相当标准的:

<util:map id="config">
    <entry key="org.neo4j.server.database.mode" value="HA"/>

    <entry key="enable_remote_shell" value="true"/> 
    <entry key="ha.server_id" value="1"/>
    <entry key="ha.initial_hosts" value="neo1:5001,neo2:5001,neo3:5001"/>
    <entry key="ha.allow_init_cluster" value="true"/>
    <entry key="ha.cluster_join_timeout" value="60s"/>
    <entry key="ha.slave_only" value="false"/>
</util:map>

<bean id="graphDbFactory" class="org.neo4j.graphdb.factory.HighlyAvailableGraphDatabaseFactory"/>

<bean id="graphDbBuilder" factory-bean="graphDbFactory" factory-method="newHighlyAvailableDatabaseBuilder">
    <constructor-arg value="#{neoloc}"/>
</bean>

<bean id="graphDbBuilderFinal" factory-bean="graphDbBuilder" factory-method="setConfig">
    <constructor-arg ref="config"/>
</bean>

<bean id="graphDatabaseService" factory-bean="graphDbBuilderFinal" factory-method="newGraphDatabase" destroy-method="shutdown" />

<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:repositories base-package="com.clarifimedia.data.repository"></neo4j:repositories>

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <set>
            <bean class="com.clarifimedia.data.converter.DateTimeToLongConverter"/>
            <bean class="com.clarifimedia.data.converter.LongToDateTimeConverter"/>
        </set>
    </property>
</bean>

配置值实际上是从 JNDI 读取的,但我在上面进行了硬编码,因为 #{xyz} 的负载不会那么方便。

版本
neo4j-2.0.1
neo4j-ha-2.0.1
spring-data-neo4j-3.0.0.RELEASE
spring-general-stuff-3.2.8.RELEASE

[编辑、切线、错误?]
我试图通过破坏网络来启动三个隔离的 master,目的是修复网络并查看是否发生了选举。但是,在启动时,由于 TimeoutException,webapp 无法启动。

Caused by: java.util.concurrent.TimeoutException: null
        at org.neo4j.cluster.statemachine.StateMachineProxyFactory$ResponseFuture.get(StateMachineProxyFactory.java:300) ~[neo4j-cluster-2.0.1.jar:2.0.1]
        at org.neo4j.cluster.client.ClusterJoin.joinByConfig(ClusterJoin.java:158) ~[neo4j-cluster-2.0.1.jar:2.0.1]
        at org.neo4j.cluster.client.ClusterJoin.start(ClusterJoin.java:91) ~[neo4j-cluster-2.0.1.jar:2.0.1]
        at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503) ~[neo4j-kernel-2.0.1.jar:2.0.1]

ClusterJoin 捕获 InterruptedException 和 ExecutionException,但不捕获 StateMachineProxyFactory$ResponseFuture 抛出的 TimeoutException。鉴于 ClusterJoin 类中的while(true),我认为这是一个错误,或者我是否有错误的 jar 文件组合(尽管这两个类都在 neo4j-cluster-2.0.1 中)。

【问题讨论】:

标签: neo4j spring-data-neo4j


【解决方案1】:

我有一个解决方法。请注意,我使用 spring Java 配置,但通过 XML 配置它应该没什么大不了的。

创建两个扩展标准sdn类的类,第一个添加一个方法检查当前jvm是否以neo作为master运行:

public class OurDelegatingGraphDatabase extends DelegatingGraphDatabase {

    public OurDelegatingGraphDatabase(GraphDatabaseService delegate) {
        super(delegate);
    }

    public boolean isMaster(){
        if (delegate instanceof HighlyAvailableGraphDatabase){
            HighlyAvailableGraphDatabase highlyAvailableGraphDatabase = (HighlyAvailableGraphDatabase) delegate;
            return highlyAvailableGraphDatabase.isMaster();
        }
        return true;
    }
}

然后是一个自定义的 SchemaIndexProvider,它只在 master 上进行索引(单模式也被认为是 master):

public class HACheckingSchemaIndexProvider extends SchemaIndexProvider {

    private OurDelegatingGraphDatabase graphDatabase;

    public HACheckingSchemaIndexProvider(GraphDatabase gd) {
        super(gd);
        if (gd instanceof OurDelegatingGraphDatabase){
            this.graphDatabase = (OurDelegatingGraphDatabase) gd;
        } else {
            throw new IllegalStateException("OurDelegatingGraphDatabase was not configured");
        }
    }

    @Override
    public void createIndex(Neo4jPersistentProperty property) {
        if (!graphDatabase.isMaster()){
            return;
        }
        super.createIndex(property);
    }

    @Override
    public void createIndex(String label, String prop, boolean unique) {
        if (!graphDatabase.isMaster()){
            return;
        }
        super.createIndex(label, prop, unique);
    }
}

然后使用 spring 配置这些:

@Configuration
//..whatever else config you have
public class Neo4jConfig extends Neo4jConfiguration {

//other config stuf..

    @Bean
    @Autowired
    @DependsOn("graphDatabaseService")
    public GraphDatabase graphDatabase() {
        return new OurDelegatingGraphDatabase(getGraphDatabaseService());
    }

    @Bean
    @Override
    public SchemaIndexProvider schemaIndexProvider() throws Exception {
        return new HACheckingSchemaIndexProvider(graphDatabase());
    }

【讨论】:

  • 很好的解决方法,应该很容易转换为 XML。跟踪异常堆栈后,我考虑了类似的事情,但担心随着 SDN 的发展,我脚下的地面会移动。虽然我也承认 SDN 不是 Neo4J 并且是社区支持的,但对于任何可能考虑支付许可费的人来说,这是一个相当基本的功能!
【解决方案2】:

SDN 不知道数据库是否为 HA。

其实我不知道 Slaves 不能接受模式更新。

所以这可能是我们必须在 Neo4j 的 spring 配置中进行可配置的东西,以明确禁用某些设置的索引创建。

您能否就此提出 JIRA 问题?

【讨论】:

  • 提出的问题:jira.spring.io/browse/DATAGRAPH-459 我认为这可能就是这种情况,因为我跟踪代码并认为为什么 SDN 应该知道/关心底层图的状态?!不过,它确实给我带来了一个有趣的挑战。感谢您的关注,您能想到的任何解决方法(除了直接使用 Neo API 进行编码)?
  • 我可以看到这在 JIRA 中仍然是一个未解决的问题。这方面有进展吗?我面临同样的问题,并不热衷于实施解决方法。
  • (但我还是做了。:))
  • 你现在可以在 neo4j 配置上配置它,有一个标志说 create-index=true 左右。 (目前没有代码,但也有文档记录)
【解决方案3】:

对于那些急于将 Wouter 的 Spring Java 配置转换为其 XML 等价物的人,希望这会有所帮助(注意 graphDatabaseService 被定义为 OP):

<bean depends-on="graphDatabaseService" id="graphDatabase" class="com.path.to.OurDelegatingGraphDatabase">
    <constructor-arg ref="graphDatabaseService" /> 
</bean>       

<bean id="schemaIndexProvider" class="com.path.to.HACheckingSchemaIndexProvider">
    <constructor-arg ref="graphDatabase" />
</bean>

这对我有用。当然,如果我犯了任何错误或以上可以改进的地方,请告诉我。谢谢!

【讨论】:

    猜你喜欢
    • 2015-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多