Cosmos DB out of Memory exception while executing stored procedure

六月ゝ 毕业季﹏ 提交于 2019-12-10 12:06:36

问题


I am using Azure Cosmos DB SQL API . I have written stored procedure will get the data and keeps in response API feed .

Failed to execute stored procedure testProcedure for collection iotcollection: {"code":400,"body":"{\"code\":\"BadRequest\",\"message\":\"Message: {\\"Errors\\":[\\"Encountered exception while executing function. Exception = Error: Out of memory\\r\\nStack trace: undefined\\"]}\r\nActivityId: c286cbb6-34c1-4929-a148-915544b20ce6, Request URI: /apps/59d3b9ef-17ca-4bbf-8a11-39d0199a8d29/services/1b26e00f-1f51-4d34-88ec-4090b8e7db00/partitions/45a313b7-2cf2-419e-9885-48bf9cfe6277/replicas/131862936473830809p/, RequestStats: \r\nRequestStartTime: 2018-11-10T05:46:36.4852333Z, Number of regions attempted: 1\r\n, SDK: Microsoft.Azure.Documents.Common/2.1.0.0\"}","activityId":"c286cbb6-34c1-4929-a148-915544b20ce6"}

My stored procedure is very simple one I just wanted to see how many records i can fetch from cosmos DB at given time and send as response.

    // SAMPLE STORED PROCEDURE
function sample(prefix) {
    var collection = getContext().getCollection();

    // Query documents and take 1st item.
    var isAccepted = collection.queryDocuments(
        collection.getSelfLink(),
        'SELECT r.data FROM root r',
    function (err, feed, options) {
        if (err) throw err;

        // Check the feed and if empty, set the body to 'no docs found', 
        // else take 1st element from feed
        if (!feed || !feed.length) {
            var response = getContext().getResponse();
            response.setBody('no docs found');
        }
        else {
            var response = getContext().getResponse();
            var body = { prefix: prefix, feed: feed[0] };
            var str = 'str';
            for ( var i =0 ; i < 100 ; i = i +1 ){
                    str = str + str ;
                    body .str = feed[0];
            }

            response.setBody(JSON.stringify(body));
        }
    });

    if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

回答1:


I'm sure the reason of Out-Of-Memoryerror is the str string is too long during your loop. It seems that the str string is useless for your test which is not added into response.

Please remove it and the sample stored procedure will work fine.



来源:https://stackoverflow.com/questions/53236362/cosmos-db-out-of-memory-exception-while-executing-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!