slfan1989 commented on code in PR #5131:
URL: https://github.com/apache/hadoop/pull/5131#discussion_r1035905558


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/RouterStoreToken.java:
##########
@@ -22,6 +22,7 @@
 import org.apache.hadoop.yarn.security.client.YARNDelegationTokenIdentifier;
 import org.apache.hadoop.yarn.util.Records;
 
+import java.io.DataInput;

Review Comment:
   We used the `readFields` method, which requires `DataInput` parameters.
   
   RouterStoreToken#readFields
   ```
    public abstract void readFields(DataInput in) throws IOException;
   ```
   
   When we store `RouterStoreToken`, we convert token into a byte array, and 
then store it in `ZK`
   
   ```
   private void storeOrUpdateRouterRMDT(RouterRMTokenRequest request,  boolean 
isUpdate)
         throws Exception {
       RouterStoreToken routerStoreToken  = request.getRouterStoreToken();
       String nodeCreatePath = getStoreTokenZNodePathByTokenRequest(request);
       LOG.debug("nodeCreatePath = {}, isUpdate = {}", nodeCreatePath, 
isUpdate);
       put(nodeCreatePath, routerStoreToken.toByteArray(), isUpdate);
    }
   ```
   
   When we need to read data, we convert the bytes array stored in `ZK` into 
`DataInputStream`, and then let `RouterStoreToken` parse the `required fields` 
from it.
   
   ```
   private RouterStoreToken getStoreTokenFromZK(String nodePath, boolean quiet)
         throws IOException {
       try {
         byte[] data = get(nodePath);
         if ((data == null) || (data.length == 0)) {
           return null;
         }
         ByteArrayInputStream bin = new ByteArrayInputStream(data);
         DataInputStream din = new DataInputStream(bin);
         RouterStoreToken storeToken = 
Records.newRecord(RouterStoreToken.class);
         storeToken.readFields(din);
         return storeToken;
       } catch (Exception ex) {
         if (!quiet) {
           LOG.error("No node in path [" + nodePath + "]");
         }
         throw new IOException(ex);
       }
     }
   ```
   
   



-- 
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: common-issues-unsubscr...@hadoop.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to