示例#1
0
        /// <summary>
        /// Returns the next batch of events in the stream, waiting indefinitely if
        /// a new batch  is not immediately available.
        /// </summary>
        /// <exception cref="System.IO.IOException">
        /// see
        /// <see cref="Poll()"/>
        /// </exception>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Inotify.MissingEventsException">
        /// see
        /// <see cref="Poll()"/>
        /// </exception>
        /// <exception cref="System.Exception">if the calling thread is interrupted</exception>
        public virtual EventBatch Take()
        {
            TraceScope scope = Trace.StartSpan("inotifyTake", traceSampler);
            EventBatch next  = null;

            try
            {
                int nextWaitMin = InitialWaitMs;
                while ((next = Poll()) == null)
                {
                    // sleep for a random period between nextWaitMin and nextWaitMin * 2
                    // to avoid stampedes at the NN if there are multiple clients
                    int sleepTime = nextWaitMin + rng.Next(nextWaitMin);
                    Log.Debug("take(): poll() returned null, sleeping for {} ms", sleepTime);
                    Sharpen.Thread.Sleep(sleepTime);
                    // the maximum sleep is 2 minutes
                    nextWaitMin = Math.Min(60000, nextWaitMin * 2);
                }
            }
            finally
            {
                scope.Close();
            }
            return(next);
        }
示例#2
0
        /// <summary>Receive OP_WRITE_BLOCK</summary>
        /// <exception cref="System.IO.IOException"/>
        private void OpWriteBlock(DataInputStream @in)
        {
            DataTransferProtos.OpWriteBlockProto proto = DataTransferProtos.OpWriteBlockProto
                                                         .ParseFrom(PBHelper.VintPrefixed(@in));
            DatanodeInfo[] targets    = PBHelper.Convert(proto.GetTargetsList());
            TraceScope     traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetHeader()
                                                                                , proto.GetType().Name);

            try
            {
                WriteBlock(PBHelper.Convert(proto.GetHeader().GetBaseHeader().GetBlock()), PBHelper
                           .ConvertStorageType(proto.GetStorageType()), PBHelper.Convert(proto.GetHeader().
                                                                                         GetBaseHeader().GetToken()), proto.GetHeader().GetClientName(), targets, PBHelper
                           .ConvertStorageTypes(proto.GetTargetStorageTypesList(), targets.Length), PBHelper
                           .Convert(proto.GetSource()), DataTransferProtoUtil.FromProto(proto.GetStage()),
                           proto.GetPipelineSize(), proto.GetMinBytesRcvd(), proto.GetMaxBytesRcvd(), proto
                           .GetLatestGenerationStamp(), DataTransferProtoUtil.FromProto(proto.GetRequestedChecksum
                                                                                            ()), (proto.HasCachingStrategy() ? GetCachingStrategy(proto.GetCachingStrategy()
                                                                                                                                                  ) : CachingStrategy.NewDefaultStrategy()), (proto.HasAllowLazyPersist() ? proto.
                                                                                                                                                                                              GetAllowLazyPersist() : false), (proto.HasPinning() ? proto.GetPinning() : false
                                                                                                                                                                                                                               ), (PBHelper.ConvertBooleanList(proto.GetTargetPinningsList())));
            }
            finally
            {
                if (traceScope != null)
                {
                    traceScope.Close();
                }
            }
        }
示例#3
0
            /// <exception cref="System.Exception"/>
            public virtual HdfsBlocksMetadata Call()
            {
                HdfsBlocksMetadata metadata = null;
                // Create the RPC proxy and make the RPC
                ClientDatanodeProtocol cdp   = null;
                TraceScope             scope = Trace.StartSpan("getHdfsBlocksMetadata", parentSpan);

                try
                {
                    cdp = DFSUtil.CreateClientDatanodeProtocolProxy(datanode, configuration, timeout,
                                                                    connectToDnViaHostname);
                    metadata = cdp.GetHdfsBlocksMetadata(poolId, blockIds, dnTokens);
                }
                catch (IOException e)
                {
                    // Bubble this up to the caller, handle with the Future
                    throw;
                }
                finally
                {
                    scope.Close();
                    if (cdp != null)
                    {
                        RPC.StopProxy(cdp);
                    }
                }
                return(metadata);
            }
示例#4
0
            internal static TraceScope GetScope(Trace trace, bool direct, bool isReal, string type, string method, string result, params string[] items)
            {
                TraceScope scope = new TraceScope(trace, direct, isReal, type, method, result, items);

                scope._WriteBegin();
                return(scope);
            }
示例#5
0
            /// <exception cref="System.Exception"/>
            public virtual object Invoke(object proxy, MethodInfo method, object[] args)
            {
                long startTime = 0;

                if (Log.IsDebugEnabled())
                {
                    startTime = Time.Now();
                }
                TraceScope traceScope = null;

                if (Trace.IsTracing())
                {
                    traceScope = Trace.StartSpan(RpcClientUtil.MethodToTraceString(method));
                }
                ObjectWritable value;

                try
                {
                    value = (ObjectWritable)client.Call(RPC.RpcKind.RpcWritable, new WritableRpcEngine.Invocation
                                                            (method, args), remoteId, fallbackToSimpleAuth);
                }
                finally
                {
                    if (traceScope != null)
                    {
                        traceScope.Close();
                    }
                }
                if (Log.IsDebugEnabled())
                {
                    long callTime = Time.Now() - startTime;
                    Log.Debug("Call: " + method.Name + " " + callTime);
                }
                return(value.Get());
            }
