Beispiel #1
0
 /// <exception cref="System.IO.IOException"/>
 internal RegisteredShm(string clientName, ShortCircuitShm.ShmId shmId, FileInputStream
                        stream, ShortCircuitRegistry registry)
     : base(shmId, stream)
 {
     this.clientName = clientName;
     this.registry   = registry;
 }
Beispiel #2
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);
     }
 }
Beispiel #3
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);
 }
Beispiel #4
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 + ")");
         }
     }
 }
Beispiel #5
0
 internal NewShmInfo(ShortCircuitShm.ShmId shmId, FileInputStream stream)
 {
     this.shmId  = shmId;
     this.stream = stream;
 }