forked from Qortal/qortal
Retry the entire bootstrap import process on failure, rather than just the download.
This commit is contained in:
parent
adeb654248
commit
47b1b6daba
@ -517,7 +517,12 @@ public class BlockChain {
|
|||||||
} else {
|
} else {
|
||||||
// Check first block is Genesis Block
|
// Check first block is Genesis Block
|
||||||
if (!isGenesisBlockValid()) {
|
if (!isGenesisBlockValid()) {
|
||||||
rebuildBlockchain();
|
try {
|
||||||
|
rebuildBlockchain();
|
||||||
|
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new DataException(String.format("Interrupted when trying to rebuild blockchain: %s", e.getMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -600,7 +605,7 @@ public class BlockChain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void rebuildBlockchain() throws DataException {
|
private static void rebuildBlockchain() throws DataException, InterruptedException {
|
||||||
boolean shouldBootstrap = Settings.getInstance().getBootstrap();
|
boolean shouldBootstrap = Settings.getInstance().getBootstrap();
|
||||||
if (shouldBootstrap) {
|
if (shouldBootstrap) {
|
||||||
// Settings indicate that we should apply a bootstrap rather than rebuilding and syncing from genesis
|
// Settings indicate that we should apply a bootstrap rather than rebuilding and syncing from genesis
|
||||||
|
@ -27,7 +27,7 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
|||||||
|
|
||||||
public class Bootstrap {
|
public class Bootstrap {
|
||||||
|
|
||||||
private Repository repository;
|
private final Repository repository;
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(Bootstrap.class);
|
private static final Logger LOGGER = LogManager.getLogger(Bootstrap.class);
|
||||||
|
|
||||||
@ -286,7 +286,22 @@ public class Bootstrap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startImport() throws DataException {
|
public void startImport() throws InterruptedException {
|
||||||
|
while (!Controller.isStopping()) {
|
||||||
|
try {
|
||||||
|
LOGGER.info("Starting import of bootstrap...");
|
||||||
|
|
||||||
|
this.doImport();
|
||||||
|
|
||||||
|
} catch (DataException e) {
|
||||||
|
LOGGER.info("Bootstrap import failed: {}", e.getMessage());
|
||||||
|
LOGGER.info("Retrying in 5 minutes");
|
||||||
|
Thread.sleep(5 * 60 * 1000L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doImport() throws DataException {
|
||||||
Path path = null;
|
Path path = null;
|
||||||
try {
|
try {
|
||||||
Path tempDir = Files.createTempDirectory("qortal-bootstrap");
|
Path tempDir = Files.createTempDirectory("qortal-bootstrap");
|
||||||
@ -313,28 +328,14 @@ public class Bootstrap {
|
|||||||
private void downloadToPath(Path path) throws DataException {
|
private void downloadToPath(Path path) throws DataException {
|
||||||
String bootstrapUrl = "http://bootstrap.qortal.org/bootstrap.7z";
|
String bootstrapUrl = "http://bootstrap.qortal.org/bootstrap.7z";
|
||||||
|
|
||||||
while (!Controller.isStopping()) {
|
try {
|
||||||
try {
|
LOGGER.info("Downloading bootstrap...");
|
||||||
LOGGER.info("Downloading bootstrap...");
|
InputStream in = new URL(bootstrapUrl).openStream();
|
||||||
InputStream in = new URL(bootstrapUrl).openStream();
|
Files.copy(in, path, REPLACE_EXISTING);
|
||||||
Files.copy(in, path, REPLACE_EXISTING);
|
|
||||||
break;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.info("Unable to download bootstrap: {}", e.getMessage());
|
throw new DataException(String.format("Unable to download bootstrap: {}", e.getMessage()));
|
||||||
LOGGER.info("Retrying in 5 minutes");
|
|
||||||
|
|
||||||
try {
|
|
||||||
repository.discardChanges();
|
|
||||||
Thread.sleep(5 * 60 * 1000L);
|
|
||||||
} catch (InterruptedException e2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's best to throw an exception on all failures, even though we're most likely just stopping
|
|
||||||
throw new DataException("Unable to download bootstrap");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importFromPath(Path path) throws InterruptedException, DataException, IOException {
|
public void importFromPath(Path path) throws InterruptedException, DataException, IOException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user