简体   繁体   English

保存 dynamoDB 表的最佳文件格式是什么?

[英]What is the best file format to save dynamoDB table?

because I have a lot of problems with pipeline on Amazon I have decided to use java to backup my database on file.因为我在亚马逊上遇到很多管道问题,所以我决定使用 java 来备份我的数据库文件。 My table is 50GB then I need the best way to save it.我的表是 50GB,那么我需要最好的方法来保存它。 This is the java code to read elements and write them into file:这是读取元素并将其写入文件的 java 代码:

public static void fetchItems() {
    try{
        FileWriter file=new FileWriter(path);
        ScanResult result = null;
        long sum=0;
        do{
            ScanRequest req = new ScanRequest();
            req.setTableName(dataTable);

            if(result != null){
                req.setExclusiveStartKey(result.getLastEvaluatedKey());
            }

            result = dynamoDB.scan(req);
            List<Map<String, AttributeValue>> rows = result.getItems();

            for(Map<String, AttributeValue> map : rows){
                try{
                    JSONObject json=new JSONObject(map);
                    file.write(json.toString());
                } catch (NumberFormatException e){
                    System.out.println(e.getMessage());
                } catch (IOException e) {
                    System.out.println(e.getMessage());

                }
            }
            sum+= result.getItems().size();
            System.out.println("Result size: " + sum);

        } while(result.getLastEvaluatedKey() != null);
        file.flush();
        file.close();
    }catch(IOException e){
        System.out.println(e.getMessage());

What extension of file and how can i save my data?文件的扩展名是什么?如何保存我的数据? With my code the file is too big and a lot of fields are null (problems with new JSONObject(map) ), does someone has an idea?使用我的代码,文件太大,很多字段都是 null(new JSONObject(map) 的问题),有人有想法吗? In the file I find writen:在文件中我发现 writen:

{"leaseOwner":{"SS":null,"BS":null,"b":null,"s":"ip-120-115-91-22346.eu-west-1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseKey":{"SS":null,"BS":null,"b":null,"s":"shardId-000000000002","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"ownerSwitchesSinceCheckpoint":{"SS":null,"BS":null,"b":null,"s":null,"n":"0","l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"checkpoint":{"SS":null,"BS":null,"b":null,"s":"49551567310479336289724454124452290401607015400753594402","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseCounter":{"SS":null,"BS":null,"b":null,"s":88634125391 {“leaseOwner”:{“SS”:null,“BS”:null,“b”:null,“s”:“ip-120-115-91-22346.eu-west-1.compute.internal:ef5c43f7 -f5b7-49cf-99e6-8601db2922e2","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseKey" :{"SS":null,"BS":null,"b":null,"s":"shardId-000000000002","n":null,"l":null,"NS":8863418,"539188" ":null,"NULL":null,"BOOL":null},"ownerSwitchesSinceCheckpoint":{"SS":null,"BS":null,"b":null,"s":null,"n": “0”,“l”:null,“NS”:null,“m”:null,“NULL”:null,“BOOL”:null},“检查点”:{“SS”:null,“BS”: null,"b":null,"s":"49551567310479336289724454124452290401607015400753594402","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL": null},"leaseCounter":{"SS":null,"BS":null,"b":null,"s":88634125391 88,"n":"34905","l":null,"NS":null,"m":null,"NULL":null,"BOOL":null}}{"leaseOwner":{"SS":null,"BS":null,"b":null,"s":"ip-120-115-91-22346.eu-west-1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseKey":{"SS":null,"BS":null,"b":null,"s":"shardId-000000000000","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"ownerSwitchesSinceCheckpoint":{"SS":null,"BS":null,"b":null,"s":null,"n":"0","l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"checkpoint":{"SS":null,"BS":null,"b":null,"s":"49551567310434734799327392878132951190473279252744634370","n":null,"l":null,"NS":null,"m":null,"NULL":8863412539 88,“n”:“34905”,“l”:null,“NS”:null,“m”:null,“NULL”:null,“BOOL”:null}}{“leaseOwner”:{“SS” :null,“BS”:null,“b”:null,“s”:“ip-120-115-91-22346.eu-west-1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2” "n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseKey":{"SS":null," BS":null,"b":null,"s":"shardId-000000000000","n":null,"l":null,"NS":null,"m":886341213LL"886341213LL"null:886,"1886," "BOOL":null},"ownerSwitchesSinceCheckpoint":{"SS":null,"BS":null,"b":null,"s":null,"n":"0","l":null "NS":null,"m":null,"NULL":null,"BOOL":null},"检查点":{"SS":null,"BS":null,"b":null," s":"49551567310434734799327392878132951190473279252744634370","n":null,"l":null,"NS":null,"m":8861":28159NU34,"m":8861":28159NU39 188,"BOOL":null},"leaseCounter":{"SS":null,"BS":null,"b":null,"s":null,"n":"34913","l":null,"NS":null,"m":null,"NULL":null,"BOOL":null}}{"leaseOwner":{"SS":null,"BS":null,"b":null,"s":"ip-120-115-91-22346.eu-west-1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseKey":{"SS":null,"BS":null,"b":null,"s":"shardId-000000000001","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"ownerSwitchesSinceCheckpoint":{"SS":null,"BS":null,"b":null,"s":null,"n":"0","l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"checkpoint":{"SS":null,"BS":null,"b":null,"s":"49551567310457035544525923501292620796040147 188,“BOOL”:null},“leaseCounter”:{“SS”:null,“BS”:null,“b”:null,“s”:null,“n”:“34913”,“l”: null,“NS”:null,“m”:null,“NULL”:null,“BOOL”:null}}{“leaseOwner”:{“SS”:null,“BS”:null,“b1”:8586314 "s":"ip-120-115-91-22346.eu-west-1.compute.internal:ef5c43f7-f5b7-49cf-99e6-8601db2922e2","n":null,"l":null," NS":null,"m":null,"NULL":null,"BOOL":null},"leaseKey":{"SS":null,"BS":null,"b":null,"s" :"shardId-000000000001","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"ownerSwitches":{"SinceCheckpoint" SS":null,"BS":null,"b":null,"s":null,"n":"0","l":null,"NS":null,"m":null," NULL":null,"BOOL":null},"checkpoint":{"SS":null,"BS":null,"b":null,"s":"495515673104570355445259235012926201796 120590684178","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseCounter":{"SS":null,"BS":null,"b":null,"s":null,"n":"34912","l":null,"NS":null,"m":null,"NULL":null,"BOOL":null}} 120590684178","n":null,"l":null,"NS":null,"m":null,"NULL":null,"BOOL":null},"leaseCounter":{"SS":583634812 "BS":null,"b":null,"s":null,"n":"34912","l":null,"NS":null,"m":null,"NULL":83634812 “布尔”:空}}

After I will have to implement also restore application.在我还必须实施恢复应用程序之后。 Thanks谢谢

I did it with csv format which seems most concise. 我用csv格式做到了,这似乎最简洁。 the first line should contain field names (sort of like excel title) so they are not repeated every line and stil enable parsing the file. 第一行应包含字段名称(类似于excel标题),因此它们不会在每一行中重复出现,并且stil启用了文件解析功能。 null values are just adjacent commas. 空值只是相邻的逗号。

AWS recently released a DynamoDB cloud native backup to S3 feature which requires no code . AWS 最近发布了一个不需要代码的 DynamoDB 云原生备份到 S3 功能。 In the article they do mention other alternatives as well that have out of the box support for extracting data from DynamoDB into S3 but it makes the most sense to use the feature built into DynamoDB.在文章中,他们确实提到了其他替代方案,这些替代方案具有开箱即用的支持,可以将数据从 DynamoDB 提取到 S3,但使用 DynamoDB 内置的功能最有意义。

In saying that the file format will still contain the type ('S' for string, 'N' for number and so on) within the JSON object (as well as NULL data), but at least it breaks the files into smaller JSON compressed files that you can easily extract from S3.在说文件格式仍将包含 JSON object(以及 NULL 数据)中的类型('S' 表示字符串,'N' 表示数字等),但至少它将文件分解为较小的 JSON 压缩您可以轻松地从 S3 中提取的文件。

The greatest advantage of the S3 backup in DynamoDB is that you don't consume any of the read capacity units of the table so there's no chance of throttling of your table (could be dangerous in production). DynamoDB 中 S3 备份的最大优势是您不会消耗表的任何读取容量单位,因此不会限制您的表(在生产中可能很危险)。

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

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