private T PerformAction <T>(DistributedStoreKey key, RequestInfo req, bool isPrimary, Func <IDistributedStoreKey, bool, StoreKind, T> func)
        {
            IDistributedStoreKey arg       = isPrimary ? key.PrimaryStoreKey : key.ShadowStoreKey;
            StoreKind            storeKind = isPrimary ? this.StoreSettings.Primary : this.StoreSettings.Shadow;

            this.PerfTracker.UpdateStart(key, storeKind, isPrimary);
            Exception exception = null;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            T result;

            try
            {
                result = func(arg, isPrimary, storeKind);
            }
            catch (Exception ex)
            {
                exception = ex;
                throw;
            }
            finally
            {
                this.PerfTracker.UpdateFinish(key, storeKind, isPrimary, req, stopwatch.ElapsedMilliseconds, exception, false);
            }
            return(result);
        }
        public IDistributedStoreKey GetBaseKey(DxStoreKeyAccessMode mode, DistributedStore.Context context)
        {
            if (this.IsRestartProcessOnDxStoreModeChange)
            {
                this.StartProcessRestartTimer();
            }
            DistributedStoreKey compositeKey = new DistributedStoreKey(string.Empty, string.Empty, mode, context);

            compositeKey.IsBaseKey = true;
            try
            {
                this.ExecuteRequest(compositeKey, OperationCategory.GetBaseKey, OperationType.Read, string.Empty, delegate(IDistributedStoreKey key, bool isPrimary, StoreKind storeKind)
                {
                    this.SetKeyByRole(compositeKey, isPrimary, this.BaseKeyGenerator(mode, context, storeKind));
                });
            }
            finally
            {
                if (compositeKey.PrimaryStoreKey == null)
                {
                    compositeKey.CloseKey();
                    compositeKey = null;
                }
            }
            return(compositeKey);
        }
        public T ExecuteRequest <T>(DistributedStoreKey key, OperationCategory operationCategory, OperationType operationType, string dbgInfo, Func <IDistributedStoreKey, bool, StoreKind, T> func)
        {
            RequestInfo req = new RequestInfo(operationCategory, operationType, dbgInfo);

            this.EnqueueShadowAction <T>(key, req, func);
            return(this.PerformAction <T>(key, req, true, func));
        }
Example #4
0
 public void UpdateStart(DistributedStoreKey key, StoreKind storeKind, bool isPrimary)
 {
     lock (this.locker)
     {
         PerformanceEntry orAdd = this.GetOrAdd(storeKind, isPrimary);
         orAdd.RecordStart();
     }
 }
 public void ExecuteRequest(DistributedStoreKey key, OperationCategory operationCategory, OperationType operationType, string dbgInfo, Action <IDistributedStoreKey, bool, StoreKind> action)
 {
     this.ExecuteRequest <int>(key, operationCategory, operationType, dbgInfo, delegate(IDistributedStoreKey storeKey, bool isPrimary, StoreKind storeKind)
     {
         action(storeKey, isPrimary, storeKind);
         return(0);
     });
 }
