Exemple #1
0
 /// <exception cref="System.IO.IOException"/>
 public override void StoreContainerKilled(ContainerId containerId)
 {
     lock (this)
     {
         NMStateStoreService.RecoveredContainerState rcs = GetRecoveredContainerState(containerId
                                                                                      );
         rcs.killed = true;
     }
 }
Exemple #2
0
 /// <exception cref="System.IO.IOException"/>
 private NMStateStoreService.RecoveredContainerState GetRecoveredContainerState(ContainerId
                                                                                containerId)
 {
     NMStateStoreService.RecoveredContainerState rcs = containerStates[containerId];
     if (rcs == null)
     {
         throw new IOException("No start request for " + containerId);
     }
     return(rcs);
 }
Exemple #3
0
 /// <exception cref="System.IO.IOException"/>
 public override void StoreContainerDiagnostics(ContainerId containerId, StringBuilder
                                                diagnostics)
 {
     lock (this)
     {
         NMStateStoreService.RecoveredContainerState rcs = GetRecoveredContainerState(containerId
                                                                                      );
         rcs.diagnostics = diagnostics.ToString();
     }
 }
Exemple #4
0
 /// <exception cref="System.IO.IOException"/>
 public override void StoreContainerCompleted(ContainerId containerId, int exitCode
                                              )
 {
     lock (this)
     {
         NMStateStoreService.RecoveredContainerState rcs = GetRecoveredContainerState(containerId
                                                                                      );
         rcs.status   = NMStateStoreService.RecoveredContainerStatus.Completed;
         rcs.exitCode = exitCode;
     }
 }
Exemple #5
0
 /// <exception cref="System.IO.IOException"/>
 public override void StoreContainer(ContainerId containerId, StartContainerRequest
                                     startRequest)
 {
     lock (this)
     {
         NMStateStoreService.RecoveredContainerState rcs = new NMStateStoreService.RecoveredContainerState
                                                               ();
         rcs.startRequest             = startRequest;
         containerStates[containerId] = rcs;
     }
 }
Exemple #6
0
 /// <exception cref="System.IO.IOException"/>
 public override void StoreContainerLaunched(ContainerId containerId)
 {
     lock (this)
     {
         NMStateStoreService.RecoveredContainerState rcs = GetRecoveredContainerState(containerId
                                                                                      );
         if (rcs.exitCode != ContainerExitStatus.Invalid)
         {
             throw new IOException("Container already completed");
         }
         rcs.status = NMStateStoreService.RecoveredContainerStatus.Launched;
     }
 }
Exemple #7
0
 /// <exception cref="System.IO.IOException"/>
 public override IList <NMStateStoreService.RecoveredContainerState> LoadContainersState
     ()
 {
     lock (this)
     {
         // return a copy so caller can't modify our state
         IList <NMStateStoreService.RecoveredContainerState> result = new AList <NMStateStoreService.RecoveredContainerState
                                                                                 >(containerStates.Count);
         foreach (NMStateStoreService.RecoveredContainerState rcs in containerStates.Values)
         {
             NMStateStoreService.RecoveredContainerState rcsCopy = new NMStateStoreService.RecoveredContainerState
                                                                       ();
             rcsCopy.status       = rcs.status;
             rcsCopy.exitCode     = rcs.exitCode;
             rcsCopy.killed       = rcs.killed;
             rcsCopy.diagnostics  = rcs.diagnostics;
             rcsCopy.startRequest = rcs.startRequest;
             result.AddItem(rcsCopy);
         }
         return(new AList <NMStateStoreService.RecoveredContainerState>());
     }
 }
