From 74ff022efcddae7a70f1a833409da693c84f9f6c Mon Sep 17 00:00:00 2001
From: liuxunorg <33611720@qq.com>
Date: Sat, 14 Jul 2018 11:25:18 +0800
Subject: [PATCH] [ZEPPELIN-3610] Cluster Raft module design
What is this PR for?
By using the Raft protocol, multiple Zeppelin-Server groups are built into a Zeppelin cluster, the cluster State Machine is maintained through the Raft protocol, and the services in the cluster are agreed upon. The Zeppelin-Server and Zeppelin-Interperter services and processes are stored in the Cluster MetaData. Metadata information;
What type of PR is it?
[Feature]
Todos
- - Added support for checking lambda syntax styles in the pom.xml file
- add raft algorithm copycat jar
- add Cluster State Machine
- add state machine query command
- add state machine delete command
- add state machine put command
What is the Jira issue?
- https://issues.apache.org/jira/browse/ZEPPELIN-3610
How should this be tested?
CI pass
Screenshots (if appropriate)
Questions:
- Does the licenses files need update? No
- Is there breaking changes for older versions? No
- Does this needs documentation? No
---
pom.xml | 7 +
zeppelin-interpreter/pom.xml | 51 +++++
.../zeppelin/cluster/ClusterStateMachine.java | 88 +++++++++
.../zeppelin/cluster/DeleteCommand.java | 41 ++++
.../org/apache/zeppelin/cluster/GetQuery.java | 40 ++++
.../apache/zeppelin/cluster/PutCommand.java | 49 +++++
.../zeppelin/cluster/meta/ClusterMeta.java | 144 ++++++++++++++
.../cluster/meta/ClusterMetaEntity.java | 57 ++++++
.../cluster/meta/ClusterMetaOperation.java | 25 +++
.../cluster/meta/ClusterMetaType.java | 25 +++
.../zeppelin/cluster/ClusterMetaTest.java | 185 ++++++++++++++++++
11 files changed, 712 insertions(+)
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/ClusterStateMachine.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/DeleteCommand.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/GetQuery.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/PutCommand.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/meta/ClusterMeta.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/meta/ClusterMetaEntity.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/meta/ClusterMetaOperation.java
create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/meta/ClusterMetaType.java
create mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/cluster/ClusterMetaTest.java
diff --git a/pom.xml b/pom.xml
index 76dc327e1e4..ecd860d9bb1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -572,6 +572,13 @@
org.apache.maven.pluginsmaven-checkstyle-plugin${plugin.checkstyle.version}
+
+
+ com.puppycrawl.tools
+ checkstyle
+ 6.11.1
+
+
diff --git a/zeppelin-interpreter/pom.xml b/zeppelin-interpreter/pom.xml
index 4ee10806922..750cdc40c01 100644
--- a/zeppelin-interpreter/pom.xml
+++ b/zeppelin-interpreter/pom.xml
@@ -44,6 +44,9 @@
3.0.31.02.12.1
+ 1.2.9-SNAPSHOT
+ 4.0.23.Final
+ 1.2.12.3
@@ -98,6 +101,54 @@
slf4j-log4j12
+
+
+ io.atomix.copycat
+ copycat-server
+ ${copycat.version}
+
+
+ io.atomix.copycat
+ copycat-client
+ ${copycat.version}
+
+
+ io.netty
+ netty-all
+ ${netty-all.version}
+
+
+ io.atomix.catalyst
+ catalyst-netty
+ ${catalyst-netty.version}
+
+
+ io.netty
+ netty-transport
+
+
+ io.netty
+ netty-buffer
+
+
+ io.netty
+ netty-common
+
+
+ io.netty
+ netty-resolver
+
+
+ io.netty
+ netty-handler
+
+
+ io.netty
+ netty-codec
+
+
+
+
org.apache.maven
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/ClusterStateMachine.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/ClusterStateMachine.java
new file mode 100644
index 00000000000..084398410d6
--- /dev/null
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/ClusterStateMachine.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.zeppelin.cluster;
+
+import io.atomix.copycat.server.Commit;
+import io.atomix.copycat.server.Snapshottable;
+import io.atomix.copycat.server.StateMachine;
+import io.atomix.copycat.server.StateMachineExecutor;
+import io.atomix.copycat.server.storage.snapshot.SnapshotReader;
+import io.atomix.copycat.server.storage.snapshot.SnapshotWriter;
+import org.apache.zeppelin.cluster.meta.ClusterMeta;
+
+/**
+ * Cluster State Machine
+ */
+public class ClusterStateMachine extends StateMachine implements Snapshottable {
+ private ClusterMeta clusterMeta = new ClusterMeta();
+
+ @Override
+ protected void configure(StateMachineExecutor executor) {
+ executor.register(PutCommand.class, this::put);
+ executor.register(GetQuery.class, this::get);
+ executor.register(DeleteCommand.class, this::delete);
+ }
+
+ public Object put(Commit commit) {
+ try {
+ clusterMeta.put(
+ commit.operation().type(),
+ commit.operation().key(), commit.operation().value());
+ } finally {
+ commit.close();
+ }
+ return null;
+ }
+
+ public Object get(Commit commit) {
+ try {
+ return clusterMeta.get(commit.operation().type(), commit.operation().key());
+ } finally {
+ commit.close();
+ }
+ }
+
+ /**
+ * Deletes the value.
+ */
+ private Object delete(Commit commit) {
+ try {
+ if (clusterMeta.contains(commit.operation().type(), commit.operation().key())) {
+ clusterMeta.remove(commit.operation().type(), commit.operation().key());
+ }
+ return null;
+ } finally {
+ commit.close();
+ }
+ }
+
+ // The following two methods come from interfaces that implement Snapshottable,
+ // This interface is implemented to enable the replication server to compress the
+ // local status log.
+ // And form a snapshot (snapshot), when copycat-server restarts,
+ // you can restore the status from the snapshot,
+ // If other servers are added, snapshots can be copied to other servers.
+ @Override
+ public void snapshot(SnapshotWriter writer) {
+ writer.writeObject(clusterMeta);
+ }
+
+ @Override
+ public void install(SnapshotReader reader) {
+ clusterMeta = reader.readObject();
+ }
+}
diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/DeleteCommand.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/DeleteCommand.java
new file mode 100644
index 00000000000..2597c648859
--- /dev/null
+++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/cluster/DeleteCommand.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 the original author or authors.
+ *
+ * Licensed 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 org.apache.zeppelin.cluster;
+
+import io.atomix.copycat.Command;
+import org.apache.zeppelin.cluster.meta.ClusterMetaType;
+
+/**
+ * Command to delete a variable in cluster state machine
+ *
+ */
+public class DeleteCommand implements Command