Пример #1
0
        public void Execute()
        {
            try
            {
                if (this.RequireObjectCacheLock)
                {
                    using (FileBasedLock cacheLock = GVFSPlatform.Instance.CreateFileBasedLock(
                               this.Context.FileSystem,
                               this.Context.Tracer,
                               Path.Combine(this.Context.Enlistment.GitObjectsRoot, ObjectCacheLock)))
                    {
                        if (!cacheLock.TryAcquireLock())
                        {
                            this.Context.Tracer.RelatedInfo(this.Area + ": Skipping work since another process holds the lock");
                            return;
                        }

                        this.CreateProcessAndRun();
                    }
                }
                else
                {
                    this.CreateProcessAndRun();
                }
            }
            catch (IOException e)
            {
                this.Context.Tracer.RelatedWarning(
                    metadata: this.CreateEventMetadata(e),
                    message: "IOException while running action: " + e.Message,
                    keywords: Keywords.Telemetry);
            }
            catch (Exception e)
            {
                if (this.EnlistmentRootReady())
                {
                    this.Context.Tracer.RelatedError(
                        metadata: this.CreateEventMetadata(e),
                        message: "Exception while running action: " + e.Message,
                        keywords: Keywords.Telemetry);
                }
                else
                {
                    this.Context.Tracer.RelatedWarning(
                        metadata: this.CreateEventMetadata(e),
                        message: "Exception while running action inside a repo that's not ready: " + e.Message);
                }

                Environment.Exit((int)ReturnCode.GenericError);
            }
        }
Пример #2
0
        private static void WaitUntilLockIsAcquired(ITracer tracer, FileBasedLock fileBasedLock)
        {
            int attempt = 0;

            while (!fileBasedLock.TryAcquireLock())
            {
                Thread.Sleep(LockWaitTimeMs);
                ++attempt;
                if (attempt == WaitingOnLockLogThreshold)
                {
                    attempt = 0;
                    tracer.RelatedInfo("WaitUntilLockIsAcquired: Waiting to acquire prefetch lock");
                }
            }
        }
Пример #3
0
        private void PostFetchJob(List <string> packIndexes)
        {
            try
            {
                using (FileBasedLock postFetchFileLock = GVFSPlatform.Instance.CreateFileBasedLock(
                           this.context.FileSystem,
                           this.context.Tracer,
                           Path.Combine(this.context.Enlistment.GitObjectsRoot, PostFetchLock)))
                {
                    if (!postFetchFileLock.TryAcquireLock())
                    {
                        this.context.Tracer.RelatedInfo(PostFetchTelemetryKey + ": Skipping post-fetch work since another process holds the lock");
                        return;
                    }

                    this.postFetchGitProcess = new GitProcess(this.context.Enlistment);

                    using (ITracer activity = this.context.Tracer.StartActivity("TryWriteMultiPackIndex", EventLevel.Informational, Keywords.Telemetry, metadata: null))
                    {
                        string midxLockFile = Path.Combine(this.context.Enlistment.GitPackRoot, MultiPackIndexLock);
                        this.context.FileSystem.TryDeleteFile(midxLockFile);

                        if (this.stopping)
                        {
                            this.context.Tracer.RelatedWarning(
                                metadata: null,
                                message: PostFetchTelemetryKey + ": Not launching 'git multi-pack-index' because the mount is stopping",
                                keywords: Keywords.Telemetry);
                            return;
                        }

                        GitProcess.Result result = this.postFetchGitProcess.WriteMultiPackIndex(this.context.Enlistment.GitObjectsRoot);

                        if (!this.stopping && result.ExitCodeIsFailure)
                        {
                            this.context.Tracer.RelatedWarning(
                                metadata: null,
                                message: PostFetchTelemetryKey + ": Failed to generate multi-pack-index for new packfiles:" + result.Errors,
                                keywords: Keywords.Telemetry);
                            return;
                        }
                    }

                    if (packIndexes == null || packIndexes.Count == 0)
                    {
                        this.context.Tracer.RelatedInfo(PostFetchTelemetryKey + ": Skipping commit-graph write due to no new packfiles");
                        return;
                    }

                    using (ITracer activity = this.context.Tracer.StartActivity("TryWriteGitCommitGraph", EventLevel.Informational, Keywords.Telemetry, metadata: null))
                    {
                        string graphLockFile = Path.Combine(this.context.Enlistment.GitObjectsRoot, "info", CommitGraphLock);
                        this.context.FileSystem.TryDeleteFile(graphLockFile);

                        if (this.stopping)
                        {
                            this.context.Tracer.RelatedWarning(
                                metadata: null,
                                message: PostFetchTelemetryKey + ": Not launching 'git commit-graph' because the mount is stopping",
                                keywords: Keywords.Telemetry);
                            return;
                        }

                        GitProcess.Result result = this.postFetchGitProcess.WriteCommitGraph(this.context.Enlistment.GitObjectsRoot, packIndexes);

                        if (!this.stopping && result.ExitCodeIsFailure)
                        {
                            this.context.Tracer.RelatedWarning(
                                metadata: null,
                                message: PostFetchTelemetryKey + ": Failed to generate commit-graph for new packfiles:" + result.Errors,
                                keywords: Keywords.Telemetry);
                            return;
                        }
                    }
                }
            }
            catch (IOException e)
            {
                this.context.Tracer.RelatedWarning(
                    metadata: this.CreateEventMetadata(null, e),
                    message: PostFetchTelemetryKey + ": IOException while running post-fetch job: " + e.Message,
                    keywords: Keywords.Telemetry);
            }
            catch (Exception e)
            {
                this.context.Tracer.RelatedError(
                    metadata: this.CreateEventMetadata(null, e),
                    message: PostFetchTelemetryKey + ": Exception while running post-fetch job: " + e.Message,
                    keywords: Keywords.Telemetry);
                Environment.Exit((int)ReturnCode.GenericError);
            }
        }
