diff --git a/src/Grace.Actors/Branch.Actor.fs b/src/Grace.Actors/Branch.Actor.fs index 7a76c0a..9e50632 100644 --- a/src/Grace.Actors/Branch.Actor.fs +++ b/src/Grace.Actors/Branch.Actor.fs @@ -23,6 +23,7 @@ open Microsoft.Extensions.Logging open System open System.Collections.Generic open System.Diagnostics +open System.Linq open System.Runtime.Serialization open System.Text open System.Threading.Tasks @@ -299,7 +300,7 @@ module Branch = member private this.ApplyEvent branchEvent = task { try - if branchEvents.Count = 0 then do! this.OnFirstWrite() + if branchEvents |> Seq.isEmpty then do! this.OnFirstWrite() // Update the branchDto with the event. let! updatedBranchDto = branchDto |> updateDto branchEvent this.correlationId @@ -505,7 +506,7 @@ module Branch = logToConsole $"In BranchActor.Handle.processCommand: Error rebasing on referenceId: {basedOn}. promotionDto: {serialize promotionDto}" - memoryCache.CreateBranchNameEntry branchName branchId + memoryCache.CreateBranchNameEntry $"{repositoryId}" branchName branchId return Ok(Created(branchId, branchName, parentBranchId, basedOn, repositoryId, branchPermissions)) | BranchCommand.Rebase referenceId -> diff --git a/src/Grace.Actors/DirectoryAppearance.Actor.fs b/src/Grace.Actors/DirectoryAppearance.Actor.fs index c162229..004992d 100644 --- a/src/Grace.Actors/DirectoryAppearance.Actor.fs +++ b/src/Grace.Actors/DirectoryAppearance.Actor.fs @@ -92,7 +92,7 @@ module DirectoryAppearance = let wasRemoved = dto.Appearances.Remove(appearance) if wasRemoved then - if dto.Appearances.Count = 0 then + if dto.Appearances |> Seq.isEmpty then let! deleteSucceeded = Storage.DeleteState stateManager dtoStateName if deleteSucceeded then diff --git a/src/Grace.Actors/Extensions/MemoryCache.Extensions.Actor.fs b/src/Grace.Actors/Extensions/MemoryCache.Extensions.Actor.fs index 33b16ec..453d8bf 100644 --- a/src/Grace.Actors/Extensions/MemoryCache.Extensions.Actor.fs +++ b/src/Grace.Actors/Extensions/MemoryCache.Extensions.Actor.fs @@ -177,14 +177,14 @@ module MemoryCache = /// Create a new entry in MemoryCache to link a BranchName with a BranchId. - member this.CreateBranchNameEntry (branchName: string) (branchId: BranchId) = - this.CreateWithDefaultExpirationTime $"{branchNamePrefix}:{branchName}" branchId + member this.CreateBranchNameEntry (repositoryId: string) (branchName: string) (branchId: BranchId) = + this.CreateWithDefaultExpirationTime $"{branchNamePrefix}:{repositoryId}-{branchName}" branchId /// Check if we have an entry in MemoryCache for a BranchName, and return the BranchId if we have it. - member this.GetBranchNameEntry(branchName: string) = this.GetFromCache $"{branchNamePrefix}:{branchName}" + member this.GetBranchNameEntry (repositoryId: string) (branchName: string) = this.GetFromCache $"{branchNamePrefix}:{repositoryId}-{branchName}" /// Remove an entry in MemoryCache for a BranchName. - member this.RemoveBranchNameEntry(branchName: string) = this.Remove($"{branchNamePrefix}:{branchName}") + member this.RemoveBranchNameEntry (repositoryId: string) (branchName: string) = this.Remove($"{branchNamePrefix}:{repositoryId}-{branchName}") /// Create a new entry in MemoryCache to store the current thread count information. diff --git a/src/Grace.Actors/FileAppearance.Actor.fs b/src/Grace.Actors/FileAppearance.Actor.fs index 2e5d6ac..9d26121 100644 --- a/src/Grace.Actors/FileAppearance.Actor.fs +++ b/src/Grace.Actors/FileAppearance.Actor.fs @@ -91,7 +91,7 @@ module FileAppearance = let wasRemoved = dto.Appearances.Remove(appearance) if wasRemoved then - if dto.Appearances.Count = 0 then + if dto.Appearances |> Seq.isEmpty then // TODO: Delete the file from storage do! stateManager.RemoveStateAsync(dtoStateName) else diff --git a/src/Grace.Actors/Organization.Actor.fs b/src/Grace.Actors/Organization.Actor.fs index fd40146..016dc14 100644 --- a/src/Grace.Actors/Organization.Actor.fs +++ b/src/Grace.Actors/Organization.Actor.fs @@ -183,7 +183,7 @@ module Organization = try let! organizationEvents = this.OrganizationEvents() - if organizationEvents.Count = 0 then do! this.OnFirstWrite() + if organizationEvents |> Seq.isEmpty then do! this.OnFirstWrite() organizationEvents.Add(organizationEvent) diff --git a/src/Grace.Actors/Owner.Actor.fs b/src/Grace.Actors/Owner.Actor.fs index 62ff60d..e662af8 100644 --- a/src/Grace.Actors/Owner.Actor.fs +++ b/src/Grace.Actors/Owner.Actor.fs @@ -188,7 +188,7 @@ module Owner = try let! ownerEvents = this.OwnerEvents() - if ownerEvents.Count = 0 then this.OnFirstWrite() + if ownerEvents |> Seq.isEmpty then this.OnFirstWrite() ownerEvents.Add(ownerEvent) diff --git a/src/Grace.Actors/Services.Actor.fs b/src/Grace.Actors/Services.Actor.fs index b8d25f6..04a73b0 100644 --- a/src/Grace.Actors/Services.Actor.fs +++ b/src/Grace.Actors/Services.Actor.fs @@ -645,7 +645,7 @@ module Services = return None else // Check if we have an active BranchName actor with a cached result. - match memoryCache.GetBranchNameEntry branchName with + match (memoryCache.GetBranchNameEntry repositoryId branchName) with | Some branchGuid -> if branchGuid.Equals(Constants.MemoryCache.EntityDoesNotExist) then // We have already checked and the branch does not exist. @@ -661,7 +661,7 @@ module Services = match! branchNameActorProxy.GetBranchId correlationId with | Some branchId -> // Add this BranchName and BranchId to the MemoryCache. - memoryCache.CreateBranchNameEntry branchName branchId + memoryCache.CreateBranchNameEntry repositoryId branchName branchId memoryCache.CreateBranchIdEntry branchId MemoryCache.ExistsValue return Some $"{branchId}" | None -> @@ -698,7 +698,7 @@ module Services = branchGuid <- Guid.Parse(branchId) // Add this BranchName and BranchId to the MemoryCache. - memoryCache.CreateBranchNameEntry branchName branchGuid + memoryCache.CreateBranchNameEntry repositoryId branchName branchGuid memoryCache.CreateBranchIdEntry branchGuid MemoryCache.ExistsValue // Set the BranchId in the BranchName actor. @@ -1092,10 +1092,11 @@ module Services = | Reference.ReferenceEventType.Created refDto -> references.Add(refDto) | _ -> ()) - Activity.Current - .SetTag("indexMetrics", $"{indexMetrics.Remove(indexMetrics.Length - 2, 2)}") - .SetTag("requestCharge", $"{requestCharge.Remove(requestCharge.Length - 2, 2)}") - |> ignore + if indexMetrics.Length >= 2 then + Activity.Current + .SetTag("indexMetrics", $"{indexMetrics.Remove(indexMetrics.Length - 2, 2)}") + .SetTag("requestCharge", $"{requestCharge.Remove(requestCharge.Length - 2, 2)}") + |> ignore finally stringBuilderPool.Return(indexMetrics) stringBuilderPool.Return(requestCharge) diff --git a/src/Grace.CLI/Command/Branch.CLI.fs b/src/Grace.CLI/Command/Branch.CLI.fs index 442f614..8b083cc 100644 --- a/src/Grace.CLI/Command/Branch.CLI.fs +++ b/src/Grace.CLI/Command/Branch.CLI.fs @@ -1934,7 +1934,6 @@ module Branch = if currentBranch.SaveEnabled then let! (updatedGraceStatus, newVersions) = getNewGraceStatusAndDirectoryVersions previousGraceStatus differences - newGraceStatus <- updatedGraceStatus newDirectoryVersions <- newVersions diff --git a/src/Grace.CLI/Command/Maintenance.CLI.fs b/src/Grace.CLI/Command/Maintenance.CLI.fs index a8fc2d3..50abe65 100644 --- a/src/Grace.CLI/Command/Maintenance.CLI.fs +++ b/src/Grace.CLI/Command/Maintenance.CLI.fs @@ -316,7 +316,7 @@ module Maintenance = )) ) - if errors.Count = 0 then + if errors |> Seq.isEmpty then if parseResult |> verbose then logToAnsiConsole Colors.Verbose "All files uploaded successfully." @@ -502,7 +502,7 @@ module Maintenance = )) ) - if errors.Count = 0 then + if errors |> Seq.isEmpty then () else AnsiConsole.MarkupLine($"{errors.Count} errors occurred.") @@ -716,7 +716,7 @@ module Maintenance = )) ) - if errors.Count = 0 then + if errors |> Seq.isEmpty then if parseResult |> verbose then logToAnsiConsole Colors.Verbose "All files uploaded successfully." @@ -902,7 +902,7 @@ module Maintenance = )) ) - if errors.Count = 0 then + if errors |> Seq.isEmpty then () else AnsiConsole.MarkupLine($"{errors.Count} errors occurred.") diff --git a/src/Grace.CLI/Command/Repository.CLI.fs b/src/Grace.CLI/Command/Repository.CLI.fs index a280b5b..894b5c7 100644 --- a/src/Grace.CLI/Command/Repository.CLI.fs +++ b/src/Grace.CLI/Command/Repository.CLI.fs @@ -661,7 +661,7 @@ module Repository = ) // Print out any errors that occurred. - if errors.Count = 0 then + if errors |> Seq.isEmpty then () else AnsiConsole.MarkupLine($"{errors.Count} errors occurred.") diff --git a/src/Grace.CLI/Command/Services.CLI.fs b/src/Grace.CLI/Command/Services.CLI.fs index 06678ee..b88605f 100644 --- a/src/Grace.CLI/Command/Services.CLI.fs +++ b/src/Grace.CLI/Command/Services.CLI.fs @@ -262,22 +262,22 @@ module Services = /// Serializes an object of type 'T to the specified file path using MessagePack. let serializeMessagePack<'T> (filePath: string) (data: 'T) = task { - let startInstant = getCurrentInstant () + //let startInstant = getCurrentInstant () use fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize = 65536, useAsync = true) do! MessagePackSerializer.SerializeAsync(fileStream, data, messagePackSerializerOptions) - let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}" - logToAnsiConsole Colors.Important $"Serialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s." + //let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}" + //logToAnsiConsole Colors.Important $"Serialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s." } :> Task /// Deserializes an object of type 'T from the specified file path using MessagePack. let deserializeMessagePack<'T> (filePath: string) = task { - let startInstant = getCurrentInstant () + //let startInstant = getCurrentInstant () use fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize = 65536, useAsync = true) let! returnValue = MessagePackSerializer.DeserializeAsync<'T>(fileStream, messagePackSerializerOptions) - let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}" - logToAnsiConsole Colors.Important $"Deserialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s." + //let duration = $"{(getCurrentInstant () - startInstant).TotalSeconds:F3}" + //logToAnsiConsole Colors.Important $"Deserialized file {filePath}; compressed length: {fileStream.Length}; time elapsed: {duration}s." return returnValue } @@ -713,7 +713,7 @@ module Services = )) ) - if errors.Count = 0 then + if errors |> Seq.isEmpty then return Ok(GraceReturnValue.Create true parameters.CorrelationId) else // use Seq.fold to create a single error message from the ConcurrentQueue diff --git a/src/Grace.CLI/Command/Watch.CLI.fs b/src/Grace.CLI/Command/Watch.CLI.fs index c4812cc..6db2f4a 100644 --- a/src/Grace.CLI/Command/Watch.CLI.fs +++ b/src/Grace.CLI/Command/Watch.CLI.fs @@ -197,7 +197,7 @@ module Watch = .ToList() let message = - if fileDifferences.Count = 0 then + if fileDifferences |> Seq.isEmpty then String.Empty else let sb = stringBuilderPool.Get() @@ -516,7 +516,7 @@ module Watch = logToAnsiConsole Colors.Verbose $"Scanning for differences." let! differences = scanForDifferences graceStatus // <--- This always finds the directories with updated write times, but we never update GraceStatus below.. - if differences.Count = 0 then + if differences |> Seq.isEmpty then logToAnsiConsole Colors.Verbose $"Already up-to-date." else logToAnsiConsole Colors.Verbose $"Found {differences.Count} differences." diff --git a/src/Grace.CLI/Program.CLI.fs b/src/Grace.CLI/Program.CLI.fs index c58cf66..f2c488f 100644 --- a/src/Grace.CLI/Program.CLI.fs +++ b/src/Grace.CLI/Program.CLI.fs @@ -143,7 +143,7 @@ module GraceCommand = /// If the command has no arguments - the user just typed `grace` - then we'll show the help screen and avoid showing an error message by adding a token that asks for help. let noErrorIfNoArgumentsMiddleware (context: InvocationContext) = - if context.ParseResult.Tokens.Count = 0 then + if context.ParseResult.Tokens |> Seq.isEmpty then context.ParseResult <- context.Parser.Parse(helpOptions[0]) let decideIfThisInstanceShouldBeCaseInsensitiveMiddleware (context: InvocationContext) = diff --git a/src/Grace.Server/ApplicationContext.Server.fs b/src/Grace.Server/ApplicationContext.Server.fs index d84055a..8c8092e 100644 --- a/src/Grace.Server/ApplicationContext.Server.fs +++ b/src/Grace.Server/ApplicationContext.Server.fs @@ -64,7 +64,6 @@ module ApplicationContext = let version = assembly.GetName().Version let fileInfo = FileInfo(assembly.Location) - logToConsole $"In setConfiguration: isNull(config): {isNull (config)}." logToConsole $"Grace Server version: {version}; build time (UTC): {fileInfo.LastWriteTimeUtc}." configuration <- config @@ -117,16 +116,6 @@ module ApplicationContext = task { let mutable isReady = false - let mutable workerThreads = 0 - let mutable completionPortThreads = 0 - ThreadPool.GetMaxThreads(&workerThreads, &completionPortThreads) - logToConsole $"Initial ThreadPool.GetMaxThreads: workerThreads: {workerThreads}; completionPortThreads: {completionPortThreads}." - ThreadPool.GetAvailableThreads(&workerThreads, &completionPortThreads) - logToConsole $"Initial ThreadPool.GetAvailableThreads: workerThreads: {workerThreads}; completionPortThreads: {completionPortThreads}." - - //let threadPoolSet = ThreadPool.SetMinThreads(25, 1000) - //if not <| threadPoolSet then logToConsole "Could not set ThreadPool.MinThreads." - // Wait for the Dapr gRPC port to be ready. logToConsole $"""---------------------------------------------------------------------------------------------- @@ -136,8 +125,8 @@ module ApplicationContext = talk to Dapr, so Grace Server will wait for {secondsToWaitForDaprToBeReady} seconds for Dapr to be ready. If no connection is made, that almost always means that something happened trying to start the Dapr sidecar, and Kubernetes is going to restart it. If that happens, - Grace Server also will exit and allow Kubernetes to restart it; by the time Grace Server - restarts, the Dapr sidecar will be up and running, and we should connect right away. + Grace Server will exit to allow Kubernetes to restart it; by the time Grace Server + restarts, the Dapr sidecar is usually up and running, and we should connect right away. -----------------------------------------------------------------------------------------------""" let mutable gRPCPort: int = 50001 // This is Dapr's default gRPC port. diff --git a/src/Grace.Server/Storage.Server.fs b/src/Grace.Server/Storage.Server.fs index 49edd32..d288ed2 100644 --- a/src/Grace.Server/Storage.Server.fs +++ b/src/Grace.Server/Storage.Server.fs @@ -200,7 +200,7 @@ module Storage = let! failed = deleteAllFromCosmosDb () - if failed.Count = 0 then + if failed |> Seq.isEmpty then log.LogWarning("{CurrentInstant} Succeeded deleting all rows from CosmosDB.", getCurrentInstantExtended ()) return! @@ -249,7 +249,7 @@ module Storage = let! failed = deleteAllRemindersFromCosmosDb () - if failed.Count = 0 then + if failed |> Seq.isEmpty then log.LogWarning("{CurrentInstant} Succeeded deleting all reminders from CosmosDB.", getCurrentInstantExtended ()) return!