| 704 | } |
| 705 | |
| 706 | bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase& database) |
| 707 | { |
| 708 | if (database.IsDummy()) { |
| 709 | return true; |
| 710 | } |
| 711 | bool ret = false; |
| 712 | BerkeleyEnvironment *env = database.env; |
| 713 | const std::string& strFile = database.strFile; |
| 714 | TRY_LOCK(cs_db, lockDb); |
| 715 | if (lockDb) |
| 716 | { |
| 717 | // Don't do this if any databases are in use |
| 718 | int nRefCount = 0; |
| 719 | std::map<std::string, int>::iterator mit = env->mapFileUseCount.begin(); |
| 720 | while (mit != env->mapFileUseCount.end()) |
| 721 | { |
| 722 | nRefCount += (*mit).second; |
| 723 | mit++; |
| 724 | } |
| 725 | |
| 726 | if (nRefCount == 0) |
| 727 | { |
| 728 | boost::this_thread::interruption_point(); |
| 729 | std::map<std::string, int>::iterator mi = env->mapFileUseCount.find(strFile); |
| 730 | if (mi != env->mapFileUseCount.end()) |
| 731 | { |
| 732 | LogPrint(BCLog::DB, "Flushing %s\n", strFile); |
| 733 | int64_t nStart = GetTimeMillis(); |
| 734 | |
| 735 | // Flush wallet file so it's self contained |
| 736 | env->CloseDb(strFile); |
| 737 | env->CheckpointLSN(strFile); |
| 738 | |
| 739 | env->mapFileUseCount.erase(mi++); |
| 740 | LogPrint(BCLog::DB, "Flushed %s %dms\n", strFile, GetTimeMillis() - nStart); |
| 741 | ret = true; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | bool BerkeleyDatabase::Rewrite(const char* pszSkip) |
| 750 | { |
nothing calls this directly
no test coverage detected