@@ -164,10 +164,18 @@ Found a localhost (127.0.0.1) in the server list among non-localhost servers. \
164164 }
165165
166166 /**
167- * Determines the local peer ID. If {@code peerNames} contains an entry whose value equals the
168- * {@code serverName}, the corresponding peer is returned. Otherwise the server name is parsed
169- * for the numeric suffix convention {@code prefix_N} or {@code prefix-N} and used as the index
170- * into {@code peers} (e.g. {@code arcadedb-0} or {@code ArcadeDB_0} maps to index 0).
167+ * Determines the local peer ID using three strategies, in priority order:
168+ * <ol>
169+ * <li><b>Named peer match:</b> if {@code peerNames} contains an entry whose value equals the
170+ * {@code serverName} (the {@code name@host} syntax), the corresponding peer is returned.</li>
171+ * <li><b>Hostname match:</b> if {@code serverName} equals the host component of a peer's Raft
172+ * address (e.g. server name {@code arcadesplit1} for the list entry
173+ * {@code arcadesplit1:2434:2480}, or an IP), that peer is returned. This lets a plain
174+ * {@code host:raftPort:httpPort} server list work without the {@code prefix_N} convention.</li>
175+ * <li><b>Numeric suffix:</b> the server name is parsed for the {@code prefix_N} / {@code prefix-N}
176+ * convention and used as the zero-based index into {@code peers} (e.g. {@code arcadedb-0}
177+ * or {@code ArcadeDB_0} maps to index 0).</li>
178+ * </ol>
171179 */
172180 static RaftPeerId findLocalPeerId (final List <RaftPeer > peers , final Map <RaftPeerId , String > peerNames ,
173181 final String serverName , final ArcadeDBServer server ) {
@@ -177,18 +185,42 @@ static RaftPeerId findLocalPeerId(final List<RaftPeer> peers, final Map<RaftPeer
177185 return entry .getKey ();
178186 }
179187
188+ // Match the server name against the host component of each peer's Raft address. Covers the
189+ // plain "host:raftPort:httpPort" (or bare-IP) server list where the node is named after its host.
190+ for (final RaftPeer peer : peers )
191+ if (serverName .equals (RaftHAServer .extractHost (peer .getAddress ())))
192+ return peer .getId ();
193+
180194 final int separatorIdx ;
181195 try {
182196 separatorIdx = findLastSeparatorIndex (serverName );
183197 } catch (final IllegalArgumentException e ) {
198+ final List <String > configuredNames = peerNames != null ? new ArrayList <>(peerNames .values ()) : List .of ();
199+ final List <String > peerHosts = new ArrayList <>(peers .size ());
200+ for (final RaftPeer peer : peers )
201+ peerHosts .add (RaftHAServer .extractHost (peer .getAddress ()));
184202 throw new IllegalArgumentException (
185- "Server name '" + serverName + "' did not match any configured peer name and has no '_N' or '-N' suffix" ,
203+ "Cannot determine which cluster peer this node is: server name '" + serverName
204+ + "' does not match any configured peer name"
205+ + (configuredNames .isEmpty () ? "" : " (configured names: " + configuredNames + ")" )
206+ + ", does not match any host in the server list (hosts: " + peerHosts
207+ + "), and does not end with a node index ('-N' or '_N'). Fix this in one of these ways: "
208+ + "(1) set 'arcadedb.server.name' to the host of this node as it appears in the server list "
209+ + "(e.g. one of " + peerHosts + "); "
210+ + "or (2) use the 'name@host:raftPort:httpPort' syntax in the server list and set "
211+ + "'arcadedb.server.name' to one of those names; "
212+ + "or (3) name each node '" + serverName + "-N' (or '_N'), where N is its zero-based position "
213+ + "in the server list (first entry = 0); for " + peers .size () + " peers the valid suffixes are -0 .. -"
214+ + (peers .size () - 1 ) + "." ,
186215 e );
187216 }
188217 final int index = Integer .parseInt (serverName .substring (separatorIdx + 1 ));
189218 if (index < 0 || index >= peers .size ())
190219 throw new IllegalArgumentException (
191- "Server index " + index + " from name '" + serverName + "' is out of range [0, " + peers .size () + ")" );
220+ "Server index " + index + " parsed from node name '" + serverName + "' is out of range: the server list has "
221+ + peers .size () + " peers, so the index must be zero-based in [0, " + peers .size () + "). "
222+ + "For " + peers .size () + " peers name the nodes with suffixes -0 .. -" + (peers .size () - 1 )
223+ + " (the first server-list entry is index 0, not 1)." );
192224
193225 return peers .get (index ).getId ();
194226 }
0 commit comments