示例#6
0
        /// <exception cref="System.Exception"/>
        public virtual void ReadWithTracing()
        {
            string fileName = "testReadTraceHooks.dat";

            WriteTestFile(fileName);
            long       startTime = Runtime.CurrentTimeMillis();
            TraceScope ts        = Trace.StartSpan("testReadTraceHooks", Sampler.Always);

            ReadTestFile(fileName);
            ts.Close();
            long endTime = Runtime.CurrentTimeMillis();

            string[] expectedSpanNames = new string[] { "testReadTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations"
                                                        , "ClientNamenodeProtocol#getBlockLocations", "OpReadBlockProto" };
            AssertSpanNamesFound(expectedSpanNames);
            // The trace should last about the same amount of time as the test
            IDictionary <string, IList <Span> > map = TestTracing.SetSpanReceiver.SetHolder.GetMap
                                                          ();
            Span s = map["testReadTraceHooks"][0];

            NUnit.Framework.Assert.IsNotNull(s);
            long spanStart = s.GetStartTimeMillis();
            long spanEnd   = s.GetStopTimeMillis();

            NUnit.Framework.Assert.IsTrue(spanStart - startTime < 100);
            NUnit.Framework.Assert.IsTrue(spanEnd - endTime < 100);
            // There should only be one trace id as it should all be homed in the
            // top trace.
            foreach (Span span in TestTracing.SetSpanReceiver.SetHolder.spans.Values)
            {
                NUnit.Framework.Assert.AreEqual(ts.GetSpan().GetTraceId(), span.GetTraceId());
            }
            TestTracing.SetSpanReceiver.SetHolder.spans.Clear();
        }
 public virtual void TestShortCircuitTraceHooks()
 {
     Assume.AssumeTrue(NativeCodeLoader.IsNativeCodeLoaded() && !Path.Windows);
     conf = new Configuration();
     conf.Set(DFSConfigKeys.DfsClientHtracePrefix + SpanReceiverHost.SpanReceiversConfSuffix
              , typeof(TestTracing.SetSpanReceiver).FullName);
     conf.SetLong("dfs.blocksize", 100 * 1024);
     conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitKey, true);
     conf.SetBoolean(DFSConfigKeys.DfsClientReadShortcircuitSkipChecksumKey, false);
     conf.Set(DFSConfigKeys.DfsDomainSocketPathKey, "testShortCircuitTraceHooks._PORT"
              );
     conf.Set(DFSConfigKeys.DfsChecksumTypeKey, "CRC32C");
     cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build();
     dfs     = cluster.GetFileSystem();
     try
     {
         DFSTestUtil.CreateFile(dfs, TestPath, TestLength, (short)1, 5678L);
         TraceScope        ts     = Trace.StartSpan("testShortCircuitTraceHooks", Sampler.Always);
         FSDataInputStream stream = dfs.Open(TestPath);
         byte[]            buf    = new byte[TestLength];
         IOUtils.ReadFully(stream, buf, 0, TestLength);
         stream.Close();
         ts.Close();
         string[] expectedSpanNames = new string[] { "OpRequestShortCircuitAccessProto", "ShortCircuitShmRequestProto" };
         TestTracing.AssertSpanNamesFound(expectedSpanNames);
     }
     finally
     {
         dfs.Close();
         cluster.Shutdown();
     }
 }
示例#8
0
        /// <exception cref="System.IO.IOException"/>
        public virtual int Read(ByteBuffer buf)
        {
            if (curDataSlice == null || curDataSlice.Remaining() == 0 && bytesNeededToFinish
                > 0)
            {
                TraceScope scope = Trace.StartSpan("RemoteBlockReader2#readNextPacket(" + blockId
                                                   + ")", Sampler.Never);
                try
                {
                    ReadNextPacket();
                }
                finally
                {
                    scope.Close();
                }
            }
            if (curDataSlice.Remaining() == 0)
            {
                // we're at EOF now
                return(-1);
            }
            int        nRead      = Math.Min(curDataSlice.Remaining(), buf.Remaining());
            ByteBuffer writeSlice = curDataSlice.Duplicate();

            writeSlice.Limit(writeSlice.Position() + nRead);
            buf.Put(writeSlice);
            curDataSlice.Position(writeSlice.Position());
            return(nRead);
        }
        /// <summary>Reads bytes into a buffer until EOF or the buffer's limit is reached</summary>
        /// <exception cref="System.IO.IOException"/>
        private int FillBuffer(FileInputStream stream, ByteBuffer buf)
        {
            TraceScope scope = Trace.StartSpan("BlockReaderLocalLegacy#fillBuffer(" + blockId
                                               + ")", Sampler.Never);

            try
            {
                int bytesRead = stream.GetChannel().Read(buf);
                if (bytesRead < 0)
                {
                    //EOF
                    return(bytesRead);
                }
                while (buf.Remaining() > 0)
                {
                    int n = stream.GetChannel().Read(buf);
                    if (n < 0)
                    {
                        //EOF
                        return(bytesRead);
                    }
                    bytesRead += n;
                }
                return(bytesRead);
            }
            finally
            {
                scope.Close();
            }
        }
