Skip to content

Commit

Permalink
break up redis tx inserts into smaller chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
glimberg committed Jul 8, 2024
1 parent 34cc261 commit 508527f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions controller/PostgreSQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,25 @@ void PostgreSQL::initializeNetworks()
fprintf(stderr, "adding networks to redis...\n");
if (_rc->clusterMode) {
auto tx = _cluster->transaction(_myAddressStr, true, false);
tx.sadd(setKey, networkSet.begin(), networkSet.end());
uint64_t count = 0;
for (std::string nwid : networkSet) {
tx.sadd(setKey, nwid);
if (++count % 30000 == 0) {
tx.exec();
tx = _cluster->transaction(_myAddressStr, true, false);
}
}
tx.exec();
} else {
auto tx = _redis->transaction(true, false);
tx.sadd(setKey, networkSet.begin(), networkSet.end());
uint64_t count = 0;
for (std::string nwid : networkSet) {
tx.sadd(setKey, nwid);
if (++count % 30000 == 0) {
tx.exec();
tx = _redis->transaction(true, false);
}
}
tx.exec();
}
fprintf(stderr, "done.\n");
Expand Down Expand Up @@ -1005,14 +1019,24 @@ void PostgreSQL::initializeMembers()
fprintf(stderr, "Load member data into redis...\n");
if (_rc->clusterMode) {
auto tx = _cluster->transaction(_myAddressStr, true, false);
uint64_t count = 0;
for (auto it : networkMembers) {
tx.sadd(it.first, it.second);
if (++count % 30000 == 0) {
tx.exec();
tx = _cluster->transaction(_myAddressStr, true, false);
}
}
tx.exec();
} else {
auto tx = _redis->transaction(true, false);
uint64_t count = 0;
for (auto it : networkMembers) {
tx.sadd(it.first, it.second);
if (++count % 30000 == 0) {
tx.exec();
tx = _redis->transaction(true, false);
}
}
tx.exec();
}
Expand Down

0 comments on commit 508527f

Please sign in to comment.