Aerospike BatchRead Api 查找响应记录的源/原始集

问题描述 投票:0回答:1

Aerospike Batch read api 采用一组集合作为输入,如下所示:

        final Key[] keys1 = new Key[3];
        keys1[0] = new Key(config.getNamespace(), config.getSetName(1)), key);
        keys1[1] = new Key(config.getNamespace(), config.getSetName(2)), key);
        keys1[2] = new Key(config.getNamespace(), config.getSetName(3)), key);

并以记录数组 (Record[3]) 的形式返回响应,如果所有 3 个集合都包含该键,则 recordList 中同一集合的元素按正确的顺序排列。

如果其中一个集合没有密钥,那么我会得到 Record[2] 的响应,并且无法将元素与原始集合联系起来。

有办法解决这个问题吗?我的集合每小时/每天分组。我只想对 aerospike 进行一次调用,并且能够区分数据集之间的数据。

我不想创建复合键(大量键:10^9),也无法创建多个命名空间,因为查询可能会变得昂贵。

aerospike aerospike-ce
1个回答
0
投票

我注意到你要求我发表评论。我在 Jupyter Notebook 中模拟了你的问题。让我发布相关的代码段。

Key key1 = new Key("test", "testSet1", 1); 
Key key2 = new Key("test", "testSet2", 2);  // We will not create this record 
Key key3 = new Key("test", "testSet3", 3); 
Key key4 = new Key("test", "testSet4", 4);
Bin b1 = new Bin("bin1", 100);
Bin b2 = new Bin("bin1", 200);
Bin b3 = new Bin("bin1", 300);
Bin b4 = new Bin("bin1", 400);
client.put(null, key1, b1);
//client.put(null, key2, b2); //Skipping so its a null record
client.put(null, key3, b3);
client.put(null, key4, b4);

这会在键 key1、key3 和 key4 处创建 3 条记录。现在让我们进行批量读取:

BatchPolicy batchPolicy = new BatchPolicy();    
Record [] bReads = client.get(batchPolicy, new Key[] {key1, key2, key3, key4});    
// process the batch reads
for (int i = 0; i < bReads.length; i++) {
    Record bRead = bReads[i];    
    if (bRead != null) {          // check individual record
        long bin1Val = bRead.getLong("bin1");         
        System.out.format("Result[%d]: bin1: %d\n",i, bin1Val);
    }
    else {   // error in individual key's operations
        System.out.format("Result[%d]: not found: \n", i);
    }
}

输出是:

Result[0]: bin1: 100
Result[1]: not found: 
Result[2]: bin1: 300
Result[3]: bin1: 400
© www.soinside.com 2019 - 2024. All rights reserved.