示例#10
0
        /// <summary>
        /// Returns the next batch of events in the stream or null if no new
        /// batches are currently available.
        /// </summary>
        /// <exception cref="System.IO.IOException">
        /// because of network error or edit log
        /// corruption. Also possible if JournalNodes are unresponsive in the
        /// QJM setting (even one unresponsive JournalNode is enough in rare cases),
        /// so catching this exception and retrying at least a few times is
        /// recommended.
        /// </exception>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Inotify.MissingEventsException">
        /// if we cannot return the next batch in the
        /// stream because the data for the events (and possibly some subsequent
        /// events) has been deleted (generally because this stream is a very large
        /// number of transactions behind the current state of the NameNode). It is
        /// safe to continue reading from the stream after this exception is thrown
        /// The next available batch of events will be returned.
        /// </exception>
        public virtual EventBatch Poll()
        {
            TraceScope scope = Trace.StartSpan("inotifyPoll", traceSampler);

            try
            {
                // need to keep retrying until the NN sends us the latest committed txid
                if (lastReadTxid == -1)
                {
                    Log.Debug("poll(): lastReadTxid is -1, reading current txid from NN");
                    lastReadTxid = namenode.GetCurrentEditLogTxid();
                    return(null);
                }
                if (!it.HasNext())
                {
                    EventBatchList el = namenode.GetEditsFromTxid(lastReadTxid + 1);
                    if (el.GetLastTxid() != -1)
                    {
                        // we only want to set syncTxid when we were actually able to read some
                        // edits on the NN -- otherwise it will seem like edits are being
                        // generated faster than we can read them when the problem is really
                        // that we are temporarily unable to read edits
                        syncTxid = el.GetSyncTxid();
                        it       = el.GetBatches().GetEnumerator();
                        long formerLastReadTxid = lastReadTxid;
                        lastReadTxid = el.GetLastTxid();
                        if (el.GetFirstTxid() != formerLastReadTxid + 1)
                        {
                            throw new MissingEventsException(formerLastReadTxid + 1, el.GetFirstTxid());
                        }
                    }
                    else
                    {
                        Log.Debug("poll(): read no edits from the NN when requesting edits " + "after txid {}"
                                  , lastReadTxid);
                        return(null);
                    }
                }
                if (it.HasNext())
                {
                    // can be empty if el.getLastTxid != -1 but none of the
                    // newly seen edit log ops actually got converted to events
                    return(it.Next());
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                scope.Close();
            }
        }
        public static TraceScope ContinueTraceSpan(DataTransferProtos.DataTransferTraceInfoProto
                                                   proto, string description)
        {
            TraceScope scope = null;
            TraceInfo  info  = FromProto(proto);

            if (info != null)
            {
                scope = Trace.StartSpan(description, info);
            }
            return(scope);
        }
示例#12
0
        public async Task RootTraceSpanCreation()
        {
            //tracer faking
            Tracer tracer = A.Fake <Tracer>();

            A.CallTo(() => tracer.CreateTraceId())
            .Returns("trace_id");

            A.CallTo(() => tracer.CreateSpanId())
            .Returns("span_id");

            string   spanId       = null;
            string   parentSpanId = null;
            string   traceId      = null;
            DateTime startTime    = DateTime.MinValue;
            DateTime endTime      = DateTime.MinValue;
            string   displayName  = null;
            Dictionary <string, string> attributes = null;

            A.CallTo(() => tracer.SendAsync(A <TraceSpan> .Ignored))
            .Invokes((TraceSpan traceSpan) =>
            {
                spanId       = traceSpan.Id;
                parentSpanId = traceSpan.ParentId;
                traceId      = traceSpan.TraceId;
                startTime    = traceSpan.StartTime;
                endTime      = traceSpan.EndTime;
                displayName  = traceSpan.DisplayName;
                attributes   = traceSpan.Attributes;
            });

            //span creating
            TraceScope traceScope = new TraceScope("root", tracer);

            traceScope.Attributes.Add("key", "value");
            await Task.Delay(1);

            traceScope.Dispose();

            //checking
            await Task.Delay(100);

            Assert.Equal("span_id", spanId);
            Assert.Null(parentSpanId);
            Assert.Equal("trace_id", traceId);
            Assert.NotEqual(startTime, DateTime.MinValue);
            Assert.NotEqual(endTime, DateTime.MinValue);
            Assert.True(endTime > startTime);
            Assert.Equal("root", displayName);
            Assert.NotNull(attributes);
            Assert.Single(attributes);
        }
示例#13
0
        /// <exception cref="System.IO.IOException"/>
        public override BatchedRemoteIterator.BatchedEntries <CachePoolEntry> MakeRequest(
            string prevKey)
        {
            TraceScope scope = Trace.StartSpan("listCachePools", traceSampler);

            try
            {
                return(namenode.ListCachePools(prevKey));
            }
            finally
            {
                scope.Close();
            }
        }
示例#14
0
        /// <exception cref="System.IO.IOException"/>
        public override BatchedRemoteIterator.BatchedEntries <EncryptionZone> MakeRequest(
            long prevId)
        {
            TraceScope scope = Trace.StartSpan("listEncryptionZones", traceSampler);

            try
            {
                return(namenode.ListEncryptionZones(prevId));
            }
            finally
            {
                scope.Close();
            }
        }
示例#15
0
        /// <summary>
        /// sendBlock() is used to read block and its metadata and stream the data to
        /// either a client or to another datanode.
        /// </summary>
        /// <param name="out">stream to which the block is written to</param>
        /// <param name="baseStream">
        /// optional. if non-null, <code>out</code> is assumed to
        /// be a wrapper over this stream. This enables optimizations for
        /// sending the data, e.g.
        /// <see cref="Org.Apache.Hadoop.Net.SocketOutputStream.TransferToFully(Sharpen.FileChannel, long, int)
        ///     "/>
        /// .
        /// </param>
        /// <param name="throttler">for sending data.</param>
        /// <returns>total bytes read, including checksum data.</returns>
        /// <exception cref="System.IO.IOException"/>
        internal virtual long SendBlock(DataOutputStream @out, OutputStream baseStream, DataTransferThrottler
                                        throttler)
        {
            TraceScope scope = Trace.StartSpan("sendBlock_" + block.GetBlockId(), Sampler.Never
                                               );

            try
            {
                return(DoSendBlock(@out, baseStream, throttler));
            }
            finally
            {
                scope.Close();
            }
        }
示例#16
0
 /// <exception cref="System.IO.IOException"/>
 protected override int ReadChunk(long pos, byte[] buf, int offset, int len, byte[]
                                  checksumBuf)
 {
     lock (this)
     {
         TraceScope scope = Trace.StartSpan("RemoteBlockReader#readChunk(" + blockId + ")"
                                            , Sampler.Never);
         try
         {
             return(ReadChunkImpl(pos, buf, offset, len, checksumBuf));
         }
         finally
         {
             scope.Close();
         }
     }
 }
示例#17
0
        /// <summary>
        /// Receive
        /// <see cref="OP.ReleaseShortCircuitFds"/>
        ///
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        private void OpReleaseShortCircuitFds(DataInputStream @in)
        {
            DataTransferProtos.ReleaseShortCircuitAccessRequestProto proto = DataTransferProtos.ReleaseShortCircuitAccessRequestProto
                                                                             .ParseFrom(PBHelper.VintPrefixed(@in));
            TraceScope traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetTraceInfo
                                                                                (), proto.GetType().Name);

            try
            {
                ReleaseShortCircuitFds(PBHelper.Convert(proto.GetSlotId()));
            }
            finally
            {
                if (traceScope != null)
                {
                    traceScope.Close();
                }
            }
        }