Пример #4
0
        private void PostFetchJob(List <string> packIndexes)
        {
            try
            {
                using (FileBasedLock postFetchFileLock = GVFSPlatform.Instance.CreateFileBasedLock(
                           this.context.FileSystem,
                           this.context.Tracer,
                           Path.Combine(this.context.Enlistment.GitObjectsRoot, PostFetchLock)))
                {
                    if (!postFetchFileLock.TryAcquireLock())
                    {
                        this.context.Tracer.RelatedInfo(PostFetchTelemetryKey + ": Skipping post-fetch work since another process holds the lock");
                        return;
                    }

                    if (!this.gitObjects.TryWriteMultiPackIndex(this.context.Tracer, this.context.Enlistment, this.context.FileSystem))
                    {
                        this.context.Tracer.RelatedWarning(
                            metadata: null,
                            message: PostFetchTelemetryKey + ": Failed to generate midx for new packfiles",
                            keywords: Keywords.Telemetry);
                    }

                    if (packIndexes == null || packIndexes.Count == 0)
                    {
                        this.context.Tracer.RelatedInfo(PostFetchTelemetryKey + ": Skipping commit-graph write due to no new packfiles");
                        return;
                    }

                    using (ITracer activity = this.context.Tracer.StartActivity("TryWriteGitCommitGraph", EventLevel.Informational, Keywords.Telemetry, metadata: null))
                    {
                        GitProcess        process = new GitProcess(this.context.Enlistment);
                        GitProcess.Result result  = process.WriteCommitGraph(this.context.Enlistment.GitObjectsRoot, packIndexes);

                        if (result.HasErrors)
                        {
                            this.context.Tracer.RelatedWarning(
                                metadata: null,
                                message: PostFetchTelemetryKey + ": Failed to generate commit-graph for new packfiles:" + result.Errors,
                                keywords: Keywords.Telemetry);
                            return;
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
                this.context.Tracer.RelatedInfo("Aborting post-fetch job due to ThreadAbortException");
            }
            catch (IOException e)
            {
                this.context.Tracer.RelatedWarning(
                    metadata: this.CreateEventMetadata(null, e),
                    message: PostFetchTelemetryKey + ": IOException while running post-fetch job: " + e.Message,
                    keywords: Keywords.Telemetry);
            }
            catch (Exception e)
            {
                this.context.Tracer.RelatedError(
                    metadata: this.CreateEventMetadata(null, e),
                    message: PostFetchTelemetryKey + ": Exception while running post-fetch job: " + e.Message,
                    keywords: Keywords.Telemetry);
                Environment.Exit((int)ReturnCode.GenericError);
            }
        }