Ejemplo n.º 1
0
        /// <summary>
        /// 当前数据库是否被Mark Down了,如果在Pre Mark Up阶段,且当前请求满足放行条件,则仍然返回false
        /// </summary>
        /// <param name="allInOneKey"></param>
        /// <returns></returns>
        public static Boolean DatabaseMarkedDown(String allInOneKey, String logicDbName)
        {
            if (markDownDatabases.ContainsKey(allInOneKey))
            {
                lock (lockObj)
                {
                    if (markDownDatabases.ContainsKey(allInOneKey))
                    {
                        if (markingUpDatabases.ContainsKey(allInOneKey) && (markingUpDatabases[allInOneKey].PreMarkUp ||
                                                                            (DateTime.Now - markingUpDatabases[allInOneKey].MarkDownTime).TotalSeconds >= markdownBean.AutoMarkUpDelay))
                        {
                            if (!markdownBean.EnableAutoMarkDown || markdownBean.AutoMarkUpBatches <= 0)
                            {
                                var markupMetrics = new MarkUpMetrics()
                                {
                                    AllInOneKey  = allInOneKey,
                                    Batches      = markdownBean.AutoMarkUpBatches,
                                    MarkUpDelay  = markdownBean.AutoMarkUpDelay,
                                    SuccessCount = 0,
                                    Success      = true
                                };

                                LogManager.Logger.MetricsMarkup(markupMetrics);
                                markDownDatabases.Remove(allInOneKey);
                                markingUpDatabases.Remove(allInOneKey);
                                return(false);
                            }
                            markingUpDatabases[allInOneKey].PreMarkUp = true;
                            try
                            {
                                //Let it pass
                                if (markingUpDatabases[allInOneKey].MarkUpArray[markingUpDatabases[allInOneKey].CurrentMarkUpIndex])
                                {
                                    return(false);
                                }
                            }
                            finally
                            {
                                //一轮放量结束,进入下一轮放量
                                if (markingUpDatabases[allInOneKey].CurrentMarkUpIndex >= (Constants.MarkUpReferCount - 1) &&
                                    markingUpDatabases[allInOneKey].CurrentBatch <= markdownBean.AutoMarkUpBatches)
                                {
                                    markingUpDatabases[allInOneKey].CurrentBatch++;
                                }
                                markingUpDatabases[allInOneKey].CurrentMarkUpIndex = (markingUpDatabases[allInOneKey].CurrentMarkUpIndex + 1) % Constants.MarkUpReferCount;
                            }
                        }
                        return(markDownDatabases.ContainsKey(allInOneKey) && markDownDatabases[allInOneKey] != MarkDownEnums.FakeAutoMarkDown);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static void AutoMarkUpMonitor(String allInOneKey, Boolean isAbnormalException)
        {
            if (markingUpDatabases.ContainsKey(allInOneKey) && markdownBean.AutoMarkUpBatches > 0)
            {
                lock (lockObj)
                {
                    if (markingUpDatabases.ContainsKey(allInOneKey) && markdownBean.AutoMarkUpBatches > 0)
                    {
                        if (isAbnormalException)
                        {
                            markingUpDatabases[allInOneKey].MarkUpFail[markingUpDatabases[allInOneKey].CurrentMarkUpSchedule]++;
                        }
                        else
                        {
                            markingUpDatabases[allInOneKey].MarkUpSuccess[markingUpDatabases[allInOneKey].CurrentMarkUpSchedule]++;
                        }

                        if (markingUpDatabases[allInOneKey].CurrentBatch > markdownBean.AutoMarkUpBatches)
                        {
                            markingUpDatabases[allInOneKey].CurrentBatch = 1;
                            //Pre Mark Up已经结束,如果监控到的状态良好,则取消Mark Down,否则回到上个阶段,并清空Pre Mark Up的记录
                            if (markingUpDatabases[allInOneKey].MarkUpFail[markingUpDatabases[allInOneKey].CurrentMarkUpSchedule] > 0)
                            {
                                markingUpDatabases[allInOneKey].PreMarkUp    = false;
                                markingUpDatabases[allInOneKey].MarkDownTime = DateTime.Now;
                                var markupMetrics = new MarkUpMetrics()
                                {
                                    AllInOneKey  = allInOneKey,
                                    Batches      = markdownBean.AutoMarkUpBatches,
                                    MarkUpDelay  = markdownBean.AutoMarkUpDelay,
                                    SuccessCount = markingUpDatabases[allInOneKey].MarkUpSuccess.Sum(),
                                    Success      = false
                                };

                                LogManager.Logger.MetricsMarkup(markupMetrics);
                                markingUpDatabases[allInOneKey].MarkUpSuccess[markingUpDatabases[allInOneKey].CurrentMarkUpSchedule] = 0;
                                markingUpDatabases[allInOneKey].MarkUpFail[markingUpDatabases[allInOneKey].CurrentMarkUpSchedule]    = 0;
                                if (markingUpDatabases[allInOneKey].CurrentMarkUpSchedule > 0)
                                {
                                    markingUpDatabases[allInOneKey].CurrentMarkUpSchedule--;
                                }
                            }
                            else
                            {
                                //如果部分完成,进入下一阶段
                                if (markingUpDatabases[allInOneKey].MarkUpSchedules.Length - 1 > markingUpDatabases[allInOneKey].CurrentMarkUpSchedule)
                                {
                                    markingUpDatabases[allInOneKey].CurrentMarkUpSchedule++;
                                    markingUpDatabases[allInOneKey].MarkUpArray        = MarkUpInfo.InitMarkUpArray(markingUpDatabases[allInOneKey].MarkUpSchedules[markingUpDatabases[allInOneKey].CurrentMarkUpSchedule]);
                                    markingUpDatabases[allInOneKey].CurrentMarkUpIndex = 0;
                                }
                                else
                                {
                                    var markupMetrics = new MarkUpMetrics()
                                    {
                                        AllInOneKey  = allInOneKey,
                                        Batches      = markdownBean.AutoMarkUpBatches,
                                        MarkUpDelay  = markdownBean.AutoMarkUpDelay,
                                        SuccessCount = markingUpDatabases[allInOneKey].MarkUpSuccess.Sum(),
                                        Success      = true
                                    };

                                    LogManager.Logger.MetricsMarkup(markupMetrics);
                                    //如果全部状态已完成,移除Mark Down数据库,情况Mark Up监控
                                    markDownDatabases.Remove(allInOneKey);
                                    markingUpDatabases.Remove(allInOneKey);
                                }
                            }
                        }
                    }
                }
            }
        }