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



##########
File path: 
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/TokenIdentifierCodec.java
##########
@@ -42,8 +42,9 @@ 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) {
+      OzoneTokenIdentifier object = OzoneTokenIdentifier.newInstance();
+      return object.fromUniqueSerializedKey(rawData);
+    } catch (BufferUnderflowException e) {

Review comment:
       We should catch IOException here and fall back to reading the old format 
to avoid OM failures to load tokens in old format upon upgrade/restart. We can 
rewrite the loaded token with the new format like HDDS-3925 upon hitting tokens 
in old format to avoid future fallbacks. But I'm OK without it given old tokens 
in old format will be expired in 7 days anyway (unlike the pipeline id) and the 
new tokens will be written in new format. 
   
   I also suggest we add a unit test like below that can repro the loading 
failure cases in TestOzoneTokenIdentifier.java. 
   ```
     @Test
     public void testTokenPersistence() throws IOException {
       OzoneTokenIdentifier idWrite = getIdentifierInst();
       idWrite.setOmServiceId("defaultServiceId");
   
       byte[] oldIdBytes = idWrite.getBytes();
       TokenIdentifierCodec idCodec = new TokenIdentifierCodec();
   
       OzoneTokenIdentifier idRead = null;
       try {
         idRead =  idCodec.fromPersistedFormat(oldIdBytes);
       } catch (IOException ex) {
         Assert.fail("Should not fail to load old token format");
       }
       Assert.assertEquals("Deserialize Serialized Token should equal.",
           idWrite, idRead);
     }
   ```
      




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to