public bool TryGet(string key, IRequestContext requestContext, out AnchorMailboxCacheEntry entry)
 {
     PerfCounters.HttpProxyCacheCountersInstance.AnchorMailboxLocalCacheHitsRateBase.Increment();
     PerfCounters.HttpProxyCacheCountersInstance.AnchorMailboxOverallCacheHitsRateBase.Increment();
     entry = null;
     if (this.innerCache.TryGetValue(key, out entry))
     {
         PerfCounters.HttpProxyCacheCountersInstance.AnchorMailboxLocalCacheHitsRate.Increment();
     }
     else if (HttpProxySettings.AnchorMailboxSharedCacheEnabled.Value)
     {
         long   latency  = 0L;
         string diagInfo = null;
         AnchorMailboxCacheEntry sharedCacheEntry = null;
         bool latency2 = LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryGet <AnchorMailboxCacheEntry>(key, requestContext.ActivityId, out sharedCacheEntry, out diagInfo), out latency);
         requestContext.LogSharedCacheCall(latency, diagInfo);
         if (latency2)
         {
             this.Add(key, sharedCacheEntry, requestContext, false);
             entry = sharedCacheEntry;
         }
     }
     if (entry != null)
     {
         PerfCounters.HttpProxyCacheCountersInstance.AnchorMailboxOverallCacheHitsRate.Increment();
         return(true);
     }
     return(false);
 }
 public void Remove(string key, IRequestContext requestContext)
 {
     this.innerCache.Remove(key);
     if (HttpProxySettings.AnchorMailboxSharedCacheEnabled.Value)
     {
         long   latency  = 0L;
         string diagInfo = null;
         LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryRemove(key, requestContext.ActivityId, out diagInfo), out latency);
         requestContext.LogSharedCacheCall(latency, diagInfo);
     }
 }
 public void Add(string key, AnchorMailboxCacheEntry entry, DateTime valueTimestamp, IRequestContext requestContext, bool addToSharedCache)
 {
     this.innerCache.TryInsertLimitedSliding(key, entry, AnchorMailboxCache.AnchorMailboxCacheAbsoluteTimeout, AnchorMailboxCache.AnchorMailboxCacheSlidingTimeout);
     if (HttpProxySettings.AnchorMailboxSharedCacheEnabled.Value && addToSharedCache)
     {
         long   latency  = 0L;
         string diagInfo = null;
         LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryInsert(key, entry, valueTimestamp, requestContext.ActivityId, out diagInfo), out latency);
         requestContext.LogSharedCacheCall(latency, diagInfo);
     }
     this.UpdateCacheSizeCounter();
 }
示例#4
0
        // Token: 0x0600017B RID: 379 RVA: 0x00007C0C File Offset: 0x00005E0C
        private ADObjectId GetRandomDatabasesFromForest(string resourceForestFqdn)
        {
            if (HttpProxySettings.LocalForestDatabaseEnabled.Value && Utilities.IsLocalForest(resourceForestFqdn))
            {
                return(LocalForestDatabaseProvider.Instance.GetRandomDatabase());
            }
            List <ADObjectId> list = null;

            if (!TargetForestAnchorMailbox.resourceForestToDatabaseMap.TryGetValue(resourceForestFqdn, out list) || list == null || list.Count <= 0)
            {
                object obj = TargetForestAnchorMailbox.forestDatabaseLock;
                lock (obj)
                {
                    if (!TargetForestAnchorMailbox.resourceForestToDatabaseMap.TryGetValue(resourceForestFqdn, out list) || list == null || list.Count <= 0)
                    {
                        list = new List <ADObjectId>();
                        PartitionId partitionId = new PartitionId(resourceForestFqdn);
                        ITopologyConfigurationSession resourceForestSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(2, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 306, "GetRandomDatabasesFromForest", "d:\\dbs\\sh\\e16df\\0212_214120_0\\cmd\\1g\\sources\\Dev\\Cafe\\src\\HttpProxy\\AnchorMailbox\\TargetForestAnchorMailbox.cs");
                        SortBy sortBy = new SortBy(ADObjectSchema.WhenCreatedUTC, 0);
                        List <PropertyDefinition> databaseSchema = new List <PropertyDefinition>
                        {
                            ADObjectSchema.Id
                        };
                        long latency = 0L;
                        ADPagedReader <ADRawEntry> latency2 = LatencyTracker.GetLatency <ADPagedReader <ADRawEntry> >(() => resourceForestSession.FindPagedADRawEntry(resourceForestSession.ConfigurationNamingContext, 2, TargetForestAnchorMailbox.DatabaseQueryFilter, sortBy, TargetForestAnchorMailbox.DatabasesToLoadPerForest.Value, databaseSchema, "d:\\dbs\\sh\\e16df\\0212_214120_0\\cmd\\1g\\sources\\Dev\\Cafe\\src\\HttpProxy\\AnchorMailbox\\TargetForestAnchorMailbox.cs", 323, "GetRandomDatabasesFromForest"), out latency);
                        base.RequestContext.LatencyTracker.HandleResourceLatency(latency);
                        if (latency2 != null)
                        {
                            foreach (ADRawEntry adrawEntry in latency2)
                            {
                                list.Add(adrawEntry.Id);
                            }
                        }
                        if (list.Count > 0)
                        {
                            TargetForestAnchorMailbox.resourceForestToDatabaseMap[resourceForestFqdn] = list;
                            if (list.Count < TargetForestAnchorMailbox.MinimumDatabasesForEffectiveLoadBalancing.Value)
                            {
                                base.RequestContext.Logger.AppendGenericError("TooFewDbsForLoadBalancing", string.Format("DbCount:{0}/Forest:{1}", list.Count, resourceForestFqdn));
                            }
                        }
                    }
                }
            }
            if (list != null && list.Count > 0)
            {
                int index = TargetForestAnchorMailbox.seededRand.Next(0, list.Count);
                return(list[index]);
            }
            return(null);
        }
 public void Remove(Guid database, IRequestContext requestContext)
 {
     this.serversCache.Remove(database);
     if (HttpProxySettings.MailboxServerLocatorSharedCacheEnabled.Value)
     {
         long   latency  = 0L;
         string diagInfo = null;
         LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryRemove(database.ToString(), requestContext.ActivityId, out diagInfo), out latency);
         if (requestContext != null)
         {
             requestContext.LogSharedCacheCall(latency, diagInfo);
         }
     }
 }
