Save load and reset dapp::multi_index data
To enable these features, you must include the advanced multi index with: #define USE_ADVANCED_IPFS at the top of the contract file. If you have already deployed a contract that does not use advanced features, do not add this line, as it is not backwards compatible.
With that, you now have the ability to save the list of shards currently being used to represent the table’s current state. With the saved snapshot, a developer can upload it to another contract, or version the snapshot and save it to be loaded to the contract later. This adds much needed flexibility to maintaining database state in a vRAM table.

Save dapp::multi_index data

Using zeus, a backup file can be created with the following command:
1
zeus backup-table <CONTRACT> <TABLE>
2
​
3
# optional flags:
4
​
5
--endpoint # endpoint of node
6
# default: localhost:13115
7
--output # output file name
8
# default: vram-backup-${CONTRACT}-${TABLE}-0-1578405972.json
9
​
10
# example
11
zeus backup-table lqdportfolio users --endpoint=http://kylin-dsp-2.liquidapps.io/
Copied!
Example: vram-backup-lqdportfolio-users-0-1578405972.json
1
{
2
"contract": "lqdportfolio",
3
"table": "users",
4
"timestamp": "2020-01-07T14:06:12.339Z",
5
"revision": 0,
6
"manifest": {
7
"next_available_key": 0,
8
"shards": 1024,
9
"buckets_per_shard": 64,
10
"shardbuckets": [
11
{
12
"key": 2,
13
"value": "015512202a1de9ce245a8d14b23512badc076aee71aad3aba30900e9c938243ce25b467d"
14
},
15
{
16
"key": 44,
17
"value": "015512205b43f739a9786fbe2c384c504af15d06fe1b5a61b72710f51932c6b62592d800"
18
},
19
...
20
]
21
}
22
}
Copied!

Load manifest

Once a manifest is saved, it can be loaded with the following smart contract action.
1
[[eosio::action]] void testman(dapp::manifest man) {
2
testindex_t testset(_self,_self.value);
3
// void load_manifest(manifest manifest, string description)
4
// description is description item in the backup table
5
testset.load_manifest(man,"Test");
6
}
Copied!
With a unit test:
1
let manifest = {
2
next_available_key: 556,
3
shards: 1024,
4
buckets_per_shard: 64,
5
shardbuckets
6
}
7
await testcontract.testman({
8
man: manifest
9
}, {
10
authorization: `${code}@active`,
11
broadcast: true,
12
sign: true
13
});
Copied!

Clear table

By calling the clear command, a table’s version is incremented via the revision param and the next_available_key is reset
1
TABLE vconfig {
2
checksum256 next_available_key = empty256;
3
uint32_t shards = 0;
4
uint32_t buckets_per_shard = 0;
5
uint32_t revision = 0;
6
};
7
void clear() {
8
vconfig_sgt vconfigsgt(_code,name(TableName).value);
9
auto config = vconfigsgt.get_or_default();
10
config.revision++;
11
config.next_available_key = empty256; //reset the next available key
12
vconfigsgt.set(config,_code);
13
}
14
[[eosio::action]] void testclear() {
15
testindex_t testset(_self,_self.value);
16
testset.clear();
17
}
Copied!
Copy link
Contents
Clear table