public Result <IReadOnlyList <ContentEvictionInfo> > GetEffectiveLastAccessTimes( OperationContext context, IReadOnlyList <ContentHashWithLastAccessTime> contentHashes) { Contract.RequiresNotNull(contentHashes); Contract.Requires(contentHashes.Count > 0); // This is required because the code inside could throw. var effectiveLastAccessTimes = new List <ContentEvictionInfo>(); double logInverseMachineRisk = -Math.Log(_configuration.MachineRisk); foreach (var contentHash in contentHashes) { DateTime lastAccessTime = contentHash.LastAccessTime; int replicaCount = 1; ReplicaRank rank = ReplicaRank.None; var(localInfo, distributedEntry, isDesignatedLocation) = _contentResolver.GetContentInfo(context, contentHash.Hash); // Getting a size from content directory information first. long size = localInfo.Size; if (distributedEntry != null) { // Use the latest last access time between LLS and local last access time DateTime distributedLastAccessTime = distributedEntry.LastAccessTimeUtc.ToDateTime(); lastAccessTime = distributedLastAccessTime > lastAccessTime ? distributedLastAccessTime : lastAccessTime; rank = GetReplicaRank(contentHash.Hash, distributedEntry, _contentResolver.LocalMachineId, _configuration, _now); if (isDesignatedLocation) { rank = Combine(ReplicaRank.Designated, rank); } replicaCount = distributedEntry.Locations.Count; if (size == 0) { size = distributedEntry.ContentSize; } } var localAge = _now - contentHash.LastAccessTime; var age = _now - lastAccessTime; var effectiveAge = GetEffectiveLastAccessTime(_configuration, age, replicaCount, size, rank, logInverseMachineRisk); var info = new ContentEvictionInfo( contentHash.Hash, age: age, localAge: localAge, effectiveAge: effectiveAge, replicaCount: replicaCount, size: size, rank: rank); effectiveLastAccessTimes.Add(info); } return(Result.Success <IReadOnlyList <ContentEvictionInfo> >(effectiveLastAccessTimes)); }
public Result <IReadOnlyList <ContentEvictionInfo> > GetEffectiveLastAccessTimes( OperationContext context, MachineId localMachineId, IReadOnlyList <ContentHashWithLastAccessTime> contentHashes) { Contract.RequiresNotNull(contentHashes); Contract.Requires(contentHashes.Count > 0); // This is required because the code inside could throw. var effectiveLastAccessTimes = new List <ContentEvictionInfo>(); double logInverseMachineRisk = -Math.Log(_configuration.MachineRisk); foreach (var contentHash in contentHashes) { DateTime lastAccessTime = contentHash.LastAccessTime; int replicaCount = 1; bool isImportantReplica = false; var(contentInfo, entry) = _contentResolver.GetContentInfo(context, contentHash.Hash); // Getting a size from content directory information first. long size = contentInfo.Size; if (entry != null) { // Use the latest last access time between LLS and local last access time DateTime distributedLastAccessTime = entry.LastAccessTimeUtc.ToDateTime(); lastAccessTime = distributedLastAccessTime > lastAccessTime ? distributedLastAccessTime : lastAccessTime; isImportantReplica = IsImportantReplica(contentHash.Hash, entry, localMachineId, _configuration.DesiredReplicaRetention); replicaCount = entry.Locations.Count; if (size == 0) { size = entry.ContentSize; } } var age = _clock.UtcNow - lastAccessTime; var effectiveAge = GetEffectiveLastAccessTime(_configuration, age, replicaCount, size, isImportantReplica, logInverseMachineRisk); var info = new ContentEvictionInfo(contentHash.Hash, age, effectiveAge, replicaCount, size, isImportantReplica); effectiveLastAccessTimes.Add(info); } return(Result.Success <IReadOnlyList <ContentEvictionInfo> >(effectiveLastAccessTimes)); }
private static ContentHashWithLastAccessTimeAndReplicaCount ToContentHashListWithLastAccessTimeAndReplicaCount(ContentEvictionInfo contentHashInfo) => new ContentHashWithLastAccessTimeAndReplicaCount(contentHashInfo.ContentHash, DateTime.UtcNow - contentHashInfo.Age, contentHashInfo.ReplicaCount, safeToEvict: true, effectiveLastAccessTime: DateTime.UtcNow - contentHashInfo.EffectiveAge);