You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/08/24 13:23:41 UTC

[GitHub] [ozone] symious commented on a diff in pull request #3082: HDDS-6312. Use KeyPrefixContainer table to accelerate the process of DELETE/UPDATE events

symious commented on code in PR #3082:
URL: https://github.com/apache/ozone/pull/3082#discussion_r953797086


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/KeyPrefixContainerCodec.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.ozone.recon.spi.impl;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.Longs;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.hadoop.hdds.utils.db.Codec;
+import org.apache.hadoop.ozone.recon.api.types.KeyPrefixContainer;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import static org.apache.commons.compress.utils.CharsetNames.UTF_8;
+
+/**
+ * Codec to encode KeyPrefixContainer as byte array.
+ */
+public class KeyPrefixContainerCodec implements Codec<KeyPrefixContainer> {
+
+  private static final String KEY_DELIMITER = "_";
+
+  @Override
+  public byte[] toPersistedFormat(KeyPrefixContainer keyPrefixContainer)
+      throws IOException {
+    Preconditions.checkNotNull(keyPrefixContainer,
+            "Null object can't be converted to byte array.");
+    byte[] keyPrefixBytes = keyPrefixContainer.getKeyPrefix().getBytes(UTF_8);
+
+    //Prefix seek can be done only with keyPrefix. In that case, we can
+    // expect the version and the containerId to be undefined.
+    if (keyPrefixContainer.getKeyVersion() != -1) {
+      keyPrefixBytes = ArrayUtils.addAll(keyPrefixBytes, KEY_DELIMITER
+          .getBytes(UTF_8));
+      keyPrefixBytes = ArrayUtils.addAll(keyPrefixBytes, Longs.toByteArray(
+          keyPrefixContainer.getKeyVersion()));
+    }
+
+    if (keyPrefixContainer.getContainerId() != -1) {
+      keyPrefixBytes = ArrayUtils.addAll(keyPrefixBytes, KEY_DELIMITER
+          .getBytes(UTF_8));
+      keyPrefixBytes = ArrayUtils.addAll(keyPrefixBytes, Longs.toByteArray(
+          keyPrefixContainer.getContainerId()));
+    }
+
+    return keyPrefixBytes;
+  }
+
+  @Override
+  public KeyPrefixContainer fromPersistedFormat(byte[] rawData)
+      throws IOException {
+
+    // When reading from byte[], we can always expect to have the key, version
+    // and version parts in the byte array.
+    byte[] keyBytes = ArrayUtils.subarray(rawData,
+        0, rawData.length - Long.BYTES * 2 - 2);

Review Comment:
   Noted with thanks, I'll try to create a new ticket for this transition.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org