Esempio n. 1
0
 /// <exception cref="Org.Apache.Hadoop.FS.InvalidRequestException"/>
 public virtual void UnregisterSlot(ShortCircuitShm.SlotId slotId)
 {
     lock (this)
     {
         if (!enabled)
         {
             if (Log.IsTraceEnabled())
             {
                 Log.Trace("unregisterSlot: ShortCircuitRegistry is " + "not enabled.");
             }
             throw new NotSupportedException();
         }
         ShortCircuitShm.ShmId shmId            = slotId.GetShmId();
         ShortCircuitRegistry.RegisteredShm shm = segments[shmId];
         if (shm == null)
         {
             throw new InvalidRequestException("there is no shared memory segment " + "registered with shmId "
                                               + shmId);
         }
         ShortCircuitShm.Slot slot = shm.GetSlot(slotId.GetSlotIdx());
         slot.MakeInvalid();
         shm.UnregisterSlot(slotId.GetSlotIdx());
         slots.Remove(slot.GetBlockId(), slot);
     }
 }
Esempio n. 2
0
 /// <summary>Handle a DFSClient request to create a new memory segment.</summary>
 /// <param name="clientName">Client name as reported by the client.</param>
 /// <param name="sock">
 /// The DomainSocket to associate with this memory
 /// segment.  When this socket is closed, or the
 /// other side writes anything to the socket, the
 /// segment will be closed.  This can happen at any
 /// time, including right after this function returns.
 /// </param>
 /// <returns>
 /// A NewShmInfo object.  The caller must close the
 /// NewShmInfo object once they are done with it.
 /// </returns>
 /// <exception cref="System.IO.IOException">If the new memory segment could not be created.
 ///     </exception>
 public virtual ShortCircuitRegistry.NewShmInfo CreateNewMemorySegment(string clientName
                                                                       , DomainSocket sock)
 {
     ShortCircuitRegistry.NewShmInfo    info = null;
     ShortCircuitRegistry.RegisteredShm shm  = null;
     ShortCircuitShm.ShmId shmId             = null;
     lock (this)
     {
         if (!enabled)
         {
             if (Log.IsTraceEnabled())
             {
                 Log.Trace("createNewMemorySegment: ShortCircuitRegistry is " + "not enabled.");
             }
             throw new NotSupportedException();
         }
         FileInputStream fis = null;
         try
         {
             do
             {
                 shmId = ShortCircuitShm.ShmId.CreateRandom();
             }while (segments.Contains(shmId));
             fis = shmFactory.CreateDescriptor(clientName, ShmLength);
             shm = new ShortCircuitRegistry.RegisteredShm(clientName, shmId, fis, this);
         }
         finally
         {
             if (shm == null)
             {
                 IOUtils.CloseQuietly(fis);
             }
         }
         info            = new ShortCircuitRegistry.NewShmInfo(shmId, fis);
         segments[shmId] = shm;
     }
     // Drop the registry lock to prevent deadlock.
     // After this point, RegisteredShm#handle may be called at any time.
     watcher.Add(sock, shm);
     if (Log.IsTraceEnabled())
     {
         Log.Trace("createNewMemorySegment: created " + info.shmId);
     }
     return(info);
 }
Esempio n. 3
0
 /// <exception cref="Org.Apache.Hadoop.FS.InvalidRequestException"/>
 public virtual void RegisterSlot(ExtendedBlockId blockId, ShortCircuitShm.SlotId
                                  slotId, bool isCached)
 {
     lock (this)
     {
         if (!enabled)
         {
             if (Log.IsTraceEnabled())
             {
                 Log.Trace(this + " can't register a slot because the " + "ShortCircuitRegistry is not enabled."
                           );
             }
             throw new NotSupportedException();
         }
         ShortCircuitShm.ShmId shmId            = slotId.GetShmId();
         ShortCircuitRegistry.RegisteredShm shm = segments[shmId];
         if (shm == null)
         {
             throw new InvalidRequestException("there is no shared memory segment " + "registered with shmId "
                                               + shmId);
         }
         ShortCircuitShm.Slot slot = shm.RegisterSlot(slotId.GetSlotIdx(), blockId);
         if (isCached)
         {
             slot.MakeAnchorable();
         }
         else
         {
             slot.MakeUnanchorable();
         }
         bool added = slots.Put(blockId, slot);
         Preconditions.CheckState(added);
         if (Log.IsTraceEnabled())
         {
             Log.Trace(this + ": registered " + blockId + " with slot " + slotId + " (isCached="
                       + isCached + ")");
         }
     }
 }
Esempio n. 4
0
 public virtual void RemoveShm(ShortCircuitShm shm)
 {
     lock (this)
     {
         if (Log.IsTraceEnabled())
         {
             Log.Debug("removing shm " + shm);
         }
         // Stop tracking the shmId.
         ShortCircuitRegistry.RegisteredShm removedShm = Sharpen.Collections.Remove(segments
                                                                                    , shm.GetShmId());
         Preconditions.CheckState(removedShm == shm, "failed to remove " + shm.GetShmId());
         // Stop tracking the slots.
         for (IEnumerator <ShortCircuitShm.Slot> iter = shm.SlotIterator(); iter.HasNext();)
         {
             ShortCircuitShm.Slot slot = iter.Next();
             bool removed = slots.Remove(slot.GetBlockId(), slot);
             Preconditions.CheckState(removed);
             slot.MakeInvalid();
         }
         // De-allocate the memory map and close the shared file.
         shm.Free();
     }
 }