Skip to content

Commit 8bbf92a

Browse files
committed
Refactor validation logic in StorageService.rebuild
patch by Stefan Miklosovic; reviewed by Ariel Weisberg for CASSANDRA-18803
1 parent 4ab31d3 commit 8bbf92a

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
3.0.30
2+
* Refactor validation logic in StorageService.rebuild (CASSANDRA-18803)
23
* Make alternation of a user type validate the same way as creation of a user type does (CASSANDRA-18585)
34
* Backport of CASSANDRA-16905 Further restrict schema column drop/recreate conversions (CASSANDRA-18760)
45
* CQLSH emits a warning when the server version doesn't match (CASSANDRA-18745)

src/java/org/apache/cassandra/service/StorageService.java

+12-20
Original file line numberDiff line numberDiff line change
@@ -1308,35 +1308,27 @@ public boolean isJoined()
13081308

13091309
public void rebuild(String sourceDc)
13101310
{
1311-
try
1311+
if (sourceDc != null)
13121312
{
1313-
// check ongoing rebuild
1314-
if (!isRebuilding.compareAndSet(false, true))
1313+
TokenMetadata.Topology topology = getTokenMetadata().cloneOnlyTokenMap().getTopology();
1314+
Set<String> availableDCs = topology.getDatacenterEndpoints().keySet();
1315+
if (!availableDCs.contains(sourceDc))
13151316
{
1316-
throw new IllegalStateException("Node is still rebuilding. Check nodetool netstats.");
1317-
}
1318-
1319-
if (sourceDc != null)
1320-
{
1321-
TokenMetadata.Topology topology = getTokenMetadata().cloneOnlyTokenMap().getTopology();
1322-
Set<String> availableDCs = topology.getDatacenterEndpoints().keySet();
1323-
if (!availableDCs.contains(sourceDc))
1324-
{
1325-
throw new IllegalArgumentException(String.format("Provided datacenter '%s' is not a valid datacenter, available datacenters are: %s",
1326-
sourceDc, String.join(",", availableDCs)));
1327-
}
1317+
throw new IllegalArgumentException(String.format("Provided datacenter '%s' is not a valid datacenter, available datacenters are: %s",
1318+
sourceDc, String.join(",", availableDCs)));
13281319
}
13291320
}
1330-
catch (Throwable ex)
1321+
1322+
// check ongoing rebuild
1323+
if (!isRebuilding.compareAndSet(false, true))
13311324
{
1332-
isRebuilding.set(false);
1333-
throw ex;
1325+
throw new IllegalStateException("Node is still rebuilding. Check nodetool netstats.");
13341326
}
13351327

1336-
logger.info("rebuild from dc: {}", sourceDc == null ? "(any dc)" : sourceDc);
1337-
13381328
try
13391329
{
1330+
logger.info("rebuild from dc: {}", sourceDc == null ? "(any dc)" : sourceDc);
1331+
13401332
RangeStreamer streamer = new RangeStreamer(tokenMetadata,
13411333
null,
13421334
FBUtilities.getBroadcastAddress(),

0 commit comments

Comments
 (0)