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 2020/07/10 06:23:56 UTC

[GitHub] [hadoop-ozone] adoroszlai commented on a change in pull request #1182: HDDS-3926. OM Token Identifier table should use in-house serialization.

adoroszlai commented on a change in pull request #1182:
URL: https://github.com/apache/hadoop-ozone/pull/1182#discussion_r452642927



##########
File path: hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java
##########
@@ -77,6 +79,119 @@ public Text getKind() {
     return KIND_NAME;
   }
 
+  /** Instead of relying on proto serialization, this
+   *  provides  explicit serialization for OzoneTokenIdentifier.
+   * @return byte[]
+   */
+  public byte[] toUniqueSerilizedKey() {

Review comment:
       ```suggestion
     public byte[] toUniqueSerializedKey() {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java
##########
@@ -33,7 +33,7 @@
   public byte[] toPersistedFormat(OzoneTokenIdentifier object) {
     Preconditions
         .checkNotNull(object, "Null object can't be converted to byte array.");
-    return object.getBytes();
+    return object.toUniqueSerilizedKey();

Review comment:
       ```suggestion
       return object.toUniqueSerializedKey();
   ```

##########
File path: hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/security/OzoneTokenIdentifier.java
##########
@@ -77,6 +79,119 @@ public Text getKind() {
     return KIND_NAME;
   }
 
+  /** Instead of relying on proto serialization, this
+   *  provides  explicit serialization for OzoneTokenIdentifier.
+   * @return byte[]
+   */
+  public byte[] toUniqueSerilizedKey() {
+    ByteBuffer result =
+        ByteBuffer.allocate(4096);
+    result.order(ByteOrder.BIG_ENDIAN);
+    try {
+      result.putLong(getIssueDate());
+      result.putInt(getMasterKeyId());
+      result.putInt(getSequenceNumber());
+
+      result.putLong(getMaxDate());
+
+      result.putInt(getOwner().toString().length());
+      result.put(getOwner().toString().getBytes());
+
+      result.putInt(getRealUser().toString().length());
+      result.put(getRealUser().toString().getBytes());
+
+      result.putInt(getRenewer().toString().length());
+      result.put(getRenewer().toString().getBytes());
+
+      result.putInt(getTokenType().getNumber());
+      // Set s3 specific fields.
+      if (getTokenType().equals(S3AUTHINFO)) {
+        result.putInt(getAwsAccessId().length());
+        result.put(getAwsAccessId().getBytes());
+
+        result.putInt(getSignature().length());
+        result.put(getSignature().getBytes());
+
+        result.putInt(getStrToSign().length());
+        result.put(getStrToSign().getBytes());
+      } else {
+        result.putInt(getOmCertSerialId().length());
+        result.put(getOmCertSerialId().getBytes());
+        if (getOmServiceId() != null) {
+          result.putInt(getOmServiceId().length());
+          result.put(getOmServiceId().getBytes());
+        } else {
+          result.putInt(0);
+        }
+      }
+    } catch (IndexOutOfBoundsException e) {
+      throw new IllegalArgumentException(
+          "Can't encode the the raw data ", e);
+    }
+    return result.array();
+  }
+
+  /** Instead of relying on proto deserialization, this
+   *  provides  explicit deserialization for OzoneTokenIdentifier.
+   * @return byte[]
+   */
+  public static OzoneTokenIdentifier fromUniqueSerilizedKey(byte[] rawData) {

Review comment:
       ```suggestion
     public static OzoneTokenIdentifier fromUniqueSerializedKey(byte[] rawData) {
   ```

##########
File path: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java
##########
@@ -42,8 +42,8 @@ public OzoneTokenIdentifier fromPersistedFormat(byte[] rawData)
     Preconditions.checkNotNull(rawData,
         "Null byte array can't converted to real object.");
     try {
-      return OzoneTokenIdentifier.readProtoBuf(rawData);
-    } catch (InvalidProtocolBufferException e) {
+      return OzoneTokenIdentifier.fromUniqueSerilizedKey(rawData);

Review comment:
       ```suggestion
         return OzoneTokenIdentifier.fromUniqueSerializedKey(rawData);
   ```

##########
File path: hadoop-hdds/interface-client/src/main/proto/proto.lock
##########
@@ -1476,6 +1476,21 @@
           }
         ],
         "messages": [
+          {

Review comment:
       > It was auto generated. I did not modify anything here in this file.
   
   Please exclude both proto.lock files from the patch.




----------------------------------------------------------------
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.

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



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