Пример #1
0
        protected virtual void TaskDistribution(string serverCode, ITaskInfo taskInfo)
        {
            IEnumerator enumor = ServerManager.GetServerEnumerator();

            taskInfo.EmitServerCode = serverCode;
            if (enumor != null)
            {
                while (enumor.MoveNext())
                {
                    IServerInfo s = (IServerInfo)enumor.Current;
                    if (string.Compare(serverCode, s.ServerCode, true) != 0 && //去掉自己发给自己
                        taskInfo.EmitServerCode != s.ServerCode)     //去掉发给源服务器
                    {
                        if (s.ServerStatus == ServerStatus.Active &&
                            TaskAllocAlgFactory.GetProvider().Alloc(taskInfo, s))
                        {
                            try
                            {
                                Console.WriteLine("正在往" + s.ServerCode + "服务器分发数据");
                                ITaskRequest request     = RegisterService.TaskRequestService.GetService(s.ServerCode);
                                ITaskInfo    disTaskInfo = request.SendRequest(s.ServerCode, taskInfo);
                            }
                            catch (Exception ex)
                            {
                                s.ServerStatus = ServerStatus.Shutdown;
                                Console.WriteLine("向" + s.ServerCode + "服务器分发数据失败,异常信息为:" + ex.Message + "|" + ex.Source + "|" + ex.StackTrace);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        //分布式批量提交数据到远程
        /// <summary>
        /// 分布式批量提交数据到远程
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="isHandle"></param>
        private static void BatchSendRequest(object obj, bool isHandle)
        {
            //获取日志实体列表
            IDataBuffer buffer = obj as IDataBuffer;

            if (buffer == null)
            {
                return;
            }
            List <LogMessage> logMessageList = buffer.GetList <LogMessage>();

            if (logMessageList == null)
            {
                return;
            }

            if (m_openLogCenter)
            {
#if THRIFT
                try
                {
                    SyncLogServerEvent.WaitOne();
                    SendRequestToNewLogCenter(logMessageList);
                    if (logMessageList.Count > 1 && DateTime.Now > lastExecuteLogTime.AddMinutes(5))
                    {
                        lastExecuteLogTime = DateTime.Now;
                        string content = string.Format("本次批量插入{0}条数据,结果:{1},IsHandle:{2}", logMessageList.Count, "Success", isHandle);
                        RecordLogCenterState("分布式日志2.0", content, isHandle, true);
                    }
                    AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Success.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V2.ToString()) });
                    return;
                }
                catch (Exception ex)
                {
                    AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Failed.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V2.ToString()) });
                    m_localLog.Error(ex);
                    string content = string.Format("批量插入数据异常,原因:{0},IsHandle:{1}", ex.ToString(), isHandle);
                    RecordLogCenterState("分布式日志2.0", content, isHandle, false);
                }
#endif
            }
            else
            {
                try
                {
                    LogMessageTaskInfo taskInfo = new LogMessageTaskInfo
                    {
                        CurrLogMessageObj = logMessageList,
                        TaskCreateTime    = DateTime.Now,
                        TaskName          = "LogMessage",
                        EmitServerCode    = m_localServerCode
                    };

                    //发送日志实体列表到远程消息队列
                    ITaskInfo retTask = m_request.SendRequest(m_logToServer, taskInfo);

                    if (logMessageList.Count > 1 &&
                        DateTime.Now > lastExecuteLogTime.AddMinutes(5))
                    {
                        lastExecuteLogTime = DateTime.Now;
                        string content = string.Format("本次批量插入{0}条数据,结果:{1},IsHandle:{2}", logMessageList.Count, retTask.TaskStatus, isHandle);
                        RecordLogCenterState("分布式日志1.0", content, isHandle, retTask.TaskStatus == TaskStatus.Success);
                    }

                    if (retTask.TaskStatus == TaskStatus.Success)
                    {
#if THRIFT
                        AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Success.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V1.ToString()) });
#endif
                        return;
                    }
                }
                catch (Exception ex)
                {
#if THRIFT
                    AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Failed.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V1.ToString()) });
#endif
                    m_localLog.Error(ex);
                    string content = string.Format("批量插入数据异常,原因:{0},IsHandle:{1}", ex.ToString(), isHandle);
                    RecordLogCenterState("分布式日志1.0", content, isHandle, false);
                }
            }
            int insertResult = LogMessageDAL.GetInstance().Insert(buffer.GetEnumerator(), isHandle);
#if THRIFT
            if (insertResult > 0)
            {
                AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Success.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.Local.ToString()) });
            }
            else
            {
                AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Failed.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.Local.ToString()) });
            }
#endif
            RecordLogCenterState("本地批量保存日志", string.Format("本地批量插入{0}条数据, IsHandler: {1}", logMessageList.Count, isHandle), isHandle, false);
        }