2017-09-13 115 views
0

我寫了bulkInsert的存儲過程,我也在處理SP的超時。仍然在執行SP時出現「請求大小過大」異常。低於SP。請幫助我,我錯了。我只採用了來自複數光視的所有代碼。並像他們一樣以相同的方式處理。請求大小太大

function spBulkInsert(docs){ 
    if (!docs) { 
     throw new Error('Documents array is null or not defined!'); 
    } 
    var context = getContext(); 
    var collection = context.getCollection(); 
    var response = context.getResponse(); 

    var docCount = docs.length; 

    if (docCount == 0) { 
     response.setBody(0); 
     return; 
    } 
    var count = 0; 
    createDoc(docs[0]); 

    function createDoc(doc) { 
     var isAccepted = collection.createDoucument(collection.getSelfLink(), doc, docCreated); 
     if (!isAccepted) { 
      response.setBody(count); 
     } 
    } 
    function docCreated(err, doc) { 
     if (err) throw err; 
     count++; 
     if (count == docCount) response.setBody(count); 
     else createDoc(docs[count]); 
    } 
}; 

代碼,用於處理上述SP:

var totalInsertedCount=0; 
       while (totalInsertedCount < data.Count) 
       { 
        var insertedCount = await client.ExecuteStoredProcedureAsync<int>(
              UriFactory.CreateStoredProcedureUri("TestDoc", "coll", "spBulkInsert"), 
              new RequestOptions { PartitionKey = new PartitionKey("partitionKey") }, data); 
        totalInsertedCount += insertedCount; 
        Console.WriteLine("Inserted {0} documents ({1} total, {2} remaining)", insertedCount, totalInsertedCount, data.Count - totalInsertedCount); 
        data= data.GetRange(insertedCount, data.Count - insertedCount); 
       } 
+0

你有多少數據傳遞給您的存儲過程?沒有更多細節,很難知道錯誤的原因。請相應地編輯您的問題。 –

+0

是的!我傳遞的數據大於2MB。但是在SP中,我正在處理isAccepted變量。另外,我也可以共享SP處理代碼。 – Shraddha

+0

@Shraddha您好,Shraddha。請確保每個文檔的大小不超過2MB。根據我的經驗,您的錯誤是由於bulkimport一次執行的過多數據造成的。請求超時並且SDK將自動回滾並重試。 Howerver,在你的代碼中,我建議你削減數據以導入並手動重試異常而不改變吞吐量。 –

回答

0

就像總結,The document size in the request exceeded the allowable document size for a request. The max allowable document size is 2MB.裏面提到here

Stored Procedure Bulk importing data是一個執行存儲過程的過程,僅僅是一個HTTP請求,並且每個HTTP請求所請求文檔的大小受到Cosmos DB低於2MB的限制。

建議

1.You可以分割你的文檔數據,並批量導入。

2.You可以嘗試簡化您的文檔數據,如去除不必要的「」和「\ n」等

0

無論在何處發生的寫入(SP或API或在門戶)總有2MB不限於以宇宙DB文檔尺寸的。提交給Cosmos數據庫之前,必須在客戶端對文件進行拆分/鏈接/鏈接/等。