- check for existance of /blocks/ dir and verify if it is non-empty, disable -reindex, if these checks fail
- print "Reindexing aborted" to log, if OpenBlockFile() in ThreadImport() fails
Intended to fix #2239
- check for existance of /blocks/ dir and verify if it is non-empty,
disable -reindex, if these checks fail
- print "Reindexing aborted" to log, if OpenBlockFile() in ThreadImport()
fails
354 | @@ -355,16 +355,23 @@ void ThreadImport(void *data) { 355 | while (!fRequestShutdown) { 356 | CDiskBlockPos pos(nFile, 0); 357 | FILE *file = OpenBlockFile(pos, true); 358 | - if (!file) 359 | + if (!file) { 360 | + // problem opening block file
fReindex=false is set immediately after the while loop anyway, just break suffices. I prefer not changing fReindex without writing it to the block index.
The change here is intended to give "Reindexing aborted" in the log (nothing more in the end, as I found it weird to read Reindexing finished after a crash).
I understand your wish to link setting fReindex with writing the reindex-state to block index. But if fRequestShutdown is getting true we also don't write it?
Edit: What about using nFile = -1 as a check that OpenBlockFile() failed ;)? Then no need to set fReindex = false here.
Changed this to use the flag nFile = -1 now.
746 | @@ -740,7 +747,13 @@ bool AppInit2() 747 | 748 | // ********************************************************* Step 7: load block chain 749 | 750 | + filesystem::path blocksDir = GetDataDir() / "blocks"; 751 | + 752 | fReindex = GetBoolArg("-reindex"); 753 | + if (fReindex && !filesystem::exists(blocksDir)) {
Is this necessary? it will fail if the directory exists but is empty, for example. Trying to do a reindex shouldn't hurt.
This check prevents the crash for me, you are right perhaps it should use ::is_empty(). If you think there is no crash or problem, did you try -reindex with empty data dir yet?
Reworked to now check if the dir exists and if it's empty.
354 | @@ -355,8 +355,10 @@ void ThreadImport(void *data) { 355 | while (!fRequestShutdown) { 356 | CDiskBlockPos pos(nFile, 0); 357 | FILE *file = OpenBlockFile(pos, true); 358 | - if (!file) 359 | + if (!file) { 360 | + nFile = -1; // use -1 as a flag for reindexing aborted
That will cause it to always report aborted, no? We iterate until we can't open any file anymore.
744 | @@ -740,7 +745,14 @@ bool AppInit2() 745 | 746 | // ********************************************************* Step 7: load block chain 747 | 748 | + filesystem::path blocksDir = GetDataDir() / "blocks"; 749 | + 750 | fReindex = GetBoolArg("-reindex"); 751 | + // don't try to reindex, if blocks dir is missing or empty
I don't think this is the correct solution. Whether the directory exist or not shouldn't ever cause a crash. If it does, that's a bug elsewhere.