private void PostFetchJob(List <string> packIndexes) { try { using (FileBasedLock postFetchFileLock = new FileBasedLock( this.context.FileSystem, this.context.Tracer, Path.Combine(this.context.Enlistment.GitObjectsRoot, PostFetchLock), this.context.Enlistment.EnlistmentRoot, overwriteExistingLock: true)) { if (!postFetchFileLock.TryAcquireLockAndDeleteOnClose()) { 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 (Exception e) { this.context.Tracer.RelatedError( metadata: null, message: PostFetchTelemetryKey + ": Exception while running post-fetch job: " + e.Message, keywords: Keywords.Telemetry); Environment.Exit((int)ReturnCode.GenericError); } }
public void CreateLockWhenDirectoryMissing() { string parentPath = Path.Combine("mock:", "path", "to"); string lockPath = Path.Combine(parentPath, "lock"); MockTracer tracer = new MockTracer(); FileBasedLockFileSystem fs = new FileBasedLockFileSystem(); FileBasedLock fileBasedLock = new FileBasedLock(fs, tracer, lockPath, "signature", overwriteExistingLock: true); fileBasedLock.TryAcquireLockAndDeleteOnClose().ShouldBeTrue(); fs.CreateDirectoryPath.ShouldNotBeNull(); fs.CreateDirectoryPath.ShouldEqual(parentPath); }
private void WaitUntilLockIsAcquired(ITracer tracer, FileBasedLock fileBasedLock) { int attempt = 0; while (!fileBasedLock.TryAcquireLockAndDeleteOnClose()) { Thread.Sleep(LockWaitTimeMs); ++attempt; if (attempt == WaitingOnLockLogThreshold) { attempt = 0; tracer.RelatedInfo("WaitUntilLockIsAcquired: Waiting to acquire prefetch lock"); } } }