forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: adjusts conformance protocol layer objects * feat: repair problems * refactor: reafctor consistency model
- Loading branch information
1 parent
c183b77
commit bcd62d5
Showing
34 changed files
with
411 additions
and
3,301 deletions.
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
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
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 |
---|---|---|
|
@@ -22,15 +22,15 @@ | |
/** | ||
* Consistent protocol related configuration objects. | ||
* | ||
* <p>{@link LogProcessor} : The consistency protocol provides services for all businesses, but each business only cares | ||
* <p>{@link RequestProcessor} : The consistency protocol provides services for all businesses, but each business only cares | ||
* about the transaction information belonging to that business, and the transaction processing between the various | ||
* services should not block each other. Therefore, the LogProcessor is abstracted to implement the parallel processing | ||
* of transactions of different services. Corresponding LogProcessor sub-interface: LogProcessor4AP or LogProcessor4CP, | ||
* different consistency protocols will actively discover the corresponding LogProcessor | ||
* | ||
* @author <a href="mailto:[email protected]">liaochuntao</a> | ||
*/ | ||
public interface Config<L extends LogProcessor> extends Serializable { | ||
public interface Config<L extends RequestProcessor> extends Serializable { | ||
|
||
/** | ||
* Set the cluster node information to initialize,like [ip:port, ip:port, ip:port]. | ||
|
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 |
---|---|---|
|
@@ -16,9 +16,9 @@ | |
|
||
package com.alibaba.nacos.consistency; | ||
|
||
import com.alibaba.nacos.consistency.entity.GetRequest; | ||
import com.alibaba.nacos.consistency.entity.Log; | ||
import com.alibaba.nacos.consistency.entity.ReadRequest; | ||
import com.alibaba.nacos.consistency.entity.Response; | ||
import com.alibaba.nacos.consistency.entity.WriteRequest; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
@@ -37,7 +37,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">liaochuntao</a> | ||
*/ | ||
public interface ConsistencyProtocol<T extends Config, P extends LogProcessor> extends CommandOperations { | ||
public interface ConsistencyProtocol<T extends Config, P extends RequestProcessor> extends CommandOperations { | ||
|
||
/** | ||
* Consistency protocol initialization: perform initialization operations based on the incoming. | ||
|
@@ -50,7 +50,7 @@ public interface ConsistencyProtocol<T extends Config, P extends LogProcessor> e | |
/** | ||
* Add a log handler. | ||
* | ||
* @param processors {@link LogProcessor} | ||
* @param processors {@link RequestProcessor} | ||
*/ | ||
void addLogProcessors(Collection<P> processors); | ||
|
||
|
@@ -69,35 +69,35 @@ public interface ConsistencyProtocol<T extends Config, P extends LogProcessor> e | |
* @return data {@link Response} | ||
* @throws Exception {@link Exception} | ||
*/ | ||
Response getData(GetRequest request) throws Exception; | ||
Response getData(ReadRequest request) throws Exception; | ||
|
||
/** | ||
* Get data asynchronously. | ||
* | ||
* @param request request | ||
* @return data {@link CompletableFuture} | ||
*/ | ||
CompletableFuture<Response> aGetData(GetRequest request); | ||
CompletableFuture<Response> aGetData(ReadRequest request); | ||
|
||
/** | ||
* Data operation, returning submission results synchronously. | ||
* 同步数据提交,在 Datum 中已携带相应的数据操作信息 | ||
* | ||
* @param data {@link Log} | ||
* @param request {@link com.alibaba.nacos.consistency.entity.WriteRequest} | ||
* @return submit operation result {@link Response} | ||
* @throws Exception {@link Exception} | ||
*/ | ||
Response submit(Log data) throws Exception; | ||
Response submit(WriteRequest request) throws Exception; | ||
|
||
/** | ||
* Data submission operation, returning submission results asynchronously. | ||
* 异步数据提交,在 Datum中已携带相应的数据操作信息,返回一个Future,自行操作,提交发生的异常会在CompleteFuture中 | ||
* | ||
* @param data {@link Log} | ||
* @param request {@link com.alibaba.nacos.consistency.entity.WriteRequest} | ||
* @return {@link CompletableFuture} submit result | ||
* @throws Exception when submit throw Exception | ||
*/ | ||
CompletableFuture<Response> submitAsync(Log data); | ||
CompletableFuture<Response> submitAsync(WriteRequest request); | ||
|
||
/** | ||
* New member list . | ||
|
97 changes: 97 additions & 0 deletions
97
consistency/src/main/java/com/alibaba/nacos/consistency/ProtoMessageUtil.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,97 @@ | ||
/* | ||
* Copyright 1999-2018 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.consistency; | ||
|
||
import com.alibaba.nacos.consistency.entity.GetRequest; | ||
import com.alibaba.nacos.consistency.entity.Log; | ||
import com.alibaba.nacos.consistency.entity.ReadRequest; | ||
import com.alibaba.nacos.consistency.entity.WriteRequest; | ||
import com.alibaba.nacos.consistency.exception.ConsistencyException; | ||
import com.google.protobuf.Message; | ||
|
||
/** | ||
* protobuf message utils. | ||
* | ||
* @author <a href="mailto:[email protected]">liaochuntao</a> | ||
*/ | ||
public class ProtoMessageUtil { | ||
|
||
/** | ||
* Converts the byte array to a specific Protobuf object. | ||
* Internally, the protobuf new and old objects are compatible. | ||
* | ||
* @param bytes An array of bytes | ||
* @return Message | ||
*/ | ||
public static Message parse(byte[] bytes) { | ||
Message result; | ||
try { | ||
result = WriteRequest.parseFrom(bytes); | ||
return result; | ||
} catch (Throwable ignore) { | ||
} | ||
try { | ||
result = ReadRequest.parseFrom(bytes); | ||
return result; | ||
} catch (Throwable ignore) { | ||
} | ||
|
||
// old consistency entity, will be @Deprecated in future | ||
try { | ||
Log log = Log.parseFrom(bytes); | ||
return convertToWriteRequest(log); | ||
} catch (Throwable ignore) { | ||
} | ||
|
||
try { | ||
GetRequest request = GetRequest.parseFrom(bytes); | ||
return convertToReadRequest(request); | ||
} catch (Throwable ignore) { | ||
} | ||
|
||
throw new ConsistencyException("The current array cannot be serialized to the corresponding object"); | ||
} | ||
|
||
/** | ||
* convert Log to WriteRequest. | ||
* | ||
* @param log log | ||
* @return {@link WriteRequest} | ||
*/ | ||
public static WriteRequest convertToWriteRequest(Log log) { | ||
return WriteRequest.newBuilder().setKey(log.getKey()).setGroup(log.getGroup()) | ||
.setData(log.getData()) | ||
.setType(log.getType()) | ||
.setOperation(log.getOperation()) | ||
.putAllExtendInfo(log.getExtendInfoMap()) | ||
.build(); | ||
} | ||
|
||
/** | ||
* convert Log to ReadRequest. | ||
* | ||
* @param request request | ||
* @return {@link ReadRequest} | ||
*/ | ||
public static ReadRequest convertToReadRequest(GetRequest request) { | ||
return ReadRequest.newBuilder() | ||
.setGroup(request.getGroup()) | ||
.setData(request.getData()) | ||
.putAllExtendInfo(request.getExtendInfoMap()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.