diff options
author | Harald Musum <musum@yahooinc.com> | 2021-09-10 11:13:09 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2021-09-10 11:13:09 +0200 |
commit | f8347a1f41341bd87adf40416a7afa2177d01408 (patch) | |
tree | d926b94578ac11685093082b53c21d1ef6c0f439 /config | |
parent | 01513fb2bef0d0b3021ede9857604b3d8b19cf31 (diff) |
Add checksum types in response based on types in request
Return response with same type as in request, except when both are
empty, then return both types.
Note: No clients have started sending requests with only xxhash64 checksum yet.
Diffstat (limited to 'config')
4 files changed, 45 insertions, 3 deletions
diff --git a/config/src/main/java/com/yahoo/vespa/config/GetConfigRequest.java b/config/src/main/java/com/yahoo/vespa/config/GetConfigRequest.java index 4e90ce532e4..35b503416ce 100644 --- a/config/src/main/java/com/yahoo/vespa/config/GetConfigRequest.java +++ b/config/src/main/java/com/yahoo/vespa/config/GetConfigRequest.java @@ -44,4 +44,11 @@ public interface GetConfigRequest { */ String getRequestDefMd5(); + /** + * Returns the payload checksums from the config request. + * + * @return the payload checksums from request. + */ + PayloadChecksums configPayloadChecksums(); + } diff --git a/config/src/main/java/com/yahoo/vespa/config/PayloadChecksum.java b/config/src/main/java/com/yahoo/vespa/config/PayloadChecksum.java index bb3ac3f76f1..a16e28ac6b6 100644 --- a/config/src/main/java/com/yahoo/vespa/config/PayloadChecksum.java +++ b/config/src/main/java/com/yahoo/vespa/config/PayloadChecksum.java @@ -1,10 +1,17 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config; +import com.yahoo.text.AbstractUtf8Array; +import com.yahoo.vespa.config.protocol.Payload; +import com.yahoo.vespa.config.util.ConfigUtils; + import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.yahoo.vespa.config.PayloadChecksum.Type.MD5; +import static com.yahoo.vespa.config.PayloadChecksum.Type.XXHASH64; + /** * Checksums of config definition payload or config payload, * md5 and xxhash64 are the supported types at the moment. @@ -27,6 +34,24 @@ public class PayloadChecksum { return new PayloadChecksum("", type); } + public static PayloadChecksum fromPayload(Payload payload, Type type) { + switch (type) { + case MD5: return fromMd5Data(payload.getData()); + case XXHASH64: return fromXxhash64Data(payload.getData()); + default: throw new IllegalArgumentException("Unknown type " + type); + } + } + + private static PayloadChecksum fromMd5Data(AbstractUtf8Array data) { + return new PayloadChecksum(ConfigUtils.getMd5(data), MD5); + } + + private static PayloadChecksum fromXxhash64Data(AbstractUtf8Array data) { + return new PayloadChecksum(ConfigUtils.getXxhash64(data), XXHASH64); + } + + public boolean isEmpty() { return checksum.isEmpty(); } + public String asString() { return checksum; } public Type type() { return type; } diff --git a/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequest.java b/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequest.java index 41106e138b7..938da855014 100644 --- a/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequest.java +++ b/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequest.java @@ -85,4 +85,12 @@ public interface JRTServerConfigRequest extends JRTConfigRequest, GetConfigReque */ Payload payloadFromResponse(ConfigResponse response); + + /** + * Returns the payload checksums from the config request. + * + * @return the payload checksumss from request. + */ + PayloadChecksums configPayloadChecksums(); + } diff --git a/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequestV3.java b/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequestV3.java index fbb52e81679..13d0ca1119a 100644 --- a/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequestV3.java +++ b/config/src/main/java/com/yahoo/vespa/config/protocol/JRTServerConfigRequestV3.java @@ -273,7 +273,9 @@ public class JRTServerConfigRequestV3 implements JRTServerConfigRequest { } @Override - public Optional<VespaVersion> getVespaVersion() { - return requestData.getVespaVersion(); - } + public Optional<VespaVersion> getVespaVersion() { return requestData.getVespaVersion(); } + + @Override + public PayloadChecksums configPayloadChecksums() { return requestData.getRequestConfigChecksums(); } + } |