I deployed a 3-core (by default) Neo4j in K8s via this helm chart. I'm quite a newbie to neo4j.
I'm using neo4jrb in a Ruby on Rails project.
When I tried to connect the neo4j service to write data. I often (not always) met this error
Neo4j::Core::CypherSession::CypherError: Cypher error:
Neo.ClientError.Cluster.NotALeader: No write operations are allowed directly on this database. Writes must pass through the leader. The role of this server is: FOLLOWER
I read this article Querying Neo4j Clusters. Then I realized there is one leader and two follower core created by the helm chart. In the cypher-shell, when I run
CALL dbms.cluster.overview() YIELD id, role RETURN id, role
I got
+-----------------------------------------------------+
| id | role |
+-----------------------------------------------------+
| "acce2b2c-53ae-498c-a49b-84f42897445e" | "FOLLOWER" |
| "03cabb09-de1a-40cc-b8b0-bb02981cf551" | "FOLLOWER" |
| "1aa96add-f5cd-43a1-9fc6-2a5360668bb7" | "LEADER" |
+-----------------------------------------------------+
So I should connect to the LEADER
when I try to write data. And I know a cluster can't be leader
permanently. If the current leader
is down, then the follower
will become a new leader
.
I once thought bolt+routing
to a causal cluster may be an easy way to fix my issue. When I went back to the ruby client, I found it doesn't support bolt+routing
for now.
What should I do now? I can't configure a LoadBalancer. I have access to writing a config for Ingress.
I'm not sure that neo4jrb supports bolt+routing.
You could try to use the java driver from graalvm's truffleruby, see:
https://github.com/michael-simons/neo4j-graalvm-polyglot-examples