2013-01-01 43 views
0

我正在編寫一個查詢以將300k行插入到表中,執行插入操作時出現404文件或目錄未找到錯誤。我是一個小白天青,所以我可能已經寫了一些愚蠢的代碼Azure表存儲:執行插入期間出現的錯誤

我創建DynamicTableEntity對象的位置:

 Test t = new Test(); 
     t.CreateTable("table2"); 
     Dictionary<string, EntityProperty> dic; 
     Random random = new Random(); 

     ArrayList part1 = new ArrayList(); 
     ArrayList part2 = new ArrayList(); 
     ArrayList part3 = new ArrayList(); 
     ArrayList part4 = new ArrayList(); 
     ArrayList part5 = new ArrayList(); 
     ArrayList part6 = new ArrayList(); 
     DynamicTableEntity dte; 
     Stopwatch sw = new Stopwatch(); 
     Guid guid; 
     sw.Start(); 
     for (int i = 0; i < 300000; i++) 
     { 

      dic = new Dictionary<string, EntityProperty>(); 

      dic.Add("count", new EntityProperty(i)); 
      dic.Add("rand1", new EntityProperty(random.Next())); 
      dic.Add("rand2", new EntityProperty(random.Next())); 
      dic.Add("rand3", new EntityProperty(random.Next())); 
      if(i!=5) 
      dic.Add("rand4", new EntityProperty(random.Next())); 
      else 
       dic.Add("rand4", new EntityProperty(1234561)); 


      if (i % 2 == 0) 

       dic.Add("randInt", new EntityProperty(random.Next())); 
      else 
       dic.Add("String", new EntityProperty("This is a string" + i)); 

      guid = Guid.NewGuid(); 

      dte = new DynamicTableEntity("0" + (i % 3), DateTime.UtcNow.Ticks.ToString() + guid + i); 

      dte.Properties = dic; 

      if (i % 6 == 0) 
       part1.Add(dte); 
      else if (i % 6 == 1) 
       part2.Add(dte); 
      else if(i%6==2) 
       part3.Add(dte); 
      else if (i % 6 == 3) 
       part4.Add(dte); 
      else if (i % 6 == 4) 
       part5.Add(dte); 
      else if (i % 6 == 5) 
       part6.Add(dte); 


      if((i + 1) % 600 == 0) 
      { 

       t.Insert("table2", part1, part2, part3, part4, part5, part6); 
       part1.RemoveRange(0,100); 
       part2.RemoveRange(0, 100); 
       part3.RemoveRange(0, 100); 
       part4.RemoveRange(0, 100); 
       part5.RemoveRange(0, 100); 
       part6.RemoveRange(0, 100); 
      } 



     } 

,這裏是插入執行代碼:

 CloudTable table = _tableClient.GetTableReference(tableName); 
     TableBatchOperation tablebatchoperation; 
     int i = 0, j = 0; 
     if (created == false) 
      table.CreateIfNotExists(); 

     foreach (ArrayList k in l) 
     { 
      tablebatchoperation = new TableBatchOperation(); 

      foreach (DynamicTableEntity dte in k) 
      { 
       tablebatchoperation.Insert(dte); 
      } 
      table.ExecuteBatch(tablebatchoperation); 
     } 

我很欣賞你幫助

回答

1

我在這裏看到的一個可能的問題是,您正在執行包含超過100個項目的批處理操作。嘗試這樣的事情(代碼不優化,但你會得到的圖片):

foreach (ArrayList k in l) 
    { 
     foreach (DynamicTableEntity dte in k) 
     { 
      if (tablebatchoperation == null) 
       tablebatchoperation = new TableBatchOperation(); 
      tablebatchoperation.Insert(dte); 
      if (tablebatchoperation.Count == 100) 
      { 
       table.ExecuteBatch(tablebatchoperation); 
       tablebatchoperation = new TableBatchOperation(); 
      } 
     } 
    } 

    if (tablebatchoperation.Count > 0) 
     table.ExecuteBatch(tablebatchoperation); 

也請記住,在一個單一的間歇操作的所有實體應該是相同的分區的一部分。你在哪裏設置分區和rowkey?

相關問題