Exemple #8
0
 /// <exception cref="System.IO.IOException"/>
 private NMStateStoreService.RecoveredContainerState LoadContainerState(ContainerId
                                                                        containerId, LeveldbIterator iter, string keyPrefix)
 {
     NMStateStoreService.RecoveredContainerState rcs = new NMStateStoreService.RecoveredContainerState
                                                           ();
     rcs.status = NMStateStoreService.RecoveredContainerStatus.Requested;
     while (iter.HasNext())
     {
         KeyValuePair <byte[], byte[]> entry = iter.PeekNext();
         string key = JniDBFactory.AsString(entry.Key);
         if (!key.StartsWith(keyPrefix))
         {
             break;
         }
         iter.Next();
         string suffix = Sharpen.Runtime.Substring(key, keyPrefix.Length - 1);
         // start with '/'
         if (suffix.Equals(ContainerRequestKeySuffix))
         {
             rcs.startRequest = new StartContainerRequestPBImpl(YarnServiceProtos.StartContainerRequestProto
                                                                .ParseFrom(entry.Value));
         }
         else
         {
             if (suffix.Equals(ContainerDiagsKeySuffix))
             {
                 rcs.diagnostics = JniDBFactory.AsString(entry.Value);
             }
             else
             {
                 if (suffix.Equals(ContainerLaunchedKeySuffix))
                 {
                     if (rcs.status == NMStateStoreService.RecoveredContainerStatus.Requested)
                     {
                         rcs.status = NMStateStoreService.RecoveredContainerStatus.Launched;
                     }
                 }
                 else
                 {
                     if (suffix.Equals(ContainerKilledKeySuffix))
                     {
                         rcs.killed = true;
                     }
                     else
                     {
                         if (suffix.Equals(ContainerExitCodeKeySuffix))
                         {
                             rcs.status   = NMStateStoreService.RecoveredContainerStatus.Completed;
                             rcs.exitCode = System.Convert.ToInt32(JniDBFactory.AsString(entry.Value));
                         }
                         else
                         {
                             throw new IOException("Unexpected container state key: " + key);
                         }
                     }
                 }
             }
         }
     }
     return(rcs);
 }
Exemple #9
0
        /// <exception cref="System.IO.IOException"/>
        public override IList <NMStateStoreService.RecoveredContainerState> LoadContainersState
            ()
        {
            AList <NMStateStoreService.RecoveredContainerState> containers = new AList <NMStateStoreService.RecoveredContainerState
                                                                                        >();
            AList <ContainerId> containersToRemove = new AList <ContainerId>();
            LeveldbIterator     iter = null;

            try
            {
                iter = new LeveldbIterator(db);
                iter.Seek(JniDBFactory.Bytes(ContainersKeyPrefix));
                while (iter.HasNext())
                {
                    KeyValuePair <byte[], byte[]> entry = iter.PeekNext();
                    string key = JniDBFactory.AsString(entry.Key);
                    if (!key.StartsWith(ContainersKeyPrefix))
                    {
                        break;
                    }
                    int idEndPos = key.IndexOf('/', ContainersKeyPrefix.Length);
                    if (idEndPos < 0)
                    {
                        throw new IOException("Unable to determine container in key: " + key);
                    }
                    ContainerId containerId = ConverterUtils.ToContainerId(Sharpen.Runtime.Substring(
                                                                               key, ContainersKeyPrefix.Length, idEndPos));
                    string keyPrefix = Sharpen.Runtime.Substring(key, 0, idEndPos + 1);
                    NMStateStoreService.RecoveredContainerState rcs = LoadContainerState(containerId,
                                                                                         iter, keyPrefix);
                    // Don't load container without StartContainerRequest
                    if (rcs.startRequest != null)
                    {
                        containers.AddItem(rcs);
                    }
                    else
                    {
                        containersToRemove.AddItem(containerId);
                    }
                }
            }
            catch (DBException e)
            {
                throw new IOException(e);
            }
            finally
            {
                if (iter != null)
                {
                    iter.Close();
                }
            }
            // remove container without StartContainerRequest
            foreach (ContainerId containerId_1 in containersToRemove)
            {
                Log.Warn("Remove container " + containerId_1 + " with incomplete records");
                try
                {
                    RemoveContainer(containerId_1);
                }
                catch (IOException e)
                {
                    // TODO: kill and cleanup the leaked container
                    Log.Error("Unable to remove container " + containerId_1 + " in store", e);
                }
            }
            return(containers);
        }