/// <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); } }
/// <exception cref="System.IO.IOException"/> public override void ReleaseShortCircuitFds(ShortCircuitShm.SlotId slotId) { DataTransferProtos.ReleaseShortCircuitAccessRequestProto.Builder builder = DataTransferProtos.ReleaseShortCircuitAccessRequestProto .NewBuilder().SetSlotId(PBHelper.Convert(slotId)); if (Trace.IsTracing()) { Span s = Trace.CurrentSpan(); builder.SetTraceInfo(DataTransferProtos.DataTransferTraceInfoProto.NewBuilder().SetTraceId (s.GetTraceId()).SetParentId(s.GetSpanId())); } DataTransferProtos.ReleaseShortCircuitAccessRequestProto proto = ((DataTransferProtos.ReleaseShortCircuitAccessRequestProto )builder.Build()); Send(@out, OP.ReleaseShortCircuitFds, proto); }
/// <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 + ")"); } } }
/// <summary> /// Receive /// <see cref="OP.RequestShortCircuitFds"/> /// /// </summary> /// <exception cref="System.IO.IOException"/> private void OpRequestShortCircuitFds(DataInputStream @in) { DataTransferProtos.OpRequestShortCircuitAccessProto proto = DataTransferProtos.OpRequestShortCircuitAccessProto .ParseFrom(PBHelper.VintPrefixed(@in)); ShortCircuitShm.SlotId slotId = (proto.HasSlotId()) ? PBHelper.Convert(proto.GetSlotId ()) : null; TraceScope traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetHeader() , proto.GetType().Name); try { RequestShortCircuitFds(PBHelper.Convert(proto.GetHeader().GetBlock()), PBHelper.Convert (proto.GetHeader().GetToken()), slotId, proto.GetMaxVersion(), proto.GetSupportsReceiptVerification ()); } finally { if (traceScope != null) { traceScope.Close(); } } }
/// <exception cref="System.IO.IOException"/> public override void RequestShortCircuitFds(ExtendedBlock blk, Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> blockToken, ShortCircuitShm.SlotId slotId, int maxVersion , bool supportsReceiptVerification) { DataTransferProtos.OpRequestShortCircuitAccessProto.Builder builder = DataTransferProtos.OpRequestShortCircuitAccessProto .NewBuilder().SetHeader(DataTransferProtoUtil.BuildBaseHeader(blk, blockToken)). SetMaxVersion(maxVersion); if (slotId != null) { builder.SetSlotId(PBHelper.Convert(slotId)); } builder.SetSupportsReceiptVerification(supportsReceiptVerification); DataTransferProtos.OpRequestShortCircuitAccessProto proto = ((DataTransferProtos.OpRequestShortCircuitAccessProto )builder.Build()); Send(@out, OP.RequestShortCircuitFds, proto); }
public abstract void RequestShortCircuitFds(ExtendedBlock arg1, Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> arg2, ShortCircuitShm.SlotId arg3, int arg4, bool arg5);
public abstract void ReleaseShortCircuitFds(ShortCircuitShm.SlotId arg1);
/// <summary>Request short circuit access file descriptors from a DataNode.</summary> /// <param name="blk">The block to get file descriptors for.</param> /// <param name="blockToken">Security token for accessing the block.</param> /// <param name="slotId"> /// The shared memory slot id to use, or null /// to use no slot id. /// </param> /// <param name="maxVersion"> /// Maximum version of the block data the client /// can understand. /// </param> /// <param name="supportsReceiptVerification"> /// True if the client supports /// receipt verification. /// </param> /// <exception cref="System.IO.IOException"/> public abstract void RequestShortCircuitFds(ExtendedBlock blk, Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> blockToken, ShortCircuitShm.SlotId slotId, int maxVersion , bool supportsReceiptVerification);
/// <summary>Request file descriptors from a DomainPeer.</summary> /// <param name="peer">The peer to use for communication.</param> /// <param name="slot"> /// If non-null, the shared memory slot to associate with the /// new ShortCircuitReplica. /// </param> /// <returns> /// A ShortCircuitReplica object if we could communicate with the /// datanode; null, otherwise. /// </returns> /// <exception cref="System.IO.IOException"> /// If we encountered an I/O exception while communicating /// with the datanode. /// </exception> private ShortCircuitReplicaInfo RequestFileDescriptors(DomainPeer peer, ShortCircuitShm.Slot slot) { ShortCircuitCache cache = clientContext.GetShortCircuitCache(); DataOutputStream @out = new DataOutputStream(new BufferedOutputStream(peer.GetOutputStream ())); ShortCircuitShm.SlotId slotId = slot == null ? null : slot.GetSlotId(); new Sender(@out).RequestShortCircuitFds(block, token, slotId, 1, failureInjector. GetSupportsReceiptVerification()); DataInputStream @in = new DataInputStream(peer.GetInputStream()); DataTransferProtos.BlockOpResponseProto resp = DataTransferProtos.BlockOpResponseProto .ParseFrom(PBHelper.VintPrefixed(@in)); DomainSocket sock = peer.GetDomainSocket(); failureInjector.InjectRequestFileDescriptorsFailure(); switch (resp.GetStatus()) { case DataTransferProtos.Status.Success: { byte[] buf = new byte[1]; FileInputStream[] fis = new FileInputStream[2]; sock.RecvFileInputStreams(fis, buf, 0, buf.Length); ShortCircuitReplica replica = null; try { ExtendedBlockId key = new ExtendedBlockId(block.GetBlockId(), block.GetBlockPoolId ()); if (buf[0] == DataTransferProtos.ShortCircuitFdResponse.UseReceiptVerification.GetNumber ()) { Log.Trace("Sending receipt verification byte for slot " + slot); sock.GetOutputStream().Write(0); } replica = new ShortCircuitReplica(key, fis[0], fis[1], cache, Time.MonotonicNow() , slot); return(new ShortCircuitReplicaInfo(replica)); } catch (IOException e) { // This indicates an error reading from disk, or a format error. Since // it's not a socket communication problem, we return null rather than // throwing an exception. Log.Warn(this + ": error creating ShortCircuitReplica.", e); return(null); } finally { if (replica == null) { IOUtils.Cleanup(DFSClient.Log, fis[0], fis[1]); } } goto case DataTransferProtos.Status.ErrorUnsupported; } case DataTransferProtos.Status.ErrorUnsupported: { if (!resp.HasShortCircuitAccessVersion()) { Log.Warn("short-circuit read access is disabled for " + "DataNode " + datanode + ". reason: " + resp.GetMessage()); clientContext.GetDomainSocketFactory().DisableShortCircuitForPath(pathInfo.GetPath ()); } else { Log.Warn("short-circuit read access for the file " + fileName + " is disabled for DataNode " + datanode + ". reason: " + resp.GetMessage()); } return(null); } case DataTransferProtos.Status.ErrorAccessToken: { string msg = "access control error while " + "attempting to set up short-circuit access to " + fileName + resp.GetMessage(); if (Log.IsDebugEnabled()) { Log.Debug(this + ":" + msg); } return(new ShortCircuitReplicaInfo(new SecretManager.InvalidToken(msg))); } default: { Log.Warn(this + ": unknown response code " + resp.GetStatus() + " while attempting to set up short-circuit access. " + resp.GetMessage()); clientContext.GetDomainSocketFactory().DisableShortCircuitForPath(pathInfo.GetPath ()); return(null); } } }