Exemple #1
0
        public virtual bool Add(DbConn PubConn, tb_partition_model model)
        {
            List<ProcedureParameter> Par = new List<ProcedureParameter>()
                {

                    //�Ƿ���ʹ��
                    new ProcedureParameter("@isused",    model.isused),
                    //����ʱ��(�Ե�ǰ��ʱ��Ϊ׼)
                    new ProcedureParameter("@createtime",    model.createtime)
                };
            int rev = PubConn.ExecuteSql(@"insert into tb_partition(isused,createtime)
                                           values(@isused,@createtime)", Par);
            return rev == 1;
        }
Exemple #2
0
        public virtual bool Edit(DbConn PubConn, tb_partition_model model)
        {
            List<ProcedureParameter> Par = new List<ProcedureParameter>()
            {

                    //�Ƿ���ʹ��
                    new ProcedureParameter("@isused",    model.isused),
                    //����ʱ��(�Ե�ǰ��ʱ��Ϊ׼)
                    new ProcedureParameter("@createtime",    model.createtime)
            };
            Par.Add(new ProcedureParameter("@partitionid",  model.partitionid));

            int rev = PubConn.ExecuteSql("update tb_partition set isused=@isused,createtime=@createtime where partitionid=@partitionid", Par);
            return rev == 1;
        }
Exemple #3
0
 public ActionResult Add(int nodeid,int count)
 {
     try
     {
         using (DbConn conn = DbConfig.CreateConn(DataConfig.MqManage))
         {
             conn.Open();
             try
             {
                 conn.BeginTransaction();
                 int r = 0;
                 var partitons = new tb_partition_dal().GetPageList(conn, "", nodeid, -1, 1, 100, ref r);
                 List<int> usedpartitionids = new List<int>();
                 foreach (var d in partitons)
                 {
                     if (!usedpartitionids.Contains(d.partitionid))
                         usedpartitionids.Add(d.partitionid);
                 }
                 List<int> canusepartitionids = new List<int>();
                 for (var i = 1; i < 100; i++)
                 {
                     var partition = XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionRuleHelper.GetPartitionID(new XXF.BaseService.MessageQuque.BusinessMQ.SystemRuntime.PartitionIDInfo() { DataNodePartition = nodeid, TablePartition =i  });
                     if (!usedpartitionids.Contains(partition))
                         canusepartitionids.Add(partition);
                 }
                 for (int i = 0; i < count; i++)
                 {
                     tb_partition_model model = new tb_partition_model();
                     model.isused = false;
                     model.partitionid = canusepartitionids[i];
                     dal.AddPartition(conn, model);
                 }
                 conn.Commit();
             }
             catch (Exception exp)
             {
                 conn.Rollback();
                 throw exp;
             }
         }
         return RedirectToAction("index", new { nodeId = nodeid });
     }
     catch (Exception exp)
     {
         ModelState.AddModelError("Error","添加失败"+ exp.Message);
         return View();
     }
 }
Exemple #4
0
 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);
 }
Exemple #5
0
        public virtual tb_partition_model CreateModel(DataRow dr)
        {
            var o = new tb_partition_model();

            //����id��,����1+���ݽڵ���+��������
            if(dr.Table.Columns.Contains("partitionid"))
            {
                o.partitionid = dr["partitionid"].Toint();
            }
            //�Ƿ���ʹ��
            if(dr.Table.Columns.Contains("isused"))
            {
                o.isused = dr["isused"].Tobool();
            }
            //����ʱ��(�Ե�ǰ��ʱ��Ϊ׼)
            if(dr.Table.Columns.Contains("createtime"))
            {
                o.createtime = dr["createtime"].ToDateTime();
            }
            return o;
        }
Exemple #6
0
 private long StartMoveMQID(string fromtablename, PartitionIDInfo info, Dictionary<int, tb_datanode_model> datanodemodels, tb_partition_model p, DateTime tabletime)
 {
     long r = -1;
     SqlHelper.ExcuteSql(this.GetDataNodeConnectString(datanodemodels[info.DataNodePartition]), (c) =>
     {
         bool exsit = c.TableIsExist(fromtablename);
         if (exsit == true)
         {
             tb_messagequeue_dal dal = new tb_messagequeue_dal(); dal.TableName = fromtablename;
             long maxid = dal.GetMaxID(c); long minid = dal.GetMinID(c);
             int findcount = 0;
             while (findcount<=30)//二分查找算法,超过30次意味着算法若对,查询过一亿的数据,说明算法有问题
             {
                 findcount++;
                 KeyValuePair<long, DateTime> mininfo = dal.GetIDCreateTime(c, minid); KeyValuePair<long, DateTime> maxinfo = dal.GetIDCreateTime(c, maxid);
                 if (mininfo.Value.Date <= tabletime.Date && maxinfo.Value.Date > tabletime.Date)//最小id小于等于当天,最大id>当天,说明中间有数据要迁移
                 {
                     var midid = (long)((maxinfo.Key + mininfo.Key) / 2); KeyValuePair<long, DateTime> midinfo = dal.GetIDCreateTime(c, midid);
                     if (midinfo.Value.Date <= tabletime.Date)//往大的查找
                     {
                         minid = midid;
                     }
                     else//往小的查找
                     {
                         maxid = minid;
                     }
                     System.Threading.Thread.Sleep(50);//避免给数据库大的压力
                 }
                 else if (mininfo.Value.Date > tabletime.Date)//最小id的时间超过表当天
                 {
                     r = mininfo.Key; return;
                 }
                 else if (maxinfo.Value.Date <= tabletime.Date)//最大id的时间小于或等同当天
                 {
                     r = maxinfo.Key; return;
                 }
             }
             if (findcount >= 30)
                 throw new Exception("二分查找算法错误,查找次数超过30次");
         }
     });
     return r;
 }
Exemple #7
0
 public List<tb_partition_model> GetClientCreateTime(DbConn conn)
 {
     try
     {
         List<tb_partition_model> list = new List<tb_partition_model>();
         string sql = @"select partitionid,clientname,tb_consumer_partition.createtime from tb_consumer_partition,[tb_consumer]  WITH(NOLOCK)
                         where [tb_consumer].tempid=tb_consumer_partition.lastconsumertempid";
         DataTable dt = conn.SqlToDataTable(sql, null);
         if (dt != null && dt.Rows.Count > 0)
         {
             foreach (DataRow dr in dt.Rows)
             {
                 tb_partition_model model = new tb_partition_model();
                 model.partitionid = Convert.ToInt32(dr["partitionid"]);
                 model.createtime = Convert.ToDateTime(dr["createtime"]);
                 list.Add(model);
             }
         }
         return list;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }