3

私のLDT(LargeMap)ビンに次の値があるとします。

key1, value1   
key2, value2   
key3, value3   
key4, value4   
. .   
key50, value50

ここで、次のスニペットを使用して必要なデータを取得します。

Map<?, ?> myFinalRecord = new HashMap<?, ?>();
// First call to client to get the largeMap associated with the bin
LargeMap largeMap = myDemoClient.getLargeMap(myPolicy, myKey, myLDTBinName, null);

for (String myLDTKey : myRequiredKeysFromLDTBin) {
    try {
        // Here each get call results in one call to aerospike
        myFinalRecord.putAll(largeMap.get(Value.get(myLDTKey)));
    } catch (Exception e) {
        log.warn("Key does not exist in LDT Bin");
    }
}

問題は、myRequiredKeysFromLDTBinたとえば 20 個のキーが含まれている場合です。次にlargeMap.get(Value.get(myLDTKey))、aerospike に対して 20 回の呼び出しを行います。

したがって、トランザクションごとに 1 ミリ秒の取得時間を使用すると、レコードから 20 個の ID を取得するための 1 回の呼び出しで、aerospike への 20 回の呼び出しが発生します。これにより、応答時間が約 1 時間長くなります。20ミリ秒

LDT Bin から取得する一連の ID を渡すだけで、1 回の呼び出しで済む方法はありますか?

4

1 に答える 1

4

マルチ取得を行うための直接的な API はありません。これを行う方法は、UDF を介してサーバーから直接 lmap API を複数回呼び出すことです。

例 「mymap.lua」

local lmap = require('ldt/lib_lmap');
function getmany(rec, binname, keys)
    local resultmap = map()
    local keycount  = #keys
    for i = 1,keycount,1 do
        local rc = lmap.exists(rec, binname, keys[i])
        if (rc == 1) then
            resultmap[keys[i]] = lmap.get(rec, binname, keys[i]);
        else
            resultmap[keys[i]] = nil;
        end
    end
    return resultmap;
end

この lua ファイルを登録します

aql> register module 'mymap.lua'
OK, 1 module added.

aql> execute lmap.put('bin', 'c', 'd') on test.demo where PK='1'
+-----+
| put |
+-----+
| 0   |
+-----+
1 row in set (0.000 secs)

aql> execute lmap.put('bin', 'b', 'c') on test.demo where PK='1'
+-----+
| put |
+-----+
| 0   |
+-----+
1 row in set (0.001 secs)

aql> execute mymap.getmany('bin', 'JSON["b","a"]') on test.demo where PK='1'
+--------------------------+
| getmany                  |
+--------------------------+
| {"a":NIL, "b":{"b":"c"}} |
+--------------------------+
1 row in set (0.000 secs)

aql> execute mymap.getmany('bin', 'JSON["b","c"]') on test.demo where PK='1'
+--------------------------------+
| getmany                        |
+--------------------------------+
| {"b":{"b":"c"}, "c":{"c":"d"}} |
+--------------------------------+
1 row in set (0.000 secs)

これを呼び出す Java コードは次のようになります。

 try {
     resultmap = myClient.execute(myPolicy, myKey, 'mymap', 'getmany', Value.get(myLDTBinName), Value.getAsList(myRequiredKeysFromLDTBin)
 } catch (Exception e) {
    log.warn("One of the key does not exist in LDT bin");
 }

キーが存在する場合は値が設定され、存在しない場合は NIL が返されます。

于 2014-12-11T11:25:45.597 に答える