From 33ff36cc42a083311065dee56adc1d72d6866f2d Mon Sep 17 00:00:00 2001 From: fibersel <0583463@gmail.com> Date: Wed, 26 May 2021 23:04:57 +0300 Subject: [PATCH] Add a system property to set hostId if not yet initialized patch by Abi Palagashvili; reviewed by Stefan Miklosovic and Paulo Motta for CASSANDRA-14582 --- CHANGES.txt | 1 + conf/jvm-server.options | 3 +++ src/java/org/apache/cassandra/db/SystemKeyspace.java | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 185ec72cf9..71018a655c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.1 + * Add a system property to set hostId if not yet initialized (CASSANDRA-14582) * GossiperTest.testHasVersion3Nodes didn't take into account trunk version changes, fixed to rely on latest version (CASSANDRA-16651) Merged from 4.0: * Make JmxHistogram#getRecentValues() and JmxTimer#getRecentValues() thread-safe (CASSANDRA-16707) diff --git a/conf/jvm-server.options b/conf/jvm-server.options index 46967f4ad7..f7845d4113 100644 --- a/conf/jvm-server.options +++ b/conf/jvm-server.options @@ -22,6 +22,9 @@ # and perhaps have affinity. #-Dcassandra.available_processors=number_of_processors +# Specify host id for the first boot and persist it +#-Dcassandra.host_id_first_boot=host_id + # The directory location of the cassandra.yaml file. #-Dcassandra.config=directory diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java index cbb708465c..4d2a567ca1 100644 --- a/src/java/org/apache/cassandra/db/SystemKeyspace.java +++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java @@ -1126,13 +1126,15 @@ public final class SystemKeyspace return hostId; // ID not found, generate a new one, persist, and then return it. - hostId = UUID.randomUUID(); + String hostString = System.getProperty("cassandra.host_id_first_boot", UUID.randomUUID().toString()); + hostId = UUID.fromString(hostString); logger.warn("No host ID found, created {} (Note: This should happen exactly once per node).", hostId); return setLocalHostId(hostId); } /** - * Sets the local host ID explicitly. Should only be called outside of SystemTable when replacing a node. + * Sets the local host ID explicitly. Should only be called outside of SystemTable when replacing a node. + * Used also in CASSANDRA-14582. */ public static synchronized UUID setLocalHostId(UUID hostId) {