public tb_consumer_partition_model RegisterConsumerPartition(DbConn PubConn, int clientid, int partitionindex, string mqpath, long tempid) { var mqpathmodel = GetMQPath(PubConn, mqpath); tb_mqpath_partition_dal mqpathpartitiondal = new tb_mqpath_partition_dal(); var mqpathpartitionmodel = mqpathpartitiondal.GetOfConsumer(PubConn, partitionindex, mqpathmodel.id); if (mqpathpartitionmodel == null) { return(null); } tb_consumer_partition_dal dal = new tb_consumer_partition_dal(); if (dal.Edit2(PubConn, new tb_consumer_partition_model() { consumerclientid = clientid, lastconsumertempid = tempid, partitionid = mqpathpartitionmodel.partitionid, partitionindex = partitionindex }) <= 0) { var partitionidinfo = PartitionRuleHelper.GetPartitionIDInfo(mqpathpartitionmodel.partitionid); var datanodename = PartitionRuleHelper.GetDataNodeName(partitionidinfo.DataNodePartition); long maxid = -1; DateTime serverdate = PubConn.GetServerDate(); string tablename = PartitionRuleHelper.GetTableName(partitionidinfo.TablePartition, serverdate); SqlHelper.ExcuteSql(this.GetDataNodeConnectString(PubConn, partitionidinfo.DataNodePartition), (c) => { var exist = c.TableIsExist(tablename); if (!exist) { throw new BusinessMQException(string.Format("当前数据节点{0},表{1}不存在", partitionidinfo.DataNodePartition, tablename)); } tb_messagequeue_dal mqdal = new tb_messagequeue_dal(); mqdal.TableName = tablename; maxid = mqdal.GetMaxId(c); if (maxid <= 0) { maxid = PartitionRuleHelper.GetMQID(new MQIDInfo() { AutoID = 0, DataNodePartition = partitionidinfo.DataNodePartition, Day = serverdate, TablePartition = partitionidinfo.TablePartition }); } }); dal.Add2(PubConn, new tb_consumer_partition_model() { consumerclientid = clientid, lastconsumertempid = tempid, lastmqid = maxid, partitionid = mqpathpartitionmodel.partitionid, partitionindex = partitionindex }); } return(dal.Get(PubConn, clientid, mqpathpartitionmodel.partitionid)); }
public override void Run() { ConfigHelper.LoadConfig(this.AppConfig["BusinessMQManageConnectString"]); List <tb_datanode_model> nodeList = new List <tb_datanode_model>(); using (DbConn conn = DbConfig.CreateConn(this.AppConfig["BusinessMQManageConnectString"])) { conn.Open(); List <tb_partition_model> createTimeList = new tb_consumer_dal().GetClientCreateTime(conn); var serverdate = conn.GetServerDate().Date; var timenow = conn.GetServerDate(); nodeList = new tb_datanode_dal().List(conn); List <Exception> exps = new List <Exception>(); foreach (var item in nodeList) { try { string dataNode = PartitionRuleHelper.GetDataNodeName(item.datanodepartition); string nodeConn = string.Format("server={0};Initial Catalog={1};User ID={2};Password={3};", item.serverip, dataNode, item.username, item.password); string partitionId = PartitionRuleHelper.PartitionNameRule(item.datanodepartition); string t = PartitionRuleHelper.GetDataNodeName(item.datanodepartition); using (DbConn dataNodeConn = DbConfig.CreateConn(nodeConn)) { dataNodeConn.Open(); var tablesinfo = new tb_messagequeue_dal().GetDataNodeTable(dataNodeConn, serverdate.AddDays(-30)); foreach (var table in tablesinfo) { string tablename = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetTableName(table.TablePartition, table.Day); TableInfo info = PartitionRuleHelper.GetTableInfo(tablename); var beginId = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetMQID(new MQIDInfo() { AutoID = 0, DataNodePartition = item.datanodepartition, Day = table.Day, TablePartition = table.TablePartition }); int mqPartitionId = PartitionRuleHelper.GetPartitionID(new PartitionIDInfo() { DataNodePartition = item.datanodepartition, TablePartition = table.TablePartition }); tb_partition_model timeModel = createTimeList.Where(q => q.partitionid == mqPartitionId).FirstOrDefault(); DateTime time = DateTime.Parse("2015-01-01"); if (timeModel != null) { time = timeModel.createtime; } var dal = new tb_messagequeue_dal(); dal.TableName = tablename; int count = dal.GetCount(dataNodeConn, time); long maxId = dal.GetMaxID(dataNodeConn, time); maxId = (maxId == 0 ? beginId : maxId); long minId = dal.GetMinID(dataNodeConn, time); minId = (minId == 0 ? beginId : minId); tb_partition_messagequeue_report_model model = new tb_partition_messagequeue_report_model(); model.partitionid = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetPartitionID(new PartitionIDInfo() { DataNodePartition = item.datanodepartition, TablePartition = table.TablePartition }); MQIDInfo mqInfo = PartitionRuleHelper.GetMQIDInfo(maxId); model.day = mqInfo.Day; model.lastupdatetime = timenow; model.createtime = timenow; model.mqmaxid = maxId; model.mqminid = minId; model.mqcount = count; new tb_partition_messagequeue_report_dal().AddReport(conn, model); } } } catch (Exception exp) { exps.Add(exp); } } Error(this.AppConfig["BusinessMQManageConnectString"], "消息统计出错", exps); } }
public override void Run() { List <tb_datanode_model> nodeList = new List <tb_datanode_model>(); List <tb_partition_model> list = new List <tb_partition_model>(); using (DbConn conn = DbConfig.CreateConn(this.AppConfig["BusinessMQManageConnectString"])) { conn.Open(); nodeList = dataNodeDal.List(conn); list = partitionDal.GetAllCanUsePartitionList(conn); } foreach (var item in nodeList) { string dataNode = PartitionRuleHelper.GetDataNodeName(item.datanodepartition); string nodeConn = string.Format("server={0};Initial Catalog={1};User ID={2};Password={3};", item.serverip, dataNode, item.username, item.password); try { using (DbConn dataNodeConn = DbConfig.CreateConn(nodeConn)) { dataNodeConn.Open(); foreach (var value in list) { PartitionIDInfo info = PartitionRuleHelper.GetPartitionIDInfo(value.partitionid); string partition = PartitionRuleHelper.PartitionNameRule(info.TablePartition); ICollection <string> tableList = msgDal.GetTableNameListByPartition(dataNodeConn, partition); if (tableList != null && tableList.Count > 0) { using (DbConn conn = DbConfig.CreateConn(this.AppConfig["BusinessMQManageConnectString"])) { foreach (var table in tableList) { if (!dataNodeConn.TableIsExist(table)) { continue; } long maxId = msgDal.GetMaxID(dataNodeConn, table); long minId = msgDal.GetMinID(dataNodeConn, table); tb_partition_messagequeue_report_model model = new tb_partition_messagequeue_report_model(); model.partitionid = value.partitionid; if (maxId > 0 && minId > 0) { MQIDInfo mqInfo = PartitionRuleHelper.GetMQIDInfo(maxId); model.day = mqInfo.Day; model.lastupdatetime = DateTime.Now; model.createtime = DateTime.Now; model.mqmaxid = maxId; model.mqminid = minId; reportDal.AddReport(conn, model); } } } } } } } catch (Exception ex) { base.OpenOperator.Error("节点不存在", ex); continue; } } }