Ejemplo n.º 1
0
        private void HandleAllFileAddOperations()
        {
            using (PrefetchLibGit2Repo repo = new PrefetchLibGit2Repo(this.tracer, this.enlistment.WorkingDirectoryRoot))
            {
                string availableBlob;
                while (this.AvailableBlobShas.TryTake(out availableBlob, Timeout.Infinite))
                {
                    if (this.HasFailures)
                    {
                        return;
                    }

                    Interlocked.Increment(ref this.shasReceived);

                    HashSet <string> paths;
                    if (this.diff.FileAddOperations.TryRemove(availableBlob, out paths))
                    {
                        try
                        {
                            long written;
                            if (!repo.TryCopyBlobToFile(availableBlob, paths, out written))
                            {
                                // TryCopyBlobTo emits an error event.
                                this.HasFailures = true;
                            }

                            Interlocked.Add(ref this.bytesWritten, written);

                            foreach (string path in paths)
                            {
                                this.AddedOrEditedLocalFiles.Add(path);

                                if (Interlocked.Increment(ref this.fileWriteCount) % NumOperationsPerStatus == 0)
                                {
                                    EventMetadata metadata = new EventMetadata();
                                    metadata.Add("AvailableBlobsQueued", this.AvailableBlobShas.Count);
                                    metadata.Add("NumberBlobsNeeded", this.diff.FileAddOperations.Count);
                                    this.tracer.RelatedEvent(EventLevel.Informational, "CheckoutStatus", metadata);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            EventMetadata errorData = new EventMetadata();
                            errorData.Add("Operation", "WriteFile");
                            this.tracer.RelatedError(errorData, ex.ToString());
                            this.HasFailures = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void DownloadMissingCommit(string commitSha, GitObjects gitObjects)
        {
            EventMetadata startMetadata = new EventMetadata();

            startMetadata.Add("CommitSha", commitSha);

            using (ITracer activity = this.Tracer.StartActivity("DownloadTrees", EventLevel.Informational, Keywords.Telemetry, startMetadata))
            {
                using (PrefetchLibGit2Repo repo = new PrefetchLibGit2Repo(this.Tracer, this.Enlistment.WorkingDirectoryRoot))
                {
                    if (!repo.ObjectExists(commitSha))
                    {
                        if (!gitObjects.TryDownloadCommit(commitSha))
                        {
                            EventMetadata metadata = new EventMetadata();
                            metadata.Add("ObjectsEndpointUrl", this.ObjectRequestor.CacheServer.ObjectsEndpointUrl);
                            activity.RelatedError(metadata, "Could not download commits");
                            throw new FetchException("Could not download commits from {0}", this.ObjectRequestor.CacheServer.ObjectsEndpointUrl);
                        }
                    }
                }
            }
        }
        protected override void DoWork()
        {
            string blobId;

            using (PrefetchLibGit2Repo repo = new PrefetchLibGit2Repo(this.tracer, this.enlistment.WorkingDirectoryRoot))
            {
                while (this.requiredBlobs.TryTake(out blobId, Timeout.Infinite))
                {
                    if (this.alreadyFoundBlobIds.Add(blobId))
                    {
                        if (!repo.ObjectExists(blobId))
                        {
                            Interlocked.Increment(ref this.missingBlobCount);
                            this.MissingBlobs.Add(blobId);
                        }
                        else
                        {
                            Interlocked.Increment(ref this.availableBlobCount);
                            this.AvailableBlobs.Add(blobId);
                        }
                    }
                }
            }
        }