Knowledge Base

Explanation of error "Record id 65536 is out of range [0, 65535]"

When running a Cypher statement that creates a new relationship type, for example

MERGE (n1:Person {id:1})-[r:knows]->(n2:Person {id:2})

one may encounter an error which is logged in the $NEO4J_HOME/logs/debug.log as

2017-10-30 17:08:29.741+0000 ERROR [o.n.b.v.r.ErrorReporter] Client triggered an unexpected error [UnknownError]: Could not create token, reference 63c2e7ef-6f5b-4834-b2a8-fe74cac3a50a. Could not create token
org.neo4j.graphdb.TransactionFailureException: Could not create token
        at org.neo4j.kernel.impl.core.DelegatingTokenHolder.getOrCreateId(
        at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.relationshipTypeGetOrCreateForName(
        at org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations.relationshipTypeGetOrCreateForName(
        at org.neo4j.kernel.impl.api.OperationsFacade.relationshipTypeGetOrCreateForName(
        at org.neo4j.cypher.internal.spi.v3_3.TransactionBoundQueryContext.getOrCreateRelTypeId(TransactionBoundQueryContext.scala:114)
        at org.neo4j.cypher.internal.compatibility.v3_3.ExceptionTranslatingQueryContext$$anonfun$getOrCreateRelTypeId$1.apply$mcI$sp(ExceptionTranslatingQueryContext.scala:203)
        at java.util.concurrent.Executors$
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$
        at org.neo4j.helpers.NamedThreadFactory$
Caused by: Record id 65536 is out of range [0, 65535]
        at org.neo4j.kernel.impl.core.DefaultRelationshipTypeCreator.createKey(
        at org.neo4j.kernel.impl.core.IsolatedTransactionTokenCreator.getOrCreate(
        at org.neo4j.kernel.impl.core.DelegatingTokenHolder.createToken(
        at org.neo4j.kernel.impl.core.DelegatingTokenHolder.getOrCreateId(
        ... 49 more

and they key part from above is the reference to Record id 65536 is out of range [0, 65535]

This error is caused as a result of hitting the maximum number of relationship types for a graph.db. The current limit is 65536. Note this is specifically for the 'relationship type', i.e. the identifier used to name the relationship. This limit does not apply to number of relationships between nodes or the total number of relationships in the graph.

When this error is encountered running

call db.relationshipTypes() yield relationshipType return count(relationshipType) as numRelTypes;

will return

| numRelTypes |
| 65536       |

To resolve this error would require removal of relationship types which are no longer associated with any nodes. As there is currently no Cypher command to do this, one would need to run This command will read a offline graph.db and prepare a new graph.db but exlcuding any relationship types/properties which are no longer in use.