0
votes

I am using spring data neo4j framework for my neo4j database,i have configured neo4j server like following :

    <bean id="graphDatabaseService"
        class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
        <constructor-arg value="http://localhost:7474/db/data" />
    </bean>

    <neo4j:config graphDatabaseService="graphDatabaseService" />

    <neo4j:repositories base-package="sample" />

My question is how to configure multiple neo4j server in SDN,as neo4j database supports HA where we can have multiple slave and a master server.

1
Are you intending to use your Spring application as a server in the Neo4J cluster?JohnMark13
no,i am talking about horizontal scaling of my neo4j database where i can have multiple database servers,how to config them in SDN??Ankit Gupta
If SDN is not part of the cluster then it does not know about the cluster and you need to give it a separate (load balancer) endpoint to target. I'll make that part more clear in my answer.JohnMark13

1 Answers

2
votes

SDN does not enable you to configure a list of HA servers to make requests to when using the SpringRestGraphDatabase class. This means that if you want to manage a cluster of servers then you need to front them behind a single entry point. Commonly what you would do is set up your cluster and then stick a load balancer in front of it and let the load balancer handle routing read requests to whichever master/slave node it fancies (this could just be round robin) and write requests to the master node. There is some documentation for configuring HAProxy to achieve this here.

Once you have a cluster running and the load balancer routing requests you then need to modify your SDN configuration to target the load balancer which just means replacing http://localhost:7474/db/data with the address of your load balancer.

Original answer - SDN as embedded HA server

Assuming that your SDN application is going to be one of the Servers in your cluster then you need to create a HighlyAvailableGraphDatabase which uses a slightly different pattern:

<util:map id="config">
   <entry key="ha.server_id" value="1"/>
   <entry key="ha.initial_hosts" value="yourotherserver1:5001,yourotherserver2:5001"/>
</util:map>

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

<bean id="graphDbBuilder" factory-bean="graphDbFactory"
      factory-method="newHighlyAvailableDatabaseBuilder">
     <constructor-arg value="/path/to/local/filesystem/store"/>
</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"
              base-package="your.graph.package"/>

This assumes that you have two other servers running Neo HA nodes that have ha.server_id values other than 1. Once your cluster is running then you can drop in new instances (for horizontal scaling) as long as that ha.server_id value differs.

An important note about horizontal scaling is that you still want to push your writes through only the master (you can write to slaves but it is slower) which requires either some smart configuration on the load balancer fronting your application OR, when running SDN some bespoke code to defer writes on slaves. See this question for a note on SDN and understanding the master/slave setup.

Setting up your standalone HA nodes is documented in this tutorial. There is a lot of documentation on available parameters (for the config map) on the Neo Site.