/// <nodoc />
        public static string GetShortHashesTraceString(this GetBulkLocationsResult result)
        {
            if (!result)
            {
                return(result.ToString());
            }

            return(string.Join(", ", result.ContentHashesInfo.Select(info => $"{info.ContentHash.ToShortString()}={info.Locations?.Count ?? 0}")));
        }
Exemplo n.º 2
0
        public void GetBulkStop(Context context, IReadOnlyList <ContentHash> input, GetBulkLocationsResult result)
        {
            if (context.IsEnabled)
            {
                string stringResult = result.Succeeded ? string.Join(",", result.ContentHashesInfo) : result.ErrorMessage;
                TracerOperationFinished(context, result, $"{Name}.{GetBulkCallName}({input.Count}) stop {result.DurationMs}ms result=[{stringResult}]");
            }

            _getBulkCallCounter.Completed(result.Duration.Ticks);
        }
Exemplo n.º 3
0
        public void GetShortHashesTraceStringForInactiveMachinesTests()
        {
            var hash     = ContentHash.Random();
            var machines = Enumerable.Range(1, 1000).Select(n => new MachineLocation($"Machine {n}")).ToList();
            GetBulkLocationsResult result = new GetBulkLocationsResult(
                new List <ContentHashWithSizeAndLocations>()
            {
                new ContentHashWithSizeAndLocations(
                    hash,
                    size: 42,
                    new List <MachineLocation>()
                {
                    new MachineLocation("Machine1")
                },
                    filteredOutLocations: machines)
            });

            var s = result.GetShortHashesTraceStringForInactiveMachines();

            s.Should().Contain(hash.ToShortString());
            s.Should().Contain(machines[0].ToString());
        }
Exemplo n.º 4
0
        public async Task TestLocalContentLocationDatabaseAsync()
        {
            var       contentHash = ContentHash.Random();
            var       context     = new Context(TestGlobal.Logger);
            const int numReplicas = 1;
            var       paths       = CreatePaths(numReplicas);
            var       valid       = ValidType.All;
            long      randomSize  = (long)ThreadSafeRandom.Generator.NextDouble() * long.MaxValue;

            GetBulkLocationsResult locationsResult = null;
            List <ContentHashWithSizeAndLocations>           contentHashInfo = null;
            IDictionary <RedisKey, MockRedisValueWithExpiry> redisData       = GetRedisData(contentHash, paths.Length, randomSize, TimeSpan.FromHours(1));

            await TestAsync(
                context,
                GetRedisDatabase(_clock, redisData.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Value)),
                GetRedisDatabase(_clock, GetMachineRedisData(paths, valid).ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Value)),
                async (genericStore, storeFactory) =>
            {
                var store         = (RedisContentLocationStore)genericStore;
                contentHashInfo   = CreateContentHashWithSizeAndLocations(contentHash, paths, randomSize);
                var contentHashes = contentHashInfo.Select(p => p.ContentHash).ToList();
                locationsResult   =
                    await store.GetBulkAsync(context, contentHashes, CancellationToken.None, UrgencyHint.Nominal);

                // Updating the value with a new location should cause a difference to be reported in the counters
                await store.UpdateBulkAsync(
                    context,
                    CreateContentHashWithSizeAndLocations(contentHash, CreatePaths(2), randomSize),
                    CancellationToken.None,
                    UrgencyHint.Nominal,
                    LocationStoreOption.None).ShouldBeSuccess();

                // Get and update operations should not trigger updates on database
                var counters = store.Counters;
                counters.GetCounterValue(ContentLocationStoreCounters.DatabaseStoreUpdate).Should().Be(0);
                counters.GetCounterValue(ContentLocationStoreCounters.DatabaseStoreAdd).Should().Be(0);
            });
        }
Exemplo n.º 5
0
        public static string?GetShortHashesTraceStringForInactiveMachines(this GetBulkLocationsResult result)
        {
            Contract.Requires(result.Succeeded);
            const int MaxMachines = 3;

            // The output format:
            // Hash1=3 (M1, M2, M3), Hash2=4 (M1, M2, M3, ...)
            var hashesWithInactiveMachines = result.ContentHashesInfo.Where(hashInfo => hashInfo.FilteredOutInactiveMachineLocations is not null);

            if (hashesWithInactiveMachines.Any())
            {
                // Some of the locations were filtered out because the machines that used to have them are inactive.
                using (var stringBuilderWrapper = Pools.StringBuilderPool.GetInstance())
                {
                    var stringBuilder = stringBuilderWrapper.Instance;

                    bool first = true;
                    foreach (var info in hashesWithInactiveMachines)
                    {
                        if (!first)
                        {
                            stringBuilder.Append(", ");
                        }

                        first = false;
                        var machines = info.FilteredOutInactiveMachineLocations !;
                        stringBuilder.AppendFormat("{0}={1}", info.ContentHash.ToShortString(), machines.Count);

                        string extra = machines.Count > MaxMachines ? ", ..." : string.Empty;
                        stringBuilder.AppendFormat(" ({0}{1})", string.Join(", ", machines.Take(MaxMachines).Select(m => m.ToString())), extra);
                    }

                    return(stringBuilder.ToString());
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        public static string GetShortHashesTraceString(this GetBulkLocationsResult result)
        {
            Contract.Requires(result.Succeeded);

            return(string.Join(", ", result.ContentHashesInfo.Select(info => $"{info.ContentHash.ToShortString()}={info.Locations?.Count ?? 0}")));
        }