示例#6
0
        private static T ExecuteFunctionAndUpdateMovingAveragePerformanceCounter <T>(ExPerformanceCounter performanceCounter, Func <T> operationToTrack)
        {
            long newValue = 0L;
            T    latency;

            try
            {
                latency = LatencyTracker.GetLatency <T>(operationToTrack, out newValue);
            }
            finally
            {
                PerfCounters.UpdateMovingAveragePerformanceCounter(performanceCounter, newValue);
            }
            return(latency);
        }
示例#7
0
        private ADObjectId GetRandomDatabasesFromForest(string resourceForestFqdn)
        {
            List <ADObjectId> list = null;
            bool flag = TargetForestAnchorMailbox.resourceForestToDatabaseMap.TryGetValue(resourceForestFqdn, out list);

            if (!flag || list == null || list.Count <= 0)
            {
                lock (TargetForestAnchorMailbox.forestDatabaseLock)
                {
                    flag = TargetForestAnchorMailbox.resourceForestToDatabaseMap.TryGetValue(resourceForestFqdn, out list);
                    if (!flag || list == null || list.Count <= 0)
                    {
                        list = new List <ADObjectId>();
                        PartitionId partitionId = new PartitionId(resourceForestFqdn);
                        ITopologyConfigurationSession resourceForestSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromAccountPartitionRootOrgScopeSet(partitionId), 318, "GetRandomDatabasesFromForest", "f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\AnchorMailbox\\TargetForestAnchorMailbox.cs");
                        SortBy sortBy = new SortBy(ADObjectSchema.WhenCreatedUTC, SortOrder.Ascending);
                        List <PropertyDefinition> databaseSchema = new List <PropertyDefinition>
                        {
                            ADObjectSchema.Id
                        };
                        long latency = 0L;
                        ADPagedReader <ADRawEntry> latency2 = LatencyTracker.GetLatency <ADPagedReader <ADRawEntry> >(() => resourceForestSession.FindPagedADRawEntry(resourceForestSession.ConfigurationNamingContext, QueryScope.SubTree, TargetForestAnchorMailbox.DatabaseQueryFilter, sortBy, TargetForestAnchorMailbox.DatabasesToLoadPerForest.Value, databaseSchema), out latency);
                        base.RequestContext.LatencyTracker.HandleResourceLatency(latency);
                        if (latency2 != null)
                        {
                            foreach (ADRawEntry adrawEntry in latency2)
                            {
                                list.Add(adrawEntry.Id);
                            }
                        }
                        if (list.Count > 0)
                        {
                            TargetForestAnchorMailbox.resourceForestToDatabaseMap[resourceForestFqdn] = list;
                            if (list.Count < TargetForestAnchorMailbox.MinimumDatabasesForEffectiveLoadBalancing.Value)
                            {
                                base.RequestContext.Logger.AppendGenericError("TooFewDbsForLoadBalancing", string.Format("DbCount:{0}/Forest:{1}", list.Count, resourceForestFqdn));
                            }
                        }
                    }
                }
            }
            if (list != null && list.Count > 0)
            {
                int index = TargetForestAnchorMailbox.seededRand.Next(0, list.Count);
                return(list[index]);
            }
            return(null);
        }
 private void Add(Guid database, MailboxServerCacheEntry entry, Guid initiatingRequestId, IRequestContext requestContext, bool addToSharedCache = true)
 {
     ExTraceGlobals.VerboseTracer.TraceDebug <Guid, BackEndServer, bool>((long)this.GetHashCode(), "[MailboxServerCache::Add]: Adding database {0} with server {1} to cache. addToSharedCache={2}", database, entry.BackEndServer, addToSharedCache);
     this.serversCache.TryInsertAbsolute(database, entry, MailboxServerCache.MailboxServerCacheAbsoluteTimeout);
     if (HttpProxySettings.MailboxServerLocatorSharedCacheEnabled.Value && addToSharedCache)
     {
         long   latency  = 0L;
         string diagInfo = null;
         LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryInsert(database.ToString(), entry, entry.LastRefreshTime, initiatingRequestId, out diagInfo), out latency);
         if (requestContext != null)
         {
             requestContext.LogSharedCacheCall(latency, diagInfo);
         }
     }
     LocalSiteMailboxServerCache.Instance.Add(database, entry.BackEndServer, entry.ResourceForest);
 }
示例#9
0
        internal static T InvokeGls <T>(LatencyTracker latencyTracker, Func <T> glsCall)
        {
            if (latencyTracker == null)
            {
                throw new ArgumentNullException("latencyTracker");
            }
            if (glsCall == null)
            {
                throw new ArgumentNullException("glsCall");
            }
            long latency  = 0L;
            T    latency2 = LatencyTracker.GetLatency <T>(() => glsCall(), out latency);

            latencyTracker.HandleGlsLatency(latency);
            return(latency2);
        }
        // Token: 0x060002B8 RID: 696 RVA: 0x0000D928 File Offset: 0x0000BB28
        private string InvokeMserv(string userAddress)
        {
            int       currentSitePartnerId = HttpProxyGlobals.LocalSite.Member.PartnerId;
            string    text = null;
            long      num  = 0L;
            Exception ex   = null;

            try
            {
                text = LatencyTracker.GetLatency <string>(() => EdgeSyncMservConnector.GetRedirectServer(DatacenterRedirectStrategy.PodRedirectTemplate.Value, userAddress, currentSitePartnerId, DatacenterRedirectStrategy.PodSiteStartRange.Value, DatacenterRedirectStrategy.PodSiteEndRange.Value, false, true), out num);
            }
            catch (MServTransientException ex)
            {
            }
            catch (MServPermanentException ex)
            {
            }
            catch (InvalidOperationException ex)
            {
            }
            catch (LocalizedException ex)
            {
            }
            finally
            {
                this.RequestContext.Logger.AppendGenericInfo("MservLatency", num);
            }
            string message = string.Format("Failed to look up MSERV for address {0}.", userAddress);

            if (ex != null)
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(3))
                {
                    ExTraceGlobals.VerboseTracer.TraceError <int, string, Exception>((long)this.GetHashCode(), "[DatacenterRedirectStrategy::InvokeMserv]: Context {0}. Failed to look up MSERV for address {1}. Error: {2}", this.TraceContext, userAddress, ex);
                }
                throw new HttpProxyException(HttpStatusCode.InternalServerError, 2002, message, ex);
            }
            if (string.IsNullOrEmpty(text))
            {
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(3))
                {
                    ExTraceGlobals.VerboseTracer.TraceError <int, string>((long)this.GetHashCode(), "[DatacenterRedirectStrategy::InvokeMserv]: Context {0}. MSERV did not return redirect server for address {1}.", this.TraceContext, userAddress);
                }
                throw new HttpProxyException(HttpStatusCode.InternalServerError, 2002, message);
            }
            return(text);
        }
示例#11
0
        // Token: 0x0600017A RID: 378 RVA: 0x00007B84 File Offset: 0x00005D84
        private string GetResourceForestFqdnByAcceptedDomainName(string tenantAcceptedDomain)
        {
            string resourceForestFqdn;

            if (!TargetForestAnchorMailbox.domainToResourceForestMap.TryGetValue(tenantAcceptedDomain, ref resourceForestFqdn))
            {
                long latency = 0L;
                resourceForestFqdn = LatencyTracker.GetLatency <string>(delegate()
                {
                    resourceForestFqdn = ADAccountPartitionLocator.GetResourceForestFqdnByAcceptedDomainName(tenantAcceptedDomain);
                    return(resourceForestFqdn);
                }, out latency);
                TargetForestAnchorMailbox.domainToResourceForestMap.TryInsertAbsolute(tenantAcceptedDomain, resourceForestFqdn, TargetForestAnchorMailbox.DomainForestAbsoluteTimeout.Value);
                base.RequestContext.LatencyTracker.HandleGlsLatency(latency);
            }
            return(resourceForestFqdn);
        }
