Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions core/src/main/scala/kafka/server/SharedServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ class SharedServer(
name = "metadata loading",
fatal = sharedServerConfig.processRoles.contains(ControllerRole),
action = () => SharedServer.this.synchronized {
if (brokerMetrics != null) brokerMetrics.metadataLoadErrorCount.getAndIncrement()
if (controllerServerMetrics != null) controllerServerMetrics.incrementMetadataErrorCount()
Option(brokerMetrics).foreach(_.metadataLoadErrorCount.getAndIncrement())
Option(controllerServerMetrics).foreach(_.incrementMetadataErrorCount())
snapshotsDiabledReason.compareAndSet(null, "metadata loading fault")
})

Expand All @@ -176,7 +176,7 @@ class SharedServer(
name = "controller startup",
fatal = true,
action = () => SharedServer.this.synchronized {
if (controllerServerMetrics != null) controllerServerMetrics.incrementMetadataErrorCount()
Option(controllerServerMetrics).foreach(_.incrementMetadataErrorCount())
snapshotsDiabledReason.compareAndSet(null, "controller startup fault")
})

Expand All @@ -187,8 +187,8 @@ class SharedServer(
name = "initial broker metadata loading",
fatal = true,
action = () => SharedServer.this.synchronized {
if (brokerMetrics != null) brokerMetrics.metadataApplyErrorCount.getAndIncrement()
if (controllerServerMetrics != null) controllerServerMetrics.incrementMetadataErrorCount()
Option(brokerMetrics).foreach(_.metadataApplyErrorCount.getAndIncrement())
Option(controllerServerMetrics).foreach(_.incrementMetadataErrorCount())
snapshotsDiabledReason.compareAndSet(null, "initial broker metadata loading fault")
})

Expand All @@ -199,7 +199,7 @@ class SharedServer(
name = "quorum controller",
fatal = true,
action = () => SharedServer.this.synchronized {
if (controllerServerMetrics != null) controllerServerMetrics.incrementMetadataErrorCount()
Option(controllerServerMetrics).foreach(_.incrementMetadataErrorCount())
snapshotsDiabledReason.compareAndSet(null, "quorum controller fault")
})

Expand All @@ -210,8 +210,8 @@ class SharedServer(
name = "metadata publishing",
fatal = false,
action = () => SharedServer.this.synchronized {
if (brokerMetrics != null) brokerMetrics.metadataApplyErrorCount.getAndIncrement()
if (controllerServerMetrics != null) controllerServerMetrics.incrementMetadataErrorCount()
Option(brokerMetrics).foreach(_.metadataApplyErrorCount.getAndIncrement())
Option(controllerServerMetrics).foreach(_.incrementMetadataErrorCount())
// Note: snapshot generation does not need to be disabled for a publishing fault.
})

Expand All @@ -234,7 +234,7 @@ class SharedServer(
if (sharedServerConfig.processRoles.contains(ControllerRole)) {
controllerServerMetrics = new ControllerMetadataMetrics(Optional.of(KafkaYammerMetrics.defaultRegistry()))
}
raftManager = new KafkaRaftManager[ApiMessageAndVersion](
val _raftManager = new KafkaRaftManager[ApiMessageAndVersion](
metaProps,
sharedServerConfig,
new MetadataRecordSerde,
Expand All @@ -246,21 +246,22 @@ class SharedServer(
controllerQuorumVotersFuture,
raftManagerFaultHandler
)
raftManager.startup()
raftManager = _raftManager
_raftManager.startup()

val loaderBuilder = new MetadataLoader.Builder().
setNodeId(metaProps.nodeId).
setTime(time).
setThreadNamePrefix(s"kafka-${sharedServerConfig.nodeId}-").
setFaultHandler(metadataLoaderFaultHandler).
setHighWaterMarkAccessor(() => raftManager.client.highWatermark())
setHighWaterMarkAccessor(() => _raftManager.client.highWatermark())
if (brokerMetrics != null) {
loaderBuilder.setMetadataLoaderMetrics(brokerMetrics)
}
loader = loaderBuilder.build()
snapshotEmitter = new SnapshotEmitter.Builder().
setNodeId(metaProps.nodeId).
setRaftClient(raftManager.client).
setRaftClient(_raftManager.client).
build()
snapshotGenerator = new SnapshotGenerator.Builder(snapshotEmitter).
setNodeId(metaProps.nodeId).
Expand All @@ -271,7 +272,7 @@ class SharedServer(
setDisabledReason(snapshotsDiabledReason).
setThreadNamePrefix(s"kafka-${sharedServerConfig.nodeId}-").
build()
raftManager.register(loader)
_raftManager.register(loader)
try {
loader.installPublishers(Collections.singletonList(snapshotGenerator))
} catch {
Expand All @@ -294,10 +295,10 @@ class SharedServer(
def ensureNotRaftLeader(): Unit = synchronized {
// Ideally, this would just resign our leadership, if we had it. But we don't have an API in
// RaftManager for that yet, so shut down the RaftManager.
if (raftManager != null) {
CoreUtils.swallow(raftManager.shutdown(), this)
Option(raftManager).foreach(_raftManager => {
CoreUtils.swallow(_raftManager.shutdown(), this)
raftManager = null
}
})
}

private def stop(): Unit = synchronized {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void testSize() throws Exception {
assertFalse(queue.isEmpty());
queue.cancelDeferred("later");
queue.cancelDeferred("soon");
assertTrue(queue.isEmpty());
TestUtils.waitForCondition(() -> queue.isEmpty(), "Failed to see the queue become empty.");
queue.close();
assertTrue(queue.isEmpty());
}
Expand Down Expand Up @@ -412,4 +412,4 @@ public void testInterruptedWithDeferredEvents() throws Exception {
assertEquals(InterruptedException.class, ieTrapper2.exception.get().getClass());
queue.close();
}
}
}