Skip to content

Commit ae673a3

Browse files
ifesdjeenbelliottsmith
authored andcommitted
Startup sequence improvements follow-up
Patch by Alex Petrov; reviewed by Benedict Elliott Smith for CASSANDRA-20822
1 parent 2f56702 commit ae673a3

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ public double getMean()
586586
sum += bCount * bucketOffsets[i];
587587
}
588588

589+
if (elements == 0)
590+
return 0d;
591+
589592
return (double) sum / elements;
590593
}
591594

src/java/org/apache/cassandra/service/accord/AccordConfigurationService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ private void reportMetadata(ClusterMetadata metadata)
232232
void reportMetadataInternal(ClusterMetadata metadata)
233233
{
234234
Topology topology = AccordTopology.createAccordTopology(metadata);
235-
if (topology.isEmpty() && isEmpty())
236-
return;
237235

238236
updateMapping(metadata);
239237
if (Invariants.isParanoid())
@@ -499,7 +497,9 @@ public void reportEpochClosed(Ranges ranges, long epoch)
499497
if (epoch < minEpoch() || epochs.wasTruncated(epoch))
500498
return;
501499

502-
syncPropagator.reportClosed(epoch, mapping.nodes(), ranges);
500+
Topology topology = getTopologyForEpoch(epoch);
501+
if (topology != null)
502+
syncPropagator.reportClosed(epoch, topology.nodes(), ranges);
503503
}
504504

505505
@VisibleForTesting
@@ -516,7 +516,9 @@ public void reportEpochRetired(Ranges ranges, long epoch)
516516

517517
checkStarted();
518518
// TODO (expected): ensure we aren't fetching a truncated epoch; otherwise this should be non-null
519-
syncPropagator.reportRetired(epoch, mapping.nodes(), ranges);
519+
Topology topology = getTopologyForEpoch(epoch);
520+
if (topology != null)
521+
syncPropagator.reportRetired(epoch, topology.nodes(), ranges);
520522
}
521523

522524
@Override

src/java/org/apache/cassandra/service/accord/AccordService.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,6 @@ public synchronized static AccordService startup(NodeId tcmId)
298298

299299
AccordService as = new AccordService(AccordTopology.tcmIdToAccord(tcmId));
300300
as.startup();
301-
instance = as;
302-
303-
AccordReplicaMetrics.touch();
304-
305301
replayJournal(as);
306302

307303
as.finishInitialization();
@@ -320,6 +316,8 @@ public synchronized static AccordService startup(NodeId tcmId)
320316
as.configService.registerListener(as.node.durability());
321317
as.node.durability().start();
322318

319+
instance = as;
320+
AccordReplicaMetrics.touch();
323321
WatermarkCollector.fetchAndReportWatermarksAsync(as.configService);
324322
return as;
325323
}
@@ -456,6 +454,27 @@ public synchronized void startup()
456454
// Replay local epochs
457455
for (ImmutableTopoloyImage image : images)
458456
configService.reportTopology(image.global);
457+
458+
// Subscribe to TCM events
459+
ChangeListener prevListener = MetadataChangeListener.instance.collector.getAndSet(new ChangeListener()
460+
{
461+
@Override
462+
public void notifyPostCommit(ClusterMetadata prev, ClusterMetadata next, boolean fromSnapshot)
463+
{
464+
if (state != State.SHUTDOWN)
465+
configService.maybeReportMetadata(next);
466+
}
467+
});
468+
469+
Invariants.require((prevListener instanceof MetadataChangeListener.PreInitStateCollector),
470+
"Listener should have been initialized with Accord pre-init state collector, but was " + prevListener.getClass());
471+
472+
MetadataChangeListener.PreInitStateCollector preinit = (MetadataChangeListener.PreInitStateCollector) prevListener;
473+
for (ClusterMetadata item : preinit.getItems())
474+
{
475+
if (item.epoch.getEpoch() > Epoch.FIRST.getEpoch())
476+
configService.maybeReportMetadata(item);
477+
}
459478
}
460479

461480
/**
@@ -476,27 +495,6 @@ public void finishInitialization()
476495

477496
if (remote != null)
478497
remote.forEach(configService::reportTopology, highestKnown + 1, Integer.MAX_VALUE);
479-
480-
// Subscribe to TCM events
481-
ChangeListener prevListener = MetadataChangeListener.instance.collector.getAndSet(new ChangeListener()
482-
{
483-
@Override
484-
public void notifyPostCommit(ClusterMetadata prev, ClusterMetadata next, boolean fromSnapshot)
485-
{
486-
if (state != State.SHUTDOWN)
487-
configService.maybeReportMetadata(next);
488-
}
489-
});
490-
491-
Invariants.require((prevListener instanceof MetadataChangeListener.PreInitStateCollector),
492-
"Listener should have been initialized with Accord pre-init state collector, but was " + prevListener.getClass());
493-
494-
MetadataChangeListener.PreInitStateCollector preinit = (MetadataChangeListener.PreInitStateCollector) prevListener;
495-
for (ClusterMetadata item : preinit.getItems())
496-
{
497-
if (item.epoch.getEpoch() > minEpoch())
498-
configService.maybeReportMetadata(item);
499-
}
500498
}
501499
catch (InterruptedException e)
502500
{

test/simulator/main/org/apache/cassandra/simulator/paxos/AccordSimulationRunner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class AccordSimulationRunner extends SimulationRunner
4747
@BeforeClass
4848
public static void beforeAll()
4949
{
50-
CassandraRelevantProperties.JUNIT_STORAGE_COMPATIBILITY_MODE.setString(StorageCompatibilityMode.NONE.toString());
5150
DatabaseDescriptor.clientInitialization();
5251
}
5352

0 commit comments

Comments
 (0)