春の「ソート超えメモリー制限」MongoDBを通報

ペドロ・エンリケ:

私は、私は、Java /春のプロジェクトでの集約を使用していますが、私がテストしていたときに、それを超えたメモリ制限を与えている、MongoRepositoryを使用してクエリを実装する方法を書いています。

私が使用することを試してみました

newAggregationOptions().cursorBatchSize(pageable.getPageSize()).allowDiskUse(true).build()

しかし、うまくいきませんでした

私の方法:

...
        var matchCriteria = match(criteria);

        var unwindVariations = unwind("variations", false);


        var sort = sort(Sort.Direction.ASC, "variations.plataformStatus.status");

        var countResult = count().as("totalElements");
        var aggregationOptions = Aggregation.newAggregationOptions().cursorBatchSize(pageable.getPageSize()).allowDiskUse(true).build();

        var countAggregation = newAggregation(
                matchCriteria,
                unwindVariations,
                sort,
                countResult)
                .withOptions(aggregationOptions);

        var totalElements = mongoTemplate.aggregate(countAggregation, "PRODUCT", Map.class).getMappedResults();


エラーメッセージ:

com.mongodb.MongoCommandException: Command failed with error 16819 (Location16819): 'Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.' on server cluster0-shard-00-01-du380.mongodb.net:27017.
ゴンサロMatheu:

あなたは有効にする必要がありallowDiskUseのオプションを選択します。

デフォルトでは、ソート操作は、大きいサイズを使用できるようになりますあなたの操作でそのオプションを有効にする、(メモリ内の)100MBの制限があります。

以下からのMongoDBのソートドキュメント

$ソート段階ではRAMの100メガバイトの制限があります。ステージは、この制限を超えた場合、デフォルトで、$ソートはエラーを生成します。大規模なデータセットの処理を可能にするため、一時ファイルへの書き込みに$ソート操作を有効にするにはtrueにallowDiskUseオプションを設定します。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=214234&siteId=1