-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IOTDB-2673] Implement the consensus layer basic framework (#5204)
- Loading branch information
1 parent
49bd401
commit a95558e
Showing
29 changed files
with
1,672 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>iotdb-parent</artifactId> | ||
<groupId>org.apache.iotdb</groupId> | ||
<version>0.13.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>iotdb-consensus</artifactId> | ||
<name>IoTDB Consensus</name> | ||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/org.apache.ratis/ratis-server --> | ||
<dependency> | ||
<groupId>org.apache.ratis</groupId> | ||
<artifactId>ratis-server</artifactId> | ||
<version>2.2.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.iotdb</groupId> | ||
<artifactId>iotdb-thrift</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
</project> |
57 changes: 57 additions & 0 deletions
57
consensus/src/main/java/org/apache/iotdb/consensus/IConsensus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.iotdb.consensus; | ||
|
||
import org.apache.iotdb.consensus.common.ConsensusGroupId; | ||
import org.apache.iotdb.consensus.common.Peer; | ||
import org.apache.iotdb.consensus.common.request.IConsensusRequest; | ||
import org.apache.iotdb.consensus.common.response.ConsensusGenericResponse; | ||
import org.apache.iotdb.consensus.common.response.ConsensusReadResponse; | ||
import org.apache.iotdb.consensus.common.response.ConsensusWriteResponse; | ||
|
||
import java.util.List; | ||
|
||
/** Consensus module base class. Each method should be thread-safe */ | ||
public interface IConsensus { | ||
void start(); | ||
|
||
void stop(); | ||
|
||
// write API | ||
ConsensusWriteResponse write(ConsensusGroupId groupId, IConsensusRequest IConsensusRequest); | ||
// read API | ||
ConsensusReadResponse read(ConsensusGroupId groupId, IConsensusRequest IConsensusRequest); | ||
|
||
// multi consensus group API | ||
ConsensusGenericResponse addConsensusGroup(ConsensusGroupId groupId, List<Peer> peers); | ||
|
||
ConsensusGenericResponse removeConsensusGroup(ConsensusGroupId groupId); | ||
|
||
// single consensus group API | ||
ConsensusGenericResponse addPeer(ConsensusGroupId groupId, Peer peer); | ||
|
||
ConsensusGenericResponse removePeer(ConsensusGroupId groupId, Peer peer); | ||
|
||
ConsensusGenericResponse changePeer(ConsensusGroupId groupId, List<Peer> newPeers); | ||
|
||
// management API | ||
ConsensusGenericResponse transferLeader(ConsensusGroupId groupId, Peer newLeader); | ||
|
||
ConsensusGenericResponse triggerSnapshot(ConsensusGroupId groupId); | ||
} |
60 changes: 60 additions & 0 deletions
60
consensus/src/main/java/org/apache/iotdb/consensus/common/ConsensusGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.iotdb.consensus.common; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
// TODO Use a mature IDL framework such as Protobuf to manage this structure | ||
public class ConsensusGroup { | ||
|
||
private final ConsensusGroupId groupId; | ||
private final List<Peer> peers; | ||
|
||
public ConsensusGroup(ConsensusGroupId groupId, List<Peer> peers) { | ||
this.groupId = groupId; | ||
this.peers = peers; | ||
} | ||
|
||
public ConsensusGroupId getGroupId() { | ||
return groupId; | ||
} | ||
|
||
public List<Peer> getPeers() { | ||
return peers; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ConsensusGroup that = (ConsensusGroup) o; | ||
return Objects.equals(groupId, that.groupId) && Objects.equals(peers, that.peers); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(groupId, peers); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
consensus/src/main/java/org/apache/iotdb/consensus/common/ConsensusGroupId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.iotdb.consensus.common; | ||
|
||
import java.util.Objects; | ||
|
||
// TODO Use a mature IDL framework such as Protobuf to manage this structure | ||
public class ConsensusGroupId { | ||
|
||
private final GroupType type; | ||
private final long id; | ||
|
||
public ConsensusGroupId(GroupType type, long id) { | ||
this.type = type; | ||
this.id = id; | ||
} | ||
|
||
public GroupType getType() { | ||
return type; | ||
} | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ConsensusGroupId that = (ConsensusGroupId) o; | ||
return id == that.id && Objects.equals(type, that.type); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(type, id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ConsensusGroupId{" + "type=" + type + ", id=" + id + '}'; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
consensus/src/main/java/org/apache/iotdb/consensus/common/DataSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.iotdb.consensus.common; | ||
|
||
public interface DataSet {} |
59 changes: 59 additions & 0 deletions
59
consensus/src/main/java/org/apache/iotdb/consensus/common/Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.iotdb.consensus.common; | ||
|
||
import java.util.Objects; | ||
|
||
// TODO Use a mature IDL framework such as Protobuf to manage this structure | ||
public class Endpoint { | ||
|
||
private final String ip; | ||
private final int port; | ||
|
||
public Endpoint(String ip, int port) { | ||
this.ip = ip; | ||
this.port = port; | ||
} | ||
|
||
public String getIp() { | ||
return ip; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Endpoint endpoint = (Endpoint) o; | ||
return port == endpoint.port && Objects.equals(ip, endpoint.ip); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(ip, port); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
consensus/src/main/java/org/apache/iotdb/consensus/common/GroupType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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.iotdb.consensus.common; | ||
|
||
// TODO Use a mature IDL framework such as Protobuf to manage this structure | ||
public enum GroupType { | ||
Config, | ||
DataRegion, | ||
SchemaRegion | ||
} |
Oops, something went wrong.