示例#12
0
        internal static MailboxDatabase[] InvokeResourceForest(LatencyTracker latencyTracker, Func <MailboxDatabase[]> activeDirectoryFunction)
        {
            if (latencyTracker == null)
            {
                throw new ArgumentNullException("latencyTracker");
            }
            if (activeDirectoryFunction == null)
            {
                throw new ArgumentNullException("activeDirectoryFunction");
            }
            long latency = 0L;

            MailboxDatabase[] latency2 = LatencyTracker.GetLatency <MailboxDatabase[]>(() => activeDirectoryFunction(), out latency);
            latencyTracker.HandleResourceLatency(latency);
            if (latency2 != null && latency2.Length > 0)
            {
                string originatingServer = latency2[0].OriginatingServer;
            }
            return(latency2);
        }
示例#13
0
        internal static ADRawEntry InvokeAccountForest(LatencyTracker latencyTracker, Func <ADRawEntry> activeDirectoryFunction)
        {
            if (latencyTracker == null)
            {
                throw new ArgumentNullException("latencyTracker");
            }
            if (activeDirectoryFunction == null)
            {
                throw new ArgumentNullException("activeDirectoryFunction");
            }
            long       latency  = 0L;
            ADRawEntry latency2 = LatencyTracker.GetLatency <ADRawEntry>(() => activeDirectoryFunction(), out latency);

            latencyTracker.HandleAccountLatency(latency);
            if (latency2 != null)
            {
                string originatingServer = latency2.OriginatingServer;
            }
            return(latency2);
        }
        public bool TryGet(Guid database, IRequestContext requestContext, out BackEndServer backEndServer)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            backEndServer = null;
            PerfCounters.HttpProxyCacheCountersInstance.BackEndServerLocalCacheHitsRateBase.Increment();
            PerfCounters.HttpProxyCacheCountersInstance.BackEndServerOverallCacheHitsRateBase.Increment();
            PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerLocalCacheHitsRate);
            PerfCounters.IncrementMovingPercentagePerformanceCounterBase(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerOverallCacheHitsRate);
            MailboxServerCacheEntry mailboxServerCacheEntry = null;
            bool flag  = false;
            bool flag2 = this.serversCache.TryGetValue(database, out mailboxServerCacheEntry);

            if (flag2)
            {
                if (MailboxServerCache.IsE14ServerStale(mailboxServerCacheEntry))
                {
                    this.Remove(database, requestContext);
                    return(false);
                }
                backEndServer = mailboxServerCacheEntry.BackEndServer;
                PerfCounters.HttpProxyCacheCountersInstance.BackEndServerLocalCacheHitsRate.Increment();
                PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerLocalCacheHitsRate);
                if (mailboxServerCacheEntry.IsDueForRefresh(MailboxServerCache.GetRefreshInterval(backEndServer)))
                {
                    flag = true;
                }
            }
            if (HttpProxySettings.MailboxServerLocatorSharedCacheEnabled.Value && (!flag2 || flag))
            {
                MailboxServerCacheEntry sharedCacheEntry = null;
                long   latency  = 0L;
                string diagInfo = null;
                bool   latency2 = LatencyTracker.GetLatency <bool>(() => this.sharedCacheClient.TryGet <MailboxServerCacheEntry>(database.ToString(), requestContext.ActivityId, out sharedCacheEntry, out diagInfo), out latency);
                requestContext.LogSharedCacheCall(latency, diagInfo);
                if (latency2 && (!flag2 || sharedCacheEntry.LastRefreshTime > mailboxServerCacheEntry.LastRefreshTime))
                {
                    this.Add(database, sharedCacheEntry, requestContext, false);
                    mailboxServerCacheEntry = sharedCacheEntry;
                    flag2 = true;
                }
            }
            if (flag2)
            {
                backEndServer = mailboxServerCacheEntry.BackEndServer;
                PerfCounters.HttpProxyCacheCountersInstance.BackEndServerOverallCacheHitsRate.Increment();
                PerfCounters.UpdateMovingPercentagePerformanceCounter(PerfCounters.HttpProxyCacheCountersInstance.MovingPercentageBackEndServerOverallCacheHitsRate);
                if (!this.LazyRefreshDisabled && mailboxServerCacheEntry.IsDueForRefresh(MailboxServerCache.GetRefreshInterval(mailboxServerCacheEntry.BackEndServer)))
                {
                    if (MailboxServerCache.BackgroundServerRefreshEnabled.Value)
                    {
                        this.RegisterRefresh(new DatabaseWithForest(database, mailboxServerCacheEntry.ResourceForest, requestContext.ActivityId));
                    }
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestContext.Logger, "ServerLocatorRefresh", database);

                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestContext.Logger, "RefreshingCacheEntry", mailboxServerCacheEntry.ToString());
                }
            }
            return(flag2);
        }