Esempio n. 1
0
            public bool TryTake(out BlobDownloadRequest request)
            {
                List <string> blobsInChunk = new List <string>();

                for (int i = 0; i < this.chunkSize; ++i)
                {
                    // Only wait a short while for new work to show up, otherwise go ahead and download what we have accumulated so far
                    const int TimeoutMs = 100;

                    string blobId;
                    if (this.missingBlobs.TryTake(out blobId, TimeoutMs))
                    {
                        blobsInChunk.Add(blobId);
                    }
                    else if (blobsInChunk.Count > 0 ||
                             this.missingBlobs.IsAddingCompleted)
                    {
                        break;
                    }
                }

                if (blobsInChunk.Count > 0)
                {
                    request = new BlobDownloadRequest(blobsInChunk);
                    return(true);
                }

                request = null;
                return(false);
            }
            public bool TryTake(out BlobDownloadRequest request)
            {
                List <string> blobsInChunk = new List <string>();

                for (int i = 0; i < this.chunkSize;)
                {
                    // Only wait a short while for new work to show up, otherwise go ahead and download what we have accumulated so far
                    const int TimeoutMs = 100;

                    string blobId;
                    if (this.missingBlobs.TryTake(out blobId, TimeoutMs))
                    {
                        blobsInChunk.Add(blobId);

                        // Only increment if a blob was added. Otherwise, if no blobs are added during TimeoutMs * chunkSize,
                        // this will exit early and blobs added later will not be downloaded.
                        ++i;
                    }
                    else if (blobsInChunk.Count > 0 ||
                             this.missingBlobs.IsAddingCompleted)
                    {
                        break;
                    }
                }

                if (blobsInChunk.Count > 0)
                {
                    request = new BlobDownloadRequest(blobsInChunk);
                    return(true);
                }

                request = null;
                return(false);
            }
Esempio n. 3
0
        public void ErrorsForIndexPackFile()
        {
            using (JsonEtwTracer tracer = CreateTracer())
            {
                MockEnlistment         enlistment = new MockEnlistment();
                MockPhysicalGitObjects gitObjects = new MockPhysicalGitObjects(tracer, enlistment, null);

                BlockingCollection <IndexPackRequest> input = new BlockingCollection <IndexPackRequest>();
                BlobDownloadRequest downloadRequest         = new BlobDownloadRequest(new string[] { FakeSha });
                input.Add(new IndexPackRequest("mock:\\path\\packFileName", downloadRequest));
                input.CompleteAdding();

                IndexPackJob dut = new IndexPackJob(1, input, new BlockingCollection <string>(), tracer, gitObjects);
                dut.Start();
                dut.WaitForCompletion();
            }
        }
Esempio n. 4
0
        private RetryWrapper <GitObjectsHttpRequestor.GitObjectTaskResult> .CallbackResult WriteObjectOrPack(
            BlobDownloadRequest request,
            int tryCount,
            GitEndPointResponseData response,
            HashSet <string> successfulDownloads = null)
        {
            // To reduce allocations, reuse the same buffer when writing objects in this batch
            byte[] bufToCopyWith = new byte[StreamUtil.DefaultCopyBufferSize];

            string fileName = null;

            switch (response.ContentType)
            {
            case GitObjectContentType.LooseObject:
                string sha = request.ObjectIds.First();
                fileName = this.gitObjects.WriteLooseObject(
                    response.Stream,
                    sha,
                    bufToCopyWith);
                this.AvailableObjects.Add(sha);
                break;

            case GitObjectContentType.PackFile:
                fileName = this.gitObjects.WriteTempPackFile(response);
                this.AvailablePacks.Add(new IndexPackRequest(fileName, request));
                break;

            case GitObjectContentType.BatchedLooseObjects:
                OnLooseObject onLooseObject = (objectStream, sha1) =>
                {
                    this.gitObjects.WriteLooseObject(
                        objectStream,
                        sha1,
                        bufToCopyWith);
                    this.AvailableObjects.Add(sha1);

                    if (successfulDownloads != null)
                    {
                        successfulDownloads.Add(sha1);
                    }

                    // This isn't strictly correct because we don't add object header bytes,
                    // just the actual compressed content length, but we expect the amount of
                    // header data to be negligible compared to the objects themselves.
                    Interlocked.Add(ref this.bytesDownloaded, objectStream.Length);
                };

                new BatchedLooseObjectDeserializer(response.Stream, onLooseObject).ProcessObjects();
                break;
            }

            if (fileName != null)
            {
                // NOTE: If we are writing a file as part of this method, the only case
                // where it's not expected to exist is when running unit tests
                FileInfo info = new FileInfo(fileName);
                if (info.Exists)
                {
                    Interlocked.Add(ref this.bytesDownloaded, info.Length);
                }
                else
                {
                    return(new RetryWrapper <GitObjectsHttpRequestor.GitObjectTaskResult> .CallbackResult(
                               new GitObjectsHttpRequestor.GitObjectTaskResult(false)));
                }
            }

            return(new RetryWrapper <GitObjectsHttpRequestor.GitObjectTaskResult> .CallbackResult(
                       new GitObjectsHttpRequestor.GitObjectTaskResult(true)));
        }
 public IndexPackRequest(string tempPackFile, BlobDownloadRequest downloadRequest)
 {
     this.TempPackFile    = tempPackFile;
     this.DownloadRequest = downloadRequest;
 }