Flush file index during server shutdown

This commit is contained in:
Martin 2016-02-01 16:56:03 +01:00
parent 1e42813658
commit 2d4e100eba
3 changed files with 29 additions and 5 deletions

View File

@ -38,6 +38,7 @@ IMutex *FileIndex::mutex=NULL;
ICondition *FileIndex::cond=NULL;
bool FileIndex::do_shutdown=false;
bool FileIndex::do_flush=false;
bool FileIndex::do_accept = true;
void FileIndex::operator()(void)
@ -117,7 +118,7 @@ void FileIndex::put_delayed(const SIndexKey& key, int64 value)
{
IScopedLock lock(mutex);
while(active_cache_buffer->size()>=max_buffer_size)
while(active_cache_buffer->size()>=max_buffer_size || !do_accept)
{
lock.relock(NULL);
Server->wait(10);
@ -313,3 +314,9 @@ void FileIndex::flush()
lock.relock(mutex);
}
}
void FileIndex::stop_accept()
{
IScopedLock lock(mutex);
do_accept = false;
}

View File

@ -138,6 +138,8 @@ public:
static void flush();
static void stop_accept();
private:
bool get_from_cache( const FileIndex::SIndexKey &key, const std::map<SIndexKey, int64>& cache, int64& res );
@ -158,4 +160,5 @@ private:
static bool do_shutdown;
static bool do_flush;
static bool do_accept;
};

View File

@ -805,12 +805,26 @@ DLLEXPORT void UnloadActions(void)
ClientMain::destroy_mutex();
}
IDatabase *db=Server->getDatabase(Server->getThreadID(), URBACKUPDB_SERVER);
db->Write("PRAGMA wal_checkpoint");
if(!shutdown_ok)
db->BeginWriteTransaction();
std::vector<DATABASE_ID> db_ids;
db_ids.push_back(URBACKUPDB_SERVER);
db_ids.push_back(URBACKUPDB_SERVER_FILES);
db_ids.push_back(URBACKUPDB_SERVER_LINKS);
db_ids.push_back(URBACKUPDB_SERVER_LINK_JOURNAL);
if (!shutdown_ok)
{
for (size_t i = 0; i < db_ids.size(); ++i)
{
IDatabase *db = Server->getDatabase(Server->getThreadID(), db_ids[i]);
db->BeginWriteTransaction();
}
}
else
{
Server->destroyAllDatabases();
}
FileIndex::stop_accept();
FileIndex::flush();
}
#ifdef STATIC_PLUGIN