kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject git commit: kafka-1384; Log Broker state; followup commit to add the missing new file
Date Wed, 07 May 2014 01:04:06 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 9b6bf4078 -> 4fe5c4684


kafka-1384; Log Broker state; followup commit to add the missing new file


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/4fe5c468
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/4fe5c468
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/4fe5c468

Branch: refs/heads/trunk
Commit: 4fe5c46848821872fb6e21513cd47d564242c576
Parents: 9b6bf40
Author: Timothy Chen <tnachen@gmail.com>
Authored: Tue May 6 18:03:59 2014 -0700
Committer: Jun Rao <junrao@gmail.com>
Committed: Tue May 6 18:03:59 2014 -0700

----------------------------------------------------------------------
 .../main/scala/kafka/server/BrokerStates.scala  | 80 ++++++++++++++++++++
 1 file changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/4fe5c468/core/src/main/scala/kafka/server/BrokerStates.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/kafka/server/BrokerStates.scala b/core/src/main/scala/kafka/server/BrokerStates.scala
new file mode 100644
index 0000000..e6ee77e
--- /dev/null
+++ b/core/src/main/scala/kafka/server/BrokerStates.scala
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package kafka.server
+
+/**
+ * Broker states are the possible state that a kafka broker can be in.
+ * A broker should be only in one state at a time.
+ * The expected state transition with the following defined states is:
+ *
+ *                +-----------+
+ *                |Not Running|
+ *                +-----+-----+
+ *                      |
+ *                      v
+ *                +-----+-----+
+ *                |Starting   +--+
+ *                +-----+-----+  | +----+------------+
+ *                      |        +>+RecoveringFrom   |
+ *                      v          |UncleanShutdown  |
+ * +----------+     +-----+-----+  +-------+---------+
+ * |RunningAs |     |RunningAs  |            |
+ * |Controller+<--->+Broker     +<-----------+
+ * +----------+     +-----+-----+
+ *        |              |
+ *        |              v
+ *        |       +-----+------------+
+ *        |-----> |PendingControlled |
+ *                |Shutdown          |
+ *                +-----+------------+
+ *                      |
+ *                      v
+ *               +-----+----------+
+ *               |BrokerShutting  |
+ *               |Down            |
+ *               +-----+----------+
+ *                     |
+ *                     v
+ *               +-----+-----+
+ *               |Not Running|
+ *               +-----------+
+ *
+ * Custom states is also allowed for cases where there are custom kafka states for different
scenarios.
+ */
+sealed trait BrokerStates { def state: Byte }
+case object NotRunning extends BrokerStates { val state: Byte = 0 }
+case object Starting extends BrokerStates { val state: Byte = 1 }
+case object RecoveringFromUncleanShutdown extends BrokerStates { val state: Byte = 2 }
+case object RunningAsBroker extends BrokerStates { val state: Byte = 3 }
+case object RunningAsController extends BrokerStates { val state: Byte = 4 }
+case object PendingControlledShutdown extends BrokerStates { val state: Byte = 6 }
+case object BrokerShuttingDown extends BrokerStates { val state: Byte = 7 }
+
+
+case class BrokerState() {
+  @volatile var currentState: Byte = NotRunning.state
+
+  def newState(newState: BrokerStates) {
+    this.newState(newState.state)
+  }
+
+  // Allowing undefined custom state
+  def newState(newState: Byte) {
+    currentState = newState
+  }
+}


Mime
View raw message