private void MoveDataToToday(DateTime fromdate, DateTime serverdate, tb_partition_model p, Dictionary <int, tb_datanode_model> datanodemodels)
        {
            var partitioninfo    = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetPartitionIDInfo(p.partitionid);
            var fromtablename    = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetTableName(partitioninfo.TablePartition, fromdate);
            var currenttablename = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetTableName(partitioninfo.TablePartition, serverdate);
            //二分法查找起始点
            long startmovemqid = StartMoveMQID(fromtablename, partitioninfo, datanodemodels, p, fromdate);

            if (startmovemqid <= -1)
            {
                return;
            }
            //为了解决可能出现的并发插入,网络极度延迟可能导致的数据顺序乱掉,起始点再往前追溯1000条
            startmovemqid = startmovemqid - 1000;
            if (startmovemqid <= 0)
            {
                startmovemqid = 1;
            }
            //从起始点开始批量扫描
            tb_messagequeue_dal dal = new tb_messagequeue_dal(); dal.TableName = fromtablename; var moveMessages = new List <tb_messagequeue_model>();

            do
            {
                SqlHelper.ExcuteSql(this.GetDataNodeConnectString(datanodemodels[partitioninfo.DataNodePartition]), (c) =>
                {
                    moveMessages = dal.GetListMoreThanID(c, 1000, startmovemqid);
                });
                //对每条数据进行逐条迁移
                foreach (var message in moveMessages)
                {
                    startmovemqid = Math.Max(startmovemqid, message.id);//起始id自增
                    if (message.sqlcreatetime.Date > fromdate.Date && message.state == (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMessageState.CanRead)
                    {
                        SqlHelper.ExcuteSql(this.GetDataNodeConnectString(datanodemodels[partitioninfo.DataNodePartition]), (c) =>
                        {
                            tb_messagequeue_dal fromdal = new tb_messagequeue_dal(); fromdal.TableName = fromtablename;
                            tb_messagequeue_dal todal   = new tb_messagequeue_dal(); todal.TableName = currenttablename;
                            todal.AddMove(c, new tb_messagequeue_model()
                            {
                                message      = message.message,
                                state        = (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMessageState.CanRead,
                                mqcreatetime = message.mqcreatetime, source = (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMessageSource.Moved
                            });                                                                                                                  //迁移到最新使用表
                            fromdal.SetState(c, message.id, (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMessageState.Moved); //原消息设置为已迁移
                        });
                    }
                }
            } while (moveMessages.Count > 0);
        }
Ejemplo n.º 2
0
 public ActionResult Delete(long id, string node)
 {
     using (DbConn conn = DbConfig.CreateConn(DataConfig.DataNodeParConn(node)))
     {
         conn.Open();
         var    mqidinfo  = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetMQIDInfo(Convert.ToInt64(id));
         string tablename = PartitionRuleHelper.GetTableName(mqidinfo.TablePartition, mqidinfo.Day);
         var    dal       = new tb_messagequeue_dal(); dal.TableName = tablename;
         if (dal.SetState(conn, id, (byte)XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.EnumMessageState.Deleted))
         {
             return(Json(new { code = 1, msg = "删除成功" }));
         }
         return(Json(new { code = -1, msg = "删除失败" }));
     }
 }