Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 206:4453a010d0db
flush to disk thread
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Nov 2012 12:03:18 +0100 |
parents | 6ab754744446 |
children | f276b175dcaf |
comparison
equal
deleted
inserted
replaced
205:6ab754744446 | 206:4453a010d0db |
---|---|
125 | 125 |
126 bool ServerIndex::DeleteInternal(Json::Value& target, | 126 bool ServerIndex::DeleteInternal(Json::Value& target, |
127 const std::string& uuid, | 127 const std::string& uuid, |
128 ResourceType expectedType) | 128 ResourceType expectedType) |
129 { | 129 { |
130 boost::mutex::scoped_lock scoped_lock(mutex_); | 130 boost::mutex::scoped_lock lock(mutex_); |
131 | 131 |
132 listener_->Reset(); | 132 listener_->Reset(); |
133 | 133 |
134 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); | 134 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); |
135 t->Begin(); | 135 t->Begin(); |
163 | 163 |
164 return true; | 164 return true; |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 static void FlushThread(DatabaseWrapper* db, | |
169 boost::mutex* mutex) | |
170 { | |
171 // By default, wait for 10 seconds before flushing | |
172 unsigned int sleep = 10; | |
173 | |
174 { | |
175 boost::mutex::scoped_lock lock(*mutex); | |
176 std::string s = db->GetGlobalProperty(GlobalProperty_FlushSleep); | |
177 try | |
178 { | |
179 sleep = boost::lexical_cast<unsigned int>(s); | |
180 } | |
181 catch (boost::bad_lexical_cast&) | |
182 { | |
183 } | |
184 } | |
185 | |
186 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; | |
187 | |
188 while (1) | |
189 { | |
190 boost::this_thread::sleep(boost::posix_time::seconds(sleep)); | |
191 boost::mutex::scoped_lock lock(*mutex); | |
192 db->FlushToDisk(); | |
193 } | |
194 } | |
195 | |
196 | |
168 ServerIndex::ServerIndex(FileStorage& fileStorage, | 197 ServerIndex::ServerIndex(FileStorage& fileStorage, |
169 const std::string& dbPath) | 198 const std::string& dbPath) |
170 { | 199 { |
171 listener_.reset(new Internals::ServerIndexListener(fileStorage)); | 200 listener_.reset(new Internals::ServerIndexListener(fileStorage)); |
172 | 201 |
186 { | 215 { |
187 } | 216 } |
188 | 217 |
189 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_)); | 218 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_)); |
190 } | 219 } |
220 | |
221 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_); | |
222 } | |
223 | |
224 | |
225 ServerIndex::~ServerIndex() | |
226 { | |
227 LOG(INFO) << "Stopping the database flushing thread"; | |
228 flushThread_.interrupt(); | |
229 flushThread_.join(); | |
191 } | 230 } |
192 | 231 |
193 | 232 |
194 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, | 233 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, |
195 const std::string& fileUuid, | 234 const std::string& fileUuid, |
196 uint64_t uncompressedFileSize, | 235 uint64_t uncompressedFileSize, |
197 const std::string& jsonUuid, | 236 const std::string& jsonUuid, |
198 const std::string& remoteAet) | 237 const std::string& remoteAet) |
199 { | 238 { |
200 boost::mutex::scoped_lock scoped_lock(mutex_); | 239 boost::mutex::scoped_lock lock(mutex_); |
201 | 240 |
202 DicomInstanceHasher hasher(dicomSummary); | 241 DicomInstanceHasher hasher(dicomSummary); |
203 | 242 |
204 try | 243 try |
205 { | 244 { |
348 return status; | 387 return status; |
349 } | 388 } |
350 | 389 |
351 uint64_t ServerIndex::GetTotalCompressedSize() | 390 uint64_t ServerIndex::GetTotalCompressedSize() |
352 { | 391 { |
353 boost::mutex::scoped_lock scoped_lock(mutex_); | 392 boost::mutex::scoped_lock lock(mutex_); |
354 return db_->GetTotalCompressedSize(); | 393 return db_->GetTotalCompressedSize(); |
355 } | 394 } |
356 | 395 |
357 uint64_t ServerIndex::GetTotalUncompressedSize() | 396 uint64_t ServerIndex::GetTotalUncompressedSize() |
358 { | 397 { |
359 boost::mutex::scoped_lock scoped_lock(mutex_); | 398 boost::mutex::scoped_lock lock(mutex_); |
360 return db_->GetTotalUncompressedSize(); | 399 return db_->GetTotalUncompressedSize(); |
361 } | 400 } |
362 | 401 |
363 | 402 |
364 SeriesStatus ServerIndex::GetSeriesStatus(int id) | 403 SeriesStatus ServerIndex::GetSeriesStatus(int id) |
440 const std::string& publicId, | 479 const std::string& publicId, |
441 ResourceType expectedType) | 480 ResourceType expectedType) |
442 { | 481 { |
443 result = Json::objectValue; | 482 result = Json::objectValue; |
444 | 483 |
445 boost::mutex::scoped_lock scoped_lock(mutex_); | 484 boost::mutex::scoped_lock lock(mutex_); |
446 | 485 |
447 // Lookup for the requested resource | 486 // Lookup for the requested resource |
448 int64_t id; | 487 int64_t id; |
449 ResourceType type; | 488 ResourceType type; |
450 if (!db_->LookupResource(publicId, id, type) || | 489 if (!db_->LookupResource(publicId, id, type) || |
579 bool ServerIndex::GetFile(std::string& fileUuid, | 618 bool ServerIndex::GetFile(std::string& fileUuid, |
580 CompressionType& compressionType, | 619 CompressionType& compressionType, |
581 const std::string& instanceUuid, | 620 const std::string& instanceUuid, |
582 AttachedFileType contentType) | 621 AttachedFileType contentType) |
583 { | 622 { |
584 boost::mutex::scoped_lock scoped_lock(mutex_); | 623 boost::mutex::scoped_lock lock(mutex_); |
585 | 624 |
586 int64_t id; | 625 int64_t id; |
587 ResourceType type; | 626 ResourceType type; |
588 if (!db_->LookupResource(instanceUuid, id, type) || | 627 if (!db_->LookupResource(instanceUuid, id, type) || |
589 type != ResourceType_Instance) | 628 type != ResourceType_Instance) |
599 | 638 |
600 | 639 |
601 void ServerIndex::GetAllUuids(Json::Value& target, | 640 void ServerIndex::GetAllUuids(Json::Value& target, |
602 ResourceType resourceType) | 641 ResourceType resourceType) |
603 { | 642 { |
604 boost::mutex::scoped_lock scoped_lock(mutex_); | 643 boost::mutex::scoped_lock lock(mutex_); |
605 db_->GetAllPublicIds(target, resourceType); | 644 db_->GetAllPublicIds(target, resourceType); |
606 } | 645 } |
607 | 646 |
608 | 647 |
609 bool ServerIndex::GetChanges(Json::Value& target, | 648 bool ServerIndex::GetChanges(Json::Value& target, |
610 int64_t since, | 649 int64_t since, |
611 unsigned int maxResults) | 650 unsigned int maxResults) |
612 { | 651 { |
613 boost::mutex::scoped_lock scoped_lock(mutex_); | 652 boost::mutex::scoped_lock lock(mutex_); |
614 | 653 |
615 db_->GetChanges(target, since, maxResults); | 654 db_->GetChanges(target, since, maxResults); |
616 | 655 |
617 return true; | 656 return true; |
618 } | 657 } |