Reindex tweaks and improvements

-Added an "Are you sure" prompt before starting the reindex to make it clear that this is a destructive sync option
-All necessary coin stat data is cleared before starting the resync (txes, blockchain_last_updated and richlist_last_updated were not previously being cleared)
-More and better messages about what is being done during the process
-Shifted some of the code around to be run in a better order (for example, blockchain_last_updated date is set right after finishing the blockchain sync instead of at the very end of the reindex)
This commit is contained in:
Joe Uhren
2022-03-19 18:44:36 -06:00
parent 26a35700d4
commit cd05484ba5
2 changed files with 45 additions and 20 deletions
+32 -20
View File
@@ -296,42 +296,54 @@ if (database == 'peers') {
if (settings.blockchain_specific.heavycoin.enabled == true) if (settings.blockchain_specific.heavycoin.enabled == true)
db.update_heavy(settings.coin.name, stats.count, 20, function() {}); db.update_heavy(settings.coin.name, stats.count, 20, function() {});
if (mode == 'reindex') { if (mode == 'reindex') {
console.log('deleting transactions.. please wait..');
Tx.deleteMany({}, function(err) { Tx.deleteMany({}, function(err) {
console.log('TXs cleared.'); console.log('transactions deleted successfully');
console.log('deleting addresses.. please wait..');
Address.deleteMany({}, function(err2) { Address.deleteMany({}, function(err2) {
console.log('Addresses cleared.'); console.log('addresses deleted successfully');
console.log('deleting address transactions.. please wait..');
AddressTx.deleteMany({}, function(err3) { AddressTx.deleteMany({}, function(err3) {
console.log('Address TXs cleared.'); console.log('address transactions deleted successfully');
console.log('deleting top 100 data.. please wait..');
Richlist.updateOne({coin: settings.coin.name}, { Richlist.updateOne({coin: settings.coin.name}, {
received: [], received: [],
balance: [] balance: []
}, function(err3) { }, function(err3) {
console.log('top 100 data deleted successfully');
console.log('deleting block index.. please wait..');
Stats.updateOne({coin: settings.coin.name}, { Stats.updateOne({coin: settings.coin.name}, {
last: 0, last: 0,
count: 0, count: 0,
supply: 0 supply: 0,
txes: 0,
blockchain_last_updated: 0,
richlist_last_updated: 0
}, function() { }, function() {
console.log('index cleared (reindex)'); console.log('block index deleted successfully');
});
// Check if the sync msg should be shown // Check if the sync msg should be shown
check_show_sync_message(stats.count); check_show_sync_message(stats.count);
db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.update_timeout, false, function() { console.log('starting resync of blockchain data.. please wait..');
db.update_richlist('received', function() { db.update_tx_db(settings.coin.name, block_start, stats.count, stats.txes, settings.sync.update_timeout, false, function() {
db.update_richlist('balance', function() { // update blockchain_last_updated value
db.get_stats(settings.coin.name, function(nstats) { db.update_last_updated_stats(settings.coin.name, { blockchain_last_updated: Math.floor(new Date() / 1000) }, function (cb) {
// always check for and remove the sync msg if exists db.update_richlist('received', function() {
remove_sync_message(); db.update_richlist('balance', function() {
// update richlist_last_updated value // update richlist_last_updated value
db.update_last_updated_stats(settings.coin.name, { richlist_last_updated: Math.floor(new Date() / 1000) }, function (cb) { db.update_last_updated_stats(settings.coin.name, { richlist_last_updated: Math.floor(new Date() / 1000) }, function (cb) {
// update blockchain_last_updated value db.get_stats(settings.coin.name, function(nstats) {
db.update_last_updated_stats(settings.coin.name, { blockchain_last_updated: Math.floor(new Date() / 1000) }, function (cb) { // always check for and remove the sync msg if exists
console.log('reindex complete (block: %s)', nstats.last); remove_sync_message();
exit();
console.log('reindex complete (block: %s)', nstats.last);
exit();
});
}); });
}); });
}); });
+13
View File
@@ -120,6 +120,19 @@ if [ -n "${MODE}" ]; then
# Check if the desired mode requires a lock # Check if the desired mode requires a lock
if [ "${MODE}" != "peers" ] && [ "${MODE}" != "masternodes" ]; then if [ "${MODE}" != "peers" ] && [ "${MODE}" != "masternodes" ]; then
# A lock is required # A lock is required
# Check if this is a reindex
if [ "${MODE}" = "index reindex" ]; then
# Prompt for the reindex
echo "You are about to delete all blockchain data (transactions and addresses)"
echo "and resync from the genesis block."
echo "Are you sure you want to do this? [y/n]: ";
read -p "" REINDEX_ANSWER
# Determine if the reindex should proceed
case "$REINDEX_ANSWER" in
y|Y|yes|Yes|YES) ;;
*) echo "Process aborted. Nothing was deleted." && exit ;;
esac
fi
# Check if the script is already running (tmp/index.pid file already exists) # Check if the script is already running (tmp/index.pid file already exists)
if [ -f "${EXPLORER_PATH}/tmp/index.pid" ]; then if [ -f "${EXPLORER_PATH}/tmp/index.pid" ]; then
# The tmp/index.pid file exists. Check if the process is actually still running # The tmp/index.pid file exists. Check if the process is actually still running