示例#18
0
        /// <summary>
        /// Receive
        /// <see cref="OP.RequestShortCircuitShm"/>
        ///
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        private void OpRequestShortCircuitShm(DataInputStream @in)
        {
            DataTransferProtos.ShortCircuitShmRequestProto proto = DataTransferProtos.ShortCircuitShmRequestProto
                                                                   .ParseFrom(PBHelper.VintPrefixed(@in));
            TraceScope traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetTraceInfo
                                                                                (), proto.GetType().Name);

            try
            {
                RequestShortCircuitShm(proto.GetClientName());
            }
            finally
            {
                if (traceScope != null)
                {
                    traceScope.Close();
                }
            }
        }
示例#19
0
        /// <exception cref="System.Exception"/>
        public virtual void WriteWithTracing()
        {
            long       startTime = Runtime.CurrentTimeMillis();
            TraceScope ts        = Trace.StartSpan("testWriteTraceHooks", Sampler.Always);

            WriteTestFile("testWriteTraceHooks.dat");
            long endTime = Runtime.CurrentTimeMillis();

            ts.Close();
            string[] expectedSpanNames = new string[] { "testWriteTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.create"
                                                        , "ClientNamenodeProtocol#create", "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync"
                                                        , "ClientNamenodeProtocol#fsync", "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete"
                                                        , "ClientNamenodeProtocol#complete", "newStreamForCreate", "DFSOutputStream#writeChunk"
                                                        , "DFSOutputStream#close", "dataStreamer", "OpWriteBlockProto", "org.apache.hadoop.hdfs.protocol.ClientProtocol.addBlock"
                                                        , "ClientNamenodeProtocol#addBlock" };
            AssertSpanNamesFound(expectedSpanNames);
            // The trace should last about the same amount of time as the test
            IDictionary <string, IList <Span> > map = TestTracing.SetSpanReceiver.SetHolder.GetMap
                                                          ();
            Span s = map["testWriteTraceHooks"][0];

            NUnit.Framework.Assert.IsNotNull(s);
            long spanStart = s.GetStartTimeMillis();
            long spanEnd   = s.GetStopTimeMillis();

            // Spans homed in the top trace shoud have same trace id.
            // Spans having multiple parents (e.g. "dataStreamer" added by HDFS-7054)
            // and children of them are exception.
            string[] spansInTopTrace = new string[] { "testWriteTraceHooks", "org.apache.hadoop.hdfs.protocol.ClientProtocol.create"
                                                      , "ClientNamenodeProtocol#create", "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync"
                                                      , "ClientNamenodeProtocol#fsync", "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete"
                                                      , "ClientNamenodeProtocol#complete", "newStreamForCreate", "DFSOutputStream#writeChunk"
                                                      , "DFSOutputStream#close" };
            foreach (string desc in spansInTopTrace)
            {
                foreach (Span span in map[desc])
                {
                    NUnit.Framework.Assert.AreEqual(ts.GetSpan().GetTraceId(), span.GetTraceId());
                }
            }
            TestTracing.SetSpanReceiver.SetHolder.spans.Clear();
        }
示例#20
0
        /// <summary>Receive OP_BLOCK_CHECKSUM</summary>
        /// <exception cref="System.IO.IOException"/>
        private void OpBlockChecksum(DataInputStream @in)
        {
            DataTransferProtos.OpBlockChecksumProto proto = DataTransferProtos.OpBlockChecksumProto
                                                            .ParseFrom(PBHelper.VintPrefixed(@in));
            TraceScope traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetHeader()
                                                                            , proto.GetType().Name);

            try
            {
                BlockChecksum(PBHelper.Convert(proto.GetHeader().GetBlock()), PBHelper.Convert(proto
                                                                                               .GetHeader().GetToken()));
            }
            finally
            {
                if (traceScope != null)
                {
                    traceScope.Close();
                }
            }
        }
        /// <exception cref="System.IO.IOException"/>
        public override BatchedRemoteIterator.BatchedEntries <CacheDirectiveEntry> MakeRequest
            (long prevKey)
        {
            BatchedRemoteIterator.BatchedEntries <CacheDirectiveEntry> entries = null;
            TraceScope scope = Trace.StartSpan("listCacheDirectives", traceSampler);

            try
            {
                entries = namenode.ListCacheDirectives(prevKey, filter);
            }
            catch (IOException e)
            {
                if (e.Message.Contains("Filtering by ID is unsupported"))
                {
                    // Retry case for old servers, do the filtering client-side
                    long id = filter.GetId();
                    filter = RemoveIdFromFilter(filter);
                    // Using id - 1 as prevId should get us a window containing the id
                    // This is somewhat brittle, since it depends on directives being
                    // returned in order of ascending ID.
                    entries = namenode.ListCacheDirectives(id - 1, filter);
                    for (int i = 0; i < entries.Size(); i++)
                    {
                        CacheDirectiveEntry entry = entries.Get(i);
                        if (entry.GetInfo().GetId().Equals((long)id))
                        {
                            return(new CacheDirectiveIterator.SingleEntry(entry));
                        }
                    }
                    throw new RemoteException(typeof(InvalidRequestException).FullName, "Did not find requested id "
                                              + id);
                }
                throw;
            }
            finally
            {
                scope.Close();
            }
            Preconditions.CheckNotNull(entries);
            return(entries);
        }
        protected override void OnProcessOutputSchema(MutableObject newSchema)
        {
            foreach (var entry in TraceScope.GetEntries(newSchema))
            {
                foreach (var subentry in AllocateScope.GetEntries(entry))
                {
                    AllocatePositionTarget.SetValue(4f, subentry);
                    AllocateSizeTarget.SetValue(.4f, subentry);
                    AllocateColorTarget.SetValue(Color.magenta, subentry);
                    AllocateEndIndexTarget.SetValue((int)12, subentry);
                }

                foreach (var subentry in ReadScope.GetEntries(entry))
                {
                    ReadPositionTarget.SetValue(4f, subentry);
                    ReadSizeTarget.SetValue(.4f, subentry);
                    ReadColorTarget.SetValue(Color.magenta, subentry);
                }

                foreach (var subentry in WriteScope.GetEntries(entry))
                {
                    WritePositionTarget.SetValue(4f, subentry);
                    WriteSizeTarget.SetValue(.4f, subentry);
                    WriteColorTarget.SetValue(Color.magenta, subentry);
                }
            }

            GridLinesTarget.SetValue(new List <MutableObject>
            {
                new MutableObject {
                    { "Visual Position", .5f }, { "Visual Weight", .2f }
                },
                new MutableObject {
                    { "Visual Position", 1f }, { "Visual Weight", .1f }
                }
            }, newSchema);

            Router.TransmitAllSchema(newSchema);
        }
示例#23
0
        /// <summary>
        /// Returns the next event batch in the stream, waiting up to the specified
        /// amount of time for a new batch.
        /// </summary>
        /// <remarks>
        /// Returns the next event batch in the stream, waiting up to the specified
        /// amount of time for a new batch. Returns null if one is not available at the
        /// end of the specified amount of time. The time before the method returns may
        /// exceed the specified amount of time by up to the time required for an RPC
        /// to the NameNode.
        /// </remarks>
        /// <param name="time">number of units of the given TimeUnit to wait</param>
        /// <param name="tu">the desired TimeUnit</param>
        /// <exception cref="System.IO.IOException">
        /// see
        /// <see cref="Poll()"/>
        /// </exception>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Inotify.MissingEventsException">
        /// see
        /// <see cref="Poll()"/>
        /// </exception>
        /// <exception cref="System.Exception">if the calling thread is interrupted</exception>
        public virtual EventBatch Poll(long time, TimeUnit tu)
        {
            TraceScope scope = Trace.StartSpan("inotifyPollWithTimeout", traceSampler);
            EventBatch next  = null;

            try
            {
                long initialTime = Time.MonotonicNow();
                long totalWait   = TimeUnit.Milliseconds.Convert(time, tu);
                long nextWait    = InitialWaitMs;
                while ((next = Poll()) == null)
                {
                    long timeLeft = totalWait - (Time.MonotonicNow() - initialTime);
                    if (timeLeft <= 0)
                    {
                        Log.Debug("timed poll(): timed out");
                        break;
                    }
                    else
                    {
                        if (timeLeft < nextWait * 2)
                        {
                            nextWait = timeLeft;
                        }
                        else
                        {
                            nextWait *= 2;
                        }
                    }
                    Log.Debug("timed poll(): poll() returned null, sleeping for {} ms", nextWait);
                    Sharpen.Thread.Sleep(nextWait);
                }
            }
            finally
            {
                scope.Close();
            }
            return(next);
        }
示例#24
0
 /// <exception cref="System.IO.IOException"/>
 public virtual int Read(byte[] buf, int off, int len)
 {
     lock (this)
     {
         UUID randomId = null;
         if (Log.IsTraceEnabled())
         {
             randomId = UUID.RandomUUID();
             Log.Trace(string.Format("Starting read #%s file %s from datanode %s", randomId.ToString
                                         (), this.filename, this.datanodeID.GetHostName()));
         }
         if (curDataSlice == null || curDataSlice.Remaining() == 0 && bytesNeededToFinish
             > 0)
         {
             TraceScope scope = Trace.StartSpan("RemoteBlockReader2#readNextPacket(" + blockId
                                                + ")", Sampler.Never);
             try
             {
                 ReadNextPacket();
             }
             finally
             {
                 scope.Close();
             }
         }
         if (Log.IsTraceEnabled())
         {
             Log.Trace(string.Format("Finishing read #" + randomId));
         }
         if (curDataSlice.Remaining() == 0)
         {
             // we're at EOF now
             return(-1);
         }
         int nRead = Math.Min(curDataSlice.Remaining(), len);
         curDataSlice.Get(buf, off, nRead);
         return(nRead);
     }
 }
