简体   繁体   English

无法将所有数据写入dynamodb表?

[英]Unable to write all the data into dynamodb table?

I am trying to insert csv file data into dynamodb but I am able to write only 1537 records into my dynamodb table . 我试图将CSV文件数据插入dynamodb中,但是我只能将1537条记录写入dynamodb表中。

Coding 编码

 try {

        S3EventNotificationRecord record = s3event.getRecords().get(0);
        String srcBucket = record.getS3().getBucket().getName();
        String srcKey = record.getS3().getObject().getKey().replace('+', ' ');  
        srcKey = URLDecoder.decode(srcKey, "UTF-8");
        AmazonS3 s3Client = new AmazonS3Client();
        S3Object s3Object = s3Client.getObject(new GetObjectRequest(srcBucket, srcKey));
        statusReport.setFileSize(s3Object.getObjectMetadata().getContentLength());


        BufferedReader br = new BufferedReader(new InputStreamReader(s3Object.getObjectContent())); 
        CSVReader reader = new CSVReader(br);

        AmazonDynamoDB dynamoDBClient = new AmazonDynamoDBClient();

        dynamoDBClient.setRegion(AWS_REGION);
        DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
        TableWriteItems energyDataTableWriteItems = new TableWriteItems(DYNAMO_TABLE_NAME);
        List<Item> itemList = new ArrayList<Item>();
        String[] nextLine;


        while ((nextLine = reader.readNext()) != null) {
            Item newItem = helper.parseIt(nextLine);
            itemList.add(newItem);
        }
for (List<Item> partition : Lists.partition(itemList, 25)) {
            energyDataTableWriteItems.withItemsToPut(partition);
            BatchWriteItemOutcome outcome = dynamoDB.batchWriteItem(energyDataTableWriteItems);

 do {
        Map<String, List<WriteRequest>> unprocessedItems = outcome.getUnprocessedItems();

        if (outcome.getUnprocessedItems().size() > 0) {
                    logger.log("Retrieving the unprocessed " + String.valueOf(outcome.getUnprocessedItems().size())
                            + " items.");
                    outcome = dynamoDB.batchWriteItemUnprocessed(unprocessedItems);
                }

        } while (outcome.getUnprocessedItems().size() > 0);*/
}
 logger.log("Load finish in " + String.valueOf(System.currentTimeMillis() - startTime) + "ms");

        reader.close();
        br.close();
        s3Object.close();

        statusReport.setStatus(true);
    } catch (Exception ex) {
        logger.log(ex.getMessage());
    }

    statusReport.setExecutiongTime(System.currentTimeMillis() - startTime);
    return statusReport;
}

Can I know the reason why it is behaving like this. 我能知道它为什么会这样吗? I have tried with more than 5 tables but I am getting the same result. 我尝试使用5个以上的表,但得到的结果相同。

You're probably running into a throughput limitation: 您可能会遇到吞吐量限制:

From the docs : 文档

The BatchWriteItem operation puts or deletes multiple items in one or more tables. BatchWriteItem操作在一个或多个表中放置或删除多个项目。 A single call to BatchWriteItem can write up to 16 MB of data, which can comprise as many as 25 put or delete requests. 一次调用BatchWriteItem最多可以写入16 MB的数据,其中可以包含多达25个放置或删除请求。 Individual items to be written can be as large as 400 KB. 要写入的单个项目最大可以为400 KB。

Also: 也:

If DynamoDB returns any unprocessed items, you should retry the batch operation on those items. 如果DynamoDB返回任何未处理的项目,则应在这些项目上重试批处理操作。

While you are partitioning your writes into 25-item chunks, that's not the only limitation. 在将写入内容划分为25个项目的块时,这不是唯一的限制。 If you look at the JavaDoc for BatchWriteItemOutcome you'll see the function getUnprocessedItems() . 如果您查看JavaDoc for BatchWriteItemOutcome ,将看到函数getUnprocessedItems()

Lastly, you don't show your catch block, but can we assume that it actually does something? 最后,您没有显示catch块,但是我们可以假设它确实在做什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM