This is an automated email from the ASF dual-hosted git repository. agura pushed a commit to branch ignite-14754 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit b7d5128cde7094b7f4fa93d820a82d44bb8af2f9 Author: Andrey Gura <[email protected]> AuthorDate: Thu May 20 20:46:17 2021 +0300 IGNITE-14754 Improved assertion message in meta storage server operation. --- .../apache/ignite/internal/util/IgniteUtils.java | 48 +++++++++++++++++++++- .../internal/metastorage/server/Operation.java | 7 ++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 60d637b..61fd09d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -24,11 +24,14 @@ import java.util.LinkedHashMap; * Collection of utility methods used throughout the system. */ public class IgniteUtils { + /** Byte bit-mask. */ + private static final int MASK = 0xf; + /** Version of the JDK. */ private static String jdkVer; - /** - * Initializes enterprise check. + /* + Initializes enterprise check. */ static { IgniteUtils.jdkVer = System.getProperty("java.specification.version"); @@ -167,4 +170,45 @@ public class IgniteUtils { return hash(val); } + + /** + * Converts byte array to hex string. + * + * @param arr Array of bytes. + * @return Hex string. + */ + public static String toHexString(byte[] arr) { + return toHexString(arr, Integer.MAX_VALUE); + } + + /** + * Converts byte array to hex string. + * + * @param arr Array of bytes. + * @param maxLen Maximum length of result string. Rounds down to a power of two. + * @return Hex string. + */ + public static String toHexString(byte[] arr, int maxLen) { + assert maxLen >=0 : "maxLem must be not negative."; + + int capacity = Math.min(arr.length << 1, maxLen); + + int lim = capacity >> 1; + + StringBuilder sb = new StringBuilder(capacity); + + for (int i = 0; i < lim; i++) + addByteAsHex(sb, arr[i]); + + return sb.toString().toUpperCase(); + } + + + /** + * @param sb String builder. + * @param b Byte to add in hexadecimal format. + */ + private static void addByteAsHex(StringBuilder sb, byte b) { + sb.append(Integer.toHexString(MASK & b >>> 4)).append(Integer.toHexString(MASK & b)); + } } diff --git a/modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/Operation.java b/modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/Operation.java index 4c69d7d..458e78a 100644 --- a/modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/Operation.java +++ b/modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/Operation.java @@ -17,8 +17,8 @@ package org.apache.ignite.internal.metastorage.server; -import java.util.Objects; import org.apache.ignite.internal.metastorage.common.OperationType; +import org.apache.ignite.internal.util.IgniteUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -63,8 +63,9 @@ public final class Operation { assert (type == OperationType.NO_OP && key == null && val == null) || (type == OperationType.PUT && key != null && val != null) || (type == OperationType.REMOVE && key != null && val == null) - : "Invalid operation parameters: [type=" + type + ", key=" + Objects.toString(key,"null") + - ", val=" + Objects.toString(key,"null") + ']'; + : "Invalid operation parameters: [type=" + type + + ", key=" + (key == null ? "null" : IgniteUtils.toHexString(key, 256)) + + ", val=" + (val == null ? "null" : IgniteUtils.toHexString(val, 256)) + ']'; this.key = key; this.val = val;