Example #6
0
 public void UpdateFinish(DistributedStoreKey key, StoreKind storeKind, bool isPrimary, RequestInfo req, long latencyInMs, Exception exception, bool isSkipped)
 {
     this.LogExecution(key, storeKind, isPrimary, req, latencyInMs, exception, isSkipped);
     lock (this.locker)
     {
         PerformanceEntry orAdd = this.GetOrAdd(storeKind, isPrimary);
         orAdd.RecordFinish(req, latencyInMs, exception, isSkipped);
     }
 }
 private void EnqueueShadowAction <T>(DistributedStoreKey key, RequestInfo req, Func <IDistributedStoreKey, bool, StoreKind, T> func)
 {
     if (!this.StoreSettings.IsShadowConfigured)
     {
         return;
     }
     lock (this.shadowLock)
     {
         Queue <Action> queue;
         int            maxAllowedLimit;
         if (req.OperationType == OperationType.Write)
         {
             queue           = this.shadowWriteQueue;
             maxAllowedLimit = RegistryParameters.DistributedStoreShadowMaxAllowedWriteQueueLength;
         }
         else
         {
             maxAllowedLimit = RegistryParameters.DistributedStoreShadowMaxAllowedReadQueueLength;
             if (req.OperationCategory == OperationCategory.OpenKey)
             {
                 queue = this.shadowOpenRequestsQueue;
             }
             else
             {
                 queue = this.shadowReadQueue;
             }
         }
         if (this.EnsureQueueLengthInLimit(queue, maxAllowedLimit, key, req))
         {
             if (!req.IsGetBaseKeyRequest && !req.IsCloseKeyRequest && key.ShadowStoreKey == null)
             {
                 queue.Enqueue(delegate
                 {
                     using (IDistributedStoreKey baseKeyByStoreKind = this.GetBaseKeyByStoreKind(DxStoreKeyAccessMode.Write, key.Context, this.StoreSettings.Shadow))
                     {
                         if (baseKeyByStoreKind != null)
                         {
                             key.ShadowStoreKey = baseKeyByStoreKind.OpenKey(key.FullKeyName, DxStoreKeyAccessMode.Write, false, null);
                         }
                     }
                 });
             }
             queue.Enqueue(delegate
             {
                 this.PerformAction <T>(key, req, false, func);
             });
             if (!this.isShadowActionExecuting)
             {
                 this.isShadowActionExecuting = true;
                 ThreadPool.QueueUserWorkItem(delegate(object o)
                 {
                     this.ExecuteShadowActions();
                 });
             }
         }
     }
 }
 public void SetKeyByRole(DistributedStoreKey compositeKey, bool isPrimary, IDistributedStoreKey key)
 {
     if (isPrimary)
     {
         compositeKey.PrimaryStoreKey = key;
         return;
     }
     compositeKey.ShadowStoreKey = key;
 }
        // Token: 0x060005A5 RID: 1445 RVA: 0x0001507C File Offset: 0x0001327C
        private IDistributedStoreKey OpenKeyFinal(string subKeyName, DxStoreKeyAccessMode mode, bool isIgnoreIfNotExist, ReadWriteConstraints constraints)
        {
            OperationCategory operationCategory = OperationCategory.OpenKey;
            OperationType     operationType     = OperationType.Read;

            if (mode == DxStoreKeyAccessMode.CreateIfNotExist)
            {
                operationCategory = OperationCategory.OpenOrCreateKey;
                operationType     = OperationType.Write;
            }
            DistributedStoreKey  compositeKey = new DistributedStoreKey(this.FullKeyName, subKeyName, mode, this.Context);
            IDistributedStoreKey result;

            try
            {
                result = (DistributedStore.Instance.ExecuteRequest <bool>(this, operationCategory, operationType, string.Format("SubKey: [{0}] Mode: [{1}] IsBestEffort: [{2}] IsConstrained: [{3}]", new object[]
                {
                    subKeyName,
                    mode,
                    isIgnoreIfNotExist,
                    constraints != null
                }), delegate(IDistributedStoreKey key, bool isPrimary, StoreKind storeKind)
                {
                    this.ThrowIfKeyIsInvalid(key);
                    IDistributedStoreKey distributedStoreKey = key.OpenKey(subKeyName, mode, isIgnoreIfNotExist, ReadWriteConstraints.Copy(constraints));
                    if (distributedStoreKey != null)
                    {
                        DistributedStore.Instance.SetKeyByRole(compositeKey, isPrimary, distributedStoreKey);
                        return(true);
                    }
                    return(false);
                }) ? compositeKey : null);
            }
            finally
            {
                if (compositeKey.PrimaryStoreKey == null)
                {
                    compositeKey.CloseKey();
                }
            }
            return(result);
        }
Example #10
0
        public void LogExecution(DistributedStoreKey key, StoreKind storeKind, bool isPrimary, RequestInfo req, long latencyInMs, Exception exception, bool isSkipped)
        {
            if (!isPrimary && !RegistryParameters.DistributedStoreIsLogShadowApiResult)
            {
                return;
            }
            bool   flag     = exception == null && !isSkipped;
            string text     = req.OperationCategory.ToString();
            string text2    = (key != null) ? key.FullKeyName : string.Empty;
            string debugStr = req.DebugStr;
            string text3    = (key != null) ? key.InstanceId.ToString() : string.Empty;
            string text4    = string.Empty;

            if (RegistryParameters.DistributedStoreIsLogApiExecutionCallstack)
            {
                text4 = new StackTrace(3, true).ToString();
            }
            if (flag)
            {
                if (RegistryParameters.DistributedStoreIsLogApiSuccess)
                {
                    if (this.apiExecutionPeriodicLogDuration != TimeSpan.Zero)
                    {
                        DxStoreHACrimsonEvents.ApiExecutionSuccess.LogPeriodic <string, bool, StoreKind, bool, string, OperationType, string, long, string, bool, string, string, string, string>(text, this.apiExecutionPeriodicLogDuration, text, isPrimary, storeKind, true, text2, req.OperationType, req.InitiatedTime.ToString("o"), latencyInMs, string.Empty, false, debugStr, text3, text4, this.CurrentProcessName);
                        return;
                    }
                    DxStoreHACrimsonEvents.ApiExecutionSuccess.Log <string, bool, StoreKind, bool, string, OperationType, string, long, string, bool, string, string, string, string>(text, isPrimary, storeKind, true, text2, req.OperationType, req.InitiatedTime.ToString("o"), latencyInMs, string.Empty, false, debugStr, text3, text4, this.CurrentProcessName);
                }
                return;
            }
            string text5 = isSkipped ? "<ApiSkipped>" : exception.ToString();
            string text6 = text + ((exception == null) ? string.Empty : exception.GetType().Name);

            if (this.apiExecutionPeriodicLogDuration != TimeSpan.Zero)
            {
                DxStoreHACrimsonEvents.ApiExecutionFailed.LogPeriodic <string, bool, StoreKind, bool, string, OperationType, string, long, string, bool, string, string, string, string>(text6, this.apiExecutionPeriodicLogDuration, text, isPrimary, storeKind, false, text2, req.OperationType, req.InitiatedTime.ToString("o"), latencyInMs, text5.Substring(0, Math.Min(text5.Length, 5000)), isSkipped, debugStr, text3, text4, this.CurrentProcessName);
                return;
            }
            DxStoreHACrimsonEvents.ApiExecutionFailed.Log <string, bool, StoreKind, bool, string, OperationType, string, long, string, bool, string, string, string, string>(text, isPrimary, storeKind, false, text2, req.OperationType, req.InitiatedTime.ToString("o"), latencyInMs, text5.Substring(0, Math.Min(text5.Length, 5000)), isSkipped, debugStr, text3, text4, this.CurrentProcessName);
        }
 private bool EnsureQueueLengthInLimit(Queue <Action> queue, int maxAllowedLimit, DistributedStoreKey key, RequestInfo req)
 {
     if (queue.Count < maxAllowedLimit)
     {
         return(true);
     }
     this.PerfTracker.UpdateStart(key, this.StoreSettings.Shadow, false);
     this.PerfTracker.UpdateFinish(key, this.StoreSettings.Shadow, false, req, 0L, null, true);
     return(false);
 }
 public T ExecuteRequest <T>(DistributedStoreKey key, OperationCategory operationCategory, OperationType operationType, string dbgInfo, Func <IDistributedStoreKey, T> func)
 {
     return(this.ExecuteRequest <T>(key, operationCategory, operationType, dbgInfo, (IDistributedStoreKey storeKey, bool isPrimary, StoreKind storeKind) => func(storeKey)));
 }