# HG changeset patch # User Pieter Wuille # Date 1335442857 25200 # Node ID bffdc5c4d973bc0e1b31aac08c2455b4246c1c4d # Parent 0340d3a668c1826f6705a6d998f75b86c60fc560# Parent 2d4c7d77f691d6799be53070a181502dc8248fe4 Merge pull request #1119 from sipa/fastshutdown Make lsn_reset ("detach databases") optional and off by default. diff --git a/src/db.cpp b/src/db.cpp --- a/src/db.cpp +++ b/src/db.cpp @@ -28,6 +28,7 @@ CCriticalSection cs_db; static bool fDbEnvInit = false; +bool fDetachDB = false; DbEnv dbenv(0); map mapFileUseCount; static map mapDb; @@ -307,9 +308,13 @@ { // Move log data to the dat file CloseDb(strFile); + printf("%s checkpoint\n", strFile.c_str()); dbenv.txn_checkpoint(0, 0, 0); - printf("%s flush\n", strFile.c_str()); - dbenv.lsn_reset(strFile.c_str(), 0); + if ((strFile != "blkindex.dat" && strFile != "addr.dat") || fDetachDB) { + printf("%s detach\n", strFile.c_str()); + dbenv.lsn_reset(strFile.c_str(), 0); + } + printf("%s closed\n", strFile.c_str()); mapFileUseCount.erase(mi++); } else diff --git a/src/db.h b/src/db.h --- a/src/db.h +++ b/src/db.h @@ -25,6 +25,7 @@ class CWalletTx; extern unsigned int nWalletDBUpdated; +extern bool fDetachDB; extern DbEnv dbenv; extern void DBFlush(bool fShutdown); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -200,6 +200,7 @@ #else " -upnp \t " + _("Use Universal Plug and Play to map the listening port (default: 0)") + "\n" + #endif + " -detachdb \t " + _("Detach block and address databases. Increases shutdown time (default: 0)") + "\n" + #endif " -paytxfee= \t " + _("Fee per KB to add to transactions you send") + "\n" + #ifdef QT_GUI @@ -255,6 +256,7 @@ } fDebug = GetBoolArg("-debug"); + fDetachDB = GetBoolArg("-detachdb", false); #if !defined(WIN32) && !defined(QT_GUI) fDaemon = GetBoolArg("-daemon"); diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -38,6 +38,7 @@ QCheckBox *minimize_on_close; #endif QCheckBox *connect_socks4; + QCheckBox *detach_database; QLineEdit *proxy_ip; QLineEdit *proxy_port; BitcoinAmountField *fee_edit; @@ -229,6 +230,10 @@ layout->addLayout(fee_hbox); + detach_database = new QCheckBox(tr("Detach databases at shutdown")); + detach_database->setToolTip(tr("Detach block and address databases at shutdown. This means they can be moved to another data directory, but it slows down shutdown. The wallet is always detached.")); + layout->addWidget(detach_database); + layout->addStretch(1); // Extra space at bottom setLayout(layout); @@ -256,6 +261,7 @@ mapper->addMapping(proxy_ip, OptionsModel::ProxyIP); mapper->addMapping(proxy_port, OptionsModel::ProxyPort); mapper->addMapping(fee_edit, OptionsModel::Fee); + mapper->addMapping(detach_database, OptionsModel::DetachDatabases); } DisplayOptionsPage::DisplayOptionsPage(QWidget *parent): diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -28,6 +28,8 @@ SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()); if (settings.contains("addrProxy") && settings.value("fUseProxy").toBool()) SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()); + if (settings.contains("detachDB")) + SoftSetBoolArg("-detachdb", settings.value("detachDB").toBool()); } bool OptionsModel::Upgrade() @@ -121,6 +123,8 @@ return QVariant(nDisplayUnit); case DisplayAddresses: return QVariant(bDisplayAddresses); + case DetachDatabases: + return QVariant(fDetachDB); default: return QVariant(); } @@ -204,6 +208,11 @@ settings.setValue("bDisplayAddresses", bDisplayAddresses); } break; + case DetachDatabases: { + fDetachDB = value.toBool(); + settings.setValue("detachDB", fDetachDB); + } + break; default: break; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -26,7 +26,8 @@ Fee, // qint64 DisplayUnit, // BitcoinUnits::Unit DisplayAddresses, // bool - OptionIDRowCount + DetachDatabases, // bool + OptionIDRowCount, }; void Init();