/// <exception cref="System.Exception"/> private void LoadRMDTSecretManagerState(RMStateStore.RMState rmState) { CheckAndResumeUpdateOperation(rmDTSecretManagerRoot); FileStatus[] childNodes = ListStatusWithRetries(rmDTSecretManagerRoot); foreach (FileStatus childNodeStatus in childNodes) { System.Diagnostics.Debug.Assert(childNodeStatus.IsFile()); string childNodeName = childNodeStatus.GetPath().GetName(); if (CheckAndRemovePartialRecordWithRetries(childNodeStatus.GetPath())) { continue; } if (childNodeName.StartsWith(DelegationTokenSequenceNumberPrefix)) { rmState.rmSecretManagerState.dtSequenceNumber = System.Convert.ToInt32(childNodeName .Split("_")[1]); continue; } Path childNodePath = GetNodePath(rmDTSecretManagerRoot, childNodeName); byte[] childData = ReadFileWithRetries(childNodePath, childNodeStatus.GetLen()); ByteArrayInputStream @is = new ByteArrayInputStream(childData); using (DataInputStream fsIn = new DataInputStream(@is)) { if (childNodeName.StartsWith(DelegationKeyPrefix)) { DelegationKey key = new DelegationKey(); key.ReadFields(fsIn); rmState.rmSecretManagerState.masterKeyState.AddItem(key); if (Log.IsDebugEnabled()) { Log.Debug("Loaded delegation key: keyId=" + key.GetKeyId() + ", expirationDate=" + key.GetExpiryDate()); } } else { if (childNodeName.StartsWith(DelegationTokenPrefix)) { RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData (); identifierData.ReadFields(fsIn); RMDelegationTokenIdentifier identifier = identifierData.GetTokenIdentifier(); long renewDate = identifierData.GetRenewDate(); rmState.rmSecretManagerState.delegationTokenState[identifier] = renewDate; if (Log.IsDebugEnabled()) { Log.Debug("Loaded RMDelegationTokenIdentifier: " + identifier + " renewDate=" + renewDate ); } } else { Log.Warn("Unknown file for recovering RMDelegationTokenSecretManager"); } } } } }
/// <exception cref="System.IO.IOException"/> private int LoadRMDTSecretManagerKeys(RMStateStore.RMState state) { int numKeys = 0; LeveldbIterator iter = null; try { iter = new LeveldbIterator(db); iter.Seek(JniDBFactory.Bytes(RmDtMasterKeyKeyPrefix)); while (iter.HasNext()) { KeyValuePair <byte[], byte[]> entry = iter.Next(); string key = JniDBFactory.AsString(entry.Key); if (!key.StartsWith(RmDtMasterKeyKeyPrefix)) { break; } DelegationKey masterKey = LoadDelegationKey(entry.Value); state.rmSecretManagerState.masterKeyState.AddItem(masterKey); ++numKeys; if (Log.IsDebugEnabled()) { Log.Debug("Loaded RM delegation key from " + key + ": keyId=" + masterKey.GetKeyId () + ", expirationDate=" + masterKey.GetExpiryDate()); } } } catch (DBException e) { throw new IOException(e); } finally { if (iter != null) { iter.Close(); } } return(numKeys); }