SammyVimes commented on a change in pull request #203: URL: https://github.com/apache/ignite-3/pull/203#discussion_r673113887
########## File path: modules/metastorage-server/src/main/java/org/apache/ignite/internal/metastorage/server/persistence/RocksStorageUtils.java ########## @@ -0,0 +1,284 @@ +/* + * 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.ignite.internal.metastorage.server.persistence; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.VarHandle; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.ignite.internal.metastorage.server.Value; +import org.apache.ignite.lang.IgniteInternalException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.rocksdb.RocksDBException; +import org.rocksdb.RocksIterator; + +import static org.apache.ignite.internal.metastorage.server.Value.TOMBSTONE; + +/** + * Utility class for {@link RocksDBKeyValueStorage}. + */ +class RocksStorageUtils { + /** Byte order for the {@link RocksDBKeyValueStorage} must be little endian for a correct lexicographic order comparation. */ + private static final ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN; + + /** VarHandle that gives the access to the elements of a {@code byte[]} array viewed as if it were a {@code long[]} array. */ + private static final VarHandle LONG_ARRAY_HANDLE = MethodHandles.byteArrayViewVarHandle(long[].class, BYTE_ORDER); + + /** + * Convert a long value to a byte array. + * + * @param value Value. + * @return Byte array. + */ + static byte[] longToBytes(long value) { + var buffer = new byte[Long.BYTES]; + + LONG_ARRAY_HANDLE.set(buffer, 0, value); + + return buffer; + } + + /** + * Convert a byte array to a long value. + * + * @param array Byte array. + * @return Long value. + */ + static long bytesToLong(byte[] array) { Review comment: This method is Little Endian whereas ByteUtils#bytesToLong is Big Endian -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
