Reputation: 1583
Current Setup:
I have a single namespace running on the Aerospike cluster. The namespace has few sets in it.
My Use-case:
I want to copy all the records from one set (has ~100 records) to another new set (keeping the schema same) under the same namespace.
My Finding:
I did some deep dive and found out a few solutions using aql
:
asbackup/asrestore
command.Help Needed:
Is there any efficient way to migrate data from one to another set, with less effort and validation? I did think of writing some java code that would scan the entire set and write those records into another set, but again that was falling under the first categories I explained earlier.
Thanks!
Upvotes: 3
Views: 1092
Reputation: 5415
A record in Aerospike is stored using the hash of your key and your set name. Set name is "stored" with that record in Aerospike purely as a metadata on that record. So you can scan an entire namespace and return records belonging to that set and in the scan callback, write each of them back as new records (due to the different set name). You will have to know "your key" for each record that comes back from the scan. By default Aerospike only stores the 20byte hash digest as the key for the record. So unless you stored it explicitly in the record either with send key true or in a bin, I don't see how you would identify "your key". Storing "your key" in a bin is easiest. You may have to first update all your 100 records and add a bin that has "your key" in it. Then in scan callback, where records come in no particular order, you will be able to compose a new Key with "your key" and "new set name". You will have to write your own java code for it. (If you have "your key" in the original records - its easy to do.)
I have not tested this .. but something along these lines would work assuming original records had your key in the "mykey" bin.
client.scanAll(null, "test", "set1", new ScanCallback(){
public void scanCallback (Key key, Record record) throws AerospikeException {
String mykey = (String)(record.getValue("mykey"));
String bin1data = record.getString("bin1");
//Alternate way to get string
Key reckey = new Key("test", "set2", mykey);
client.put(null, reckey, new Bin("bin1", bin1data));
}
});
Upvotes: 3