Beispiel #1
0
        private void CheckIfScanNewTable(tb_consumer_partition_model partition, MQIDInfo mqidinfo, string datanodeconnectstring, PartitionIDInfo partionidinfo)
        {
            var serverdate = Context.ManageServerTime.AddSeconds(-1);      //此处延迟1秒,停顿消费者日分区表之间的切换

            if (serverdate != null && serverdate.Date > mqidinfo.Day.Date) //服务器时间和消息时间对应不上
            {
                SqlHelper.ExcuteSql(datanodeconnectstring, (c) =>
                {
                    DateTime t = mqidinfo.Day.Date.AddDays(1);
                    while (serverdate.Date >= t)    //查找最后的可用消息表,然后跳出
                    {
                        string tablename = PartitionRuleHelper.GetTableName(partionidinfo.TablePartition, t);
                        if (exsittablenames.ContainsKey(tablename) || c.TableIsExist(tablename))
                        {
                            AddExsitTableNameCache(tablename);
                            _lastpullququeiddic[partition.partitionid] = PartitionRuleHelper.GetMQID(new MQIDInfo()
                            {
                                AutoID            = 0,
                                DataNodePartition = mqidinfo.DataNodePartition,
                                TablePartition    = mqidinfo.TablePartition,
                                Day = t
                            });    //重设第二天最小的id
                            break;
                        }

                        t = t.AddDays(1);
                    }
                });
            }
        }
Beispiel #2
0
        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));
        }