示例#25
0
        /// <summary>
        /// Receive
        /// <see cref="OP.TransferBlock"/>
        ///
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        private void OpTransferBlock(DataInputStream @in)
        {
            DataTransferProtos.OpTransferBlockProto proto = DataTransferProtos.OpTransferBlockProto
                                                            .ParseFrom(PBHelper.VintPrefixed(@in));
            DatanodeInfo[] targets    = PBHelper.Convert(proto.GetTargetsList());
            TraceScope     traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetHeader()
                                                                                , proto.GetType().Name);

            try
            {
                TransferBlock(PBHelper.Convert(proto.GetHeader().GetBaseHeader().GetBlock()), PBHelper
                              .Convert(proto.GetHeader().GetBaseHeader().GetToken()), proto.GetHeader().GetClientName
                                  (), targets, PBHelper.ConvertStorageTypes(proto.GetTargetStorageTypesList(), targets
                                                                            .Length));
            }
            finally
            {
                if (traceScope != null)
                {
                    traceScope.Close();
                }
            }
        }
示例#26
0
        /// <summary>Receive OP_READ_BLOCK</summary>
        /// <exception cref="System.IO.IOException"/>
        private void OpReadBlock()
        {
            DataTransferProtos.OpReadBlockProto proto = DataTransferProtos.OpReadBlockProto.ParseFrom
                                                            (PBHelper.VintPrefixed(@in));
            TraceScope traceScope = DataTransferProtoUtil.ContinueTraceSpan(proto.GetHeader()
                                                                            , proto.GetType().Name);

            try
            {
                ReadBlock(PBHelper.Convert(proto.GetHeader().GetBaseHeader().GetBlock()), PBHelper
                          .Convert(proto.GetHeader().GetBaseHeader().GetToken()), proto.GetHeader().GetClientName
                              (), proto.GetOffset(), proto.GetLen(), proto.GetSendChecksums(), (proto.HasCachingStrategy
                                                                                                    () ? GetCachingStrategy(proto.GetCachingStrategy()) : CachingStrategy.NewDefaultStrategy
                                                                                                    ()));
            }
            finally
            {
                if (traceScope != null)
                {
                    traceScope.Close();
                }
            }
        }
示例#27
0
        /// <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();
                }
            }
        }
示例#28
0
 /// <summary>Read from the block file into a buffer.</summary>
 /// <remarks>
 /// Read from the block file into a buffer.
 /// This function overwrites checksumBuf.  It will increment dataPos.
 /// </remarks>
 /// <param name="buf">
 /// The buffer to read into.  May be dataBuf.
 /// The position and limit of this buffer should be set to
 /// multiples of the checksum size.
 /// </param>
 /// <param name="canSkipChecksum">True if we can skip checksumming.</param>
 /// <returns>Total bytes read.  0 on EOF.</returns>
 /// <exception cref="System.IO.IOException"/>
 private int FillBuffer(ByteBuffer buf, bool canSkipChecksum)
 {
     lock (this)
     {
         TraceScope scope = Trace.StartSpan("BlockReaderLocal#fillBuffer(" + block.GetBlockId
                                                () + ")", Sampler.Never);
         try
         {
             int  total        = 0;
             long startDataPos = dataPos;
             int  startBufPos  = buf.Position();
             while (buf.HasRemaining())
             {
                 int nRead = dataIn.Read(buf, dataPos);
                 if (nRead < 0)
                 {
                     break;
                 }
                 dataPos += nRead;
                 total   += nRead;
             }
             if (canSkipChecksum)
             {
                 FreeChecksumBufIfExists();
                 return(total);
             }
             if (total > 0)
             {
                 try
                 {
                     buf.Limit(buf.Position());
                     buf.Position(startBufPos);
                     CreateChecksumBufIfNeeded();
                     int checksumsNeeded = (total + bytesPerChecksum - 1) / bytesPerChecksum;
                     checksumBuf.Clear();
                     checksumBuf.Limit(checksumsNeeded * checksumSize);
                     long checksumPos = BlockMetadataHeader.GetHeaderSize() + ((startDataPos / bytesPerChecksum
                                                                                ) * checksumSize);
                     while (checksumBuf.HasRemaining())
                     {
                         int nRead = checksumIn.Read(checksumBuf, checksumPos);
                         if (nRead < 0)
                         {
                             throw new IOException("Got unexpected checksum file EOF at " + checksumPos + ", block file position "
                                                   + startDataPos + " for " + "block " + block + " of file " + filename);
                         }
                         checksumPos += nRead;
                     }
                     checksumBuf.Flip();
                     checksum.VerifyChunkedSums(buf, checksumBuf, filename, startDataPos);
                 }
                 finally
                 {
                     buf.Position(buf.Limit());
                 }
             }
             return(total);
         }
         finally
         {
             scope.Close();
         }
     }
 }
示例#29
0
            /// <summary>This is the client side invoker of RPC method.</summary>
            /// <remarks>
            /// This is the client side invoker of RPC method. It only throws
            /// ServiceException, since the invocation proxy expects only
            /// ServiceException to be thrown by the method in case protobuf service.
            /// ServiceException has the following causes:
            /// <ol>
            /// <li>Exceptions encountered on the client side in this method are
            /// set as cause in ServiceException as is.</li>
            /// <li>Exceptions from the server are wrapped in RemoteException and are
            /// set as cause in ServiceException</li>
            /// </ol>
            /// Note that the client calling protobuf RPC methods, must handle
            /// ServiceException by getting the cause from the ServiceException. If the
            /// cause is RemoteException, then unwrap it to get the exception thrown by
            /// the server.
            /// </remarks>
            /// <exception cref="Com.Google.Protobuf.ServiceException"/>
            public virtual object Invoke(object proxy, MethodInfo method, object[] args)
            {
                long startTime = 0;

                if (Log.IsDebugEnabled())
                {
                    startTime = Time.Now();
                }
                if (args.Length != 2)
                {
                    // RpcController + Message
                    throw new ServiceException("Too many parameters for request. Method: [" + method.
                                               Name + "]" + ", Expected: 2, Actual: " + args.Length);
                }
                if (args[1] == null)
                {
                    throw new ServiceException("null param while calling Method: [" + method.Name + "]"
                                               );
                }
                TraceScope traceScope = null;

                // if Tracing is on then start a new span for this rpc.
                // guard it in the if statement to make sure there isn't
                // any extra string manipulation.
                if (Trace.IsTracing())
                {
                    traceScope = Trace.StartSpan(RpcClientUtil.MethodToTraceString(method));
                }
                ProtobufRpcEngineProtos.RequestHeaderProto rpcRequestHeader = ConstructRpcRequestHeader
                                                                                  (method);
                if (Log.IsTraceEnabled())
                {
                    Log.Trace(Thread.CurrentThread().GetId() + ": Call -> " + remoteId + ": "
                              + method.Name + " {" + TextFormat.ShortDebugString((Message)args[1]) + "}");
                }
                Message theRequest = (Message)args[1];

                ProtobufRpcEngine.RpcResponseWrapper val;
                try
                {
                    val = (ProtobufRpcEngine.RpcResponseWrapper)client.Call(RPC.RpcKind.RpcProtocolBuffer
                                                                            , new ProtobufRpcEngine.RpcRequestWrapper(rpcRequestHeader, theRequest), remoteId
                                                                            , fallbackToSimpleAuth);
                }
                catch (Exception e)
                {
                    if (Log.IsTraceEnabled())
                    {
                        Log.Trace(Thread.CurrentThread().GetId() + ": Exception <- " + remoteId +
                                  ": " + method.Name + " {" + e + "}");
                    }
                    if (Trace.IsTracing())
                    {
                        traceScope.GetSpan().AddTimelineAnnotation("Call got exception: " + e.Message);
                    }
                    throw new ServiceException(e);
                }
                finally
                {
                    if (traceScope != null)
                    {
                        traceScope.Close();
                    }
                }
                if (Log.IsDebugEnabled())
                {
                    long callTime = Time.Now() - startTime;
                    Log.Debug("Call: " + method.Name + " took " + callTime + "ms");
                }
                Message prototype = null;

                try
                {
                    prototype = GetReturnProtoType(method);
                }
                catch (Exception e)
                {
                    throw new ServiceException(e);
                }
                Message returnMessage;

                try
                {
                    returnMessage = prototype.NewBuilderForType().MergeFrom(val.theResponseRead).Build
                                        ();
                    if (Log.IsTraceEnabled())
                    {
                        Log.Trace(Thread.CurrentThread().GetId() + ": Response <- " + remoteId +
                                  ": " + method.Name + " {" + TextFormat.ShortDebugString(returnMessage) + "}");
                    }
                }
                catch (Exception e)
                {
                    throw new ServiceException(e);
                }
                return(returnMessage);
            }
示例#30
0
        public IExcludeForRetry Subscribe <TSubscriber, TEvent>(string tag, AbstractValidator <TEvent> validator, string retryCron, ushort?retryLimit) where TSubscriber : IEventHandler <TEvent> where TEvent : class
        {
            //naming validation
            if (tag != null)
            {
                tag.CheckNaming();
            }

            //subscriber registration in a container
            Injection.AddTransient(typeof(TSubscriber));

            //retry handler
            IRetry retryHandler = new RetryHandler(0, 0, 0, false);

            //creates queue and exchanges
            string directory         = typeof(TEvent).GetTypeInfo().GetCustomAttribute <BusNamespace>().Directory;
            string subdirectory      = typeof(TEvent).GetTypeInfo().GetCustomAttribute <BusNamespace>().Subdirectory;
            string exchange          = "event_" + directory.ToLower() + "_" + subdirectory.ToLower();
            string routingKey        = typeof(TEvent).Name.ToLower() + "." + (tag != null ? tag.ToLower() : "*");
            string restoreRoutingKey = _appId.ToLower() + "." + directory.ToLower() + "." + subdirectory.ToLower() + "." + typeof(TEvent).Name.ToLower() + (tag != null ? ("." + tag.ToLower()) : "");
            string queue             = _appId.ToLower() + "-event-" + directory.ToLower() + "-" + subdirectory.ToLower() + "-" + typeof(TEvent).Name.ToLower() + (tag != null ? ("-" + tag.ToLower()) : "");

            _eventHandlerChannel.ExchangeDeclare(exchange, ExchangeType.Topic, true, false);
            _eventHandlerChannel.ExchangeDeclare(DEAD_LETTER_QUEUE_EXCHANGE, ExchangeType.Direct, true, false);
            _eventHandlerChannel.QueueDeclare(queue, true, false, false, new Dictionary <string, object> {
                { "x-queue-mode", "lazy" }
            });
            _eventHandlerChannel.QueueBind(queue, exchange, routingKey);
            _eventHandlerChannel.QueueBind(queue, DEAD_LETTER_QUEUE_EXCHANGE, restoreRoutingKey);

            //creates dead letter queue
            string deadLetterQueue = queue + "-dlq";
            string dlqRoutingKey   = _appId.ToLower() + "." + directory.ToLower() + "." + subdirectory.ToLower() + "." + typeof(TEvent).Name.ToLower() + (tag != null ? ("." + tag.ToLower()) : "") + ".dlq";

            _deadLetterQueueChannel.QueueDeclare(deadLetterQueue, true, false, false, new Dictionary <string, object> {
                { "x-queue-mode", "lazy" }
            });
            _deadLetterQueueChannel.QueueBind(deadLetterQueue, DEAD_LETTER_QUEUE_EXCHANGE, dlqRoutingKey);

            //message listener
            EventingBasicConsumer consumer = new EventingBasicConsumer(_eventHandlerChannel);

            consumer.Received += (obj, args) =>
            {
                Task.Factory.StartNew(async() =>
                {
                    string messageBody = Encoding.UTF8.GetString(args.Body.ToArray());

                    try
                    {
                        TEvent messageEvent = _jsonConverter.Deserialize <TEvent>(messageBody);
                        if (validator != null)
                        {
                            await validator.ValidateAndThrowAsync(messageEvent, (directory + "." + subdirectory + "." + typeof(TEvent).Name + " is not valid"));
                        }

                        using (IServiceScope serviceScope = _serviceProvider.CreateScope())
                            using (ITraceScope traceScope = new TraceScope("Handle-" + directory + "." + subdirectory + "." + typeof(TEvent).Name, _tracer))
                            {
                                TSubscriber subscriber = serviceScope.ServiceProvider.GetService <TSubscriber>();
                                subscriber.Bus         = this;
                                subscriber.TraceScope  = traceScope;
                                traceScope.Attributes.Add("AppId", _appId);
                                traceScope.Attributes.Add("MessageId", args.BasicProperties.MessageId);
                                await subscriber.HandleAsync(messageEvent);
                            }

                        _logger.Send(new MessageDetail
                        {
                            Id            = args.BasicProperties.MessageId,
                            CorrelationId = null,
                            Type          = MessageType.Event,
                            Directory     = directory,
                            Subdirectory  = subdirectory,
                            Name          = typeof(TEvent).Name,
                            Body          = messageBody,
                            AppId         = args.BasicProperties.AppId,
                            Exception     = null,
                            ToRetry       = false
                        });
                    }
                    catch (Exception exception)
                    {
                        bool toRetry      = false;
                        ushort retryIndex = ushort.Parse(Encoding.UTF8.GetString((byte[])args.BasicProperties.Headers["RetryIndex"]));
                        if (retryHandler.IsForRetry(exception) && !string.IsNullOrEmpty(retryCron) && retryLimit != null && retryIndex < retryLimit)
                        {
                            IBasicProperties properties = _deadLetterQueueChannel.CreateBasicProperties();
                            properties.MessageId        = args.BasicProperties.MessageId;
                            properties.AppId            = args.BasicProperties.AppId;
                            properties.Headers          = new Dictionary <string, object>();
                            properties.Headers.Add("RetryIndex", (++retryIndex).ToString());
                            properties.Persistent = true;
                            _deadLetterQueueChannel.BasicPublish(DEAD_LETTER_QUEUE_EXCHANGE, dlqRoutingKey, properties, args.Body);

                            toRetry = true;
                        }

                        _logger.Send(new MessageDetail
                        {
                            Id            = args.BasicProperties.MessageId,
                            CorrelationId = null,
                            Type          = MessageType.Event,
                            Directory     = directory,
                            Subdirectory  = subdirectory,
                            Name          = typeof(TEvent).Name,
                            Body          = messageBody,
                            AppId         = args.BasicProperties.AppId,
                            Exception     = exception,
                            ToRetry       = toRetry
                        });
                    }

                    //acknowledgment
                    _eventHandlerChannel.BasicAck(args.DeliveryTag, false);
                },
                                      _cancellationTokenSource.Token,
                                      TaskCreationOptions.DenyChildAttach,
                                      TaskScheduler.Default);
            };

            _toActivateConsumers.Add(new Tuple <IModel, string, EventingBasicConsumer>(_eventHandlerChannel, queue, consumer));

            //message restore
            Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    await retryCron.CronDelay();

                    List <BasicGetResult> bgrs = new List <BasicGetResult>();
                    for (int i = 0; i < DEAD_LETTER_QUEUE_RECOVERY_LIMIT; i++)
                    {
                        BasicGetResult bgr = _deadLetterQueueChannel.BasicGet(deadLetterQueue, false);
                        if (bgr == null)
                        {
                            break;
                        }

                        bgrs.Add(bgr);
                    }

                    foreach (BasicGetResult bgr in bgrs)
                    {
                        _deadLetterQueueChannel.BasicPublish(DEAD_LETTER_QUEUE_EXCHANGE, restoreRoutingKey, bgr.BasicProperties, bgr.Body);
                        _deadLetterQueueChannel.BasicAck(bgr.DeliveryTag, false);
                    }
                }
            },
                                  _cancellationTokenSource.Token,
                                  TaskCreationOptions.DenyChildAttach,
                                  _deadLetterQueueTaskScheduler);

            return(retryHandler);
        }