public Task TestUpdateRingAndGetLocations() { return(RunTestAsync(async(context, store, directory) => { ClusterState clusterState = ClusterState.CreateForTest(); for (int i = 0; i <= 10; i++) { var machineId = new MachineId(i); var machineLocation = new MachineLocation(i.ToString()); clusterState.AddMachine(machineId, machineLocation); } var contentHashes = new List <ContentHashWithPath>(); var contentHash1 = new ContentHashWithPath(new ContentHash("MD5:72F6F256239CC69B6FE9AF1C7489CFD1"), directory.Path / "hash1"); var contentHash2 = new ContentHashWithPath(new ContentHash("MD5:61C4F184221AD54A2FA4A92A6137AA42"), directory.Path / "hash2"); contentHashes.Add(contentHash1); contentHashes.Add(contentHash2); var result = await store.UpdateRingAsync(context, clusterState).ShouldBeSuccess(); var locations = store.GetBulkLocations(context, contentHashes).ShouldBeSuccess(); locations.Count.Should().Be(2); locations.ContentHashesInfo[0].ContentHash.Serialize().Should().Be("MD5:72F6F256239CC69B6FE9AF1C7489CFD1"); locations.ContentHashesInfo[0].Locations[0].ToString().Should().Be("6"); locations.ContentHashesInfo[0].Locations[1].ToString().Should().Be("4"); locations.ContentHashesInfo[0].Locations[2].ToString().Should().Be("5"); locations.ContentHashesInfo[1].ContentHash.Serialize().Should().Be("MD5:61C4F184221AD54A2FA4A92A6137AA42"); locations.ContentHashesInfo[1].Locations[0].ToString().Should().Be("10"); locations.ContentHashesInfo[1].Locations[1].ToString().Should().Be("1"); locations.ContentHashesInfo[1].Locations[2].ToString().Should().Be("3"); })); }
/// <nodoc /> public void StoreResult(OperationContext context, string path, List <string> machines) { foreach (var machine in machines) { _knownMachines.GetOrAdd(machine, _ => { var machineId = new MachineId(Interlocked.Increment(ref _currentId)); _clusterState.AddMachine(machineId, new MachineLocation(machine)); return(machineId); }); } var pathHash = ComputePathHash(path); var entry = ContentLocationEntry.Create(MachineIdSet.Empty.SetExistence(machines.SelectList(machine => _knownMachines[machine]), true), 0, DateTime.UtcNow); _database.Store(context, pathHash, entry); }
public void BinManagerExcludesMaster() { var amountMachines = 4; var machineMappings = Enumerable.Range(0, amountMachines).Select(i => new MachineMapping(new MachineLocation(i.ToString()), new MachineId(i))).ToArray(); var masterMapping = machineMappings[0]; var clusterState = new ClusterState(machineMappings[0].Id, machineMappings) { EnableBinManagerUpdates = true }; foreach (var mapping in machineMappings) { clusterState.AddMachine(mapping.Id, mapping.Location); } clusterState.SetMasterMachine(masterMapping.Location); clusterState.InitializeBinManagerIfNeeded(locationsPerBin: amountMachines, _clock, expiryTime: TimeSpan.Zero); var binMappings = clusterState.GetBinMappings().ThrowIfFailure(); foreach (var binMapping in binMappings) { // Master should not be there binMapping.Length.Should().Be(amountMachines - 1); binMapping.Should().NotContain(masterMapping.Id); } // Make sure this stays true after updates var inactiveMachines = new BitMachineIdSet(new byte[amountMachines], 0); inactiveMachines = inactiveMachines.SetExistenceBits(MachineIdCollection.Create(machineMappings[1].Id), true); clusterState.SetMachineStates(inactiveMachines).ShouldBeSuccess(); binMappings = clusterState.GetBinMappings().ThrowIfFailure(); foreach (var binMapping in binMappings) { // Master and inactive should not be there binMapping.Length.Should().Be(amountMachines - 2); binMapping.Should().NotContain(masterMapping.Id); } }
public Task TestPutToColdStorageWithRemoteLocations() { return(RunTestAsync(async(context, store, directory) => { ClusterState clusterState = ClusterState.CreateForTest(); for (int i = 0; i <= 10; i++) { clusterState.AddMachine(new MachineId(i), new MachineLocation(i.ToString())); } var result = await store.UpdateRingAsync(context, clusterState).ShouldBeSuccess(); // Create file to put var originalPath = directory.Path / "original.txt"; var fileContents = GetRandomFileContents(); FileSystem.WriteAllText(originalPath, fileContents); var contentHasher = HashInfoLookup.GetContentHasher(HashType.MD5); var contentHash = contentHasher.GetContentHash(Encoding.UTF8.GetBytes(fileContents)); await store.PutFileAsync(context, contentHash, new DisposableFile(context, FileSystem, originalPath), context.Token).ShouldBeSuccess(); })); }