comparison OrthancServer/ServerIndex.cpp @ 268:4bc02e2254ec

preparing ServerIndex for recycling
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Dec 2012 13:43:35 +0100
parents 5b8e8b74bc8b
children f6fdf5abe751
comparison
equal deleted inserted replaced
266:a08dca15790e 268:4bc02e2254ec
137 bool ServerIndex::DeleteResource(Json::Value& target, 137 bool ServerIndex::DeleteResource(Json::Value& target,
138 const std::string& uuid, 138 const std::string& uuid,
139 ResourceType expectedType) 139 ResourceType expectedType)
140 { 140 {
141 boost::mutex::scoped_lock lock(mutex_); 141 boost::mutex::scoped_lock lock(mutex_);
142
143 listener_->Reset(); 142 listener_->Reset();
144 143
145 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction()); 144 std::auto_ptr<SQLite::Transaction> t(db_->StartTransaction());
146 t->Begin(); 145 t->Begin();
147 146
246 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, 245 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary,
247 const Attachments& attachments, 246 const Attachments& attachments,
248 const std::string& remoteAet) 247 const std::string& remoteAet)
249 { 248 {
250 boost::mutex::scoped_lock lock(mutex_); 249 boost::mutex::scoped_lock lock(mutex_);
250 listener_->Reset();
251 251
252 DicomInstanceHasher hasher(dicomSummary); 252 DicomInstanceHasher hasher(dicomSummary);
253 253
254 try 254 try
255 { 255 {
264 if (db_->LookupResource(hasher.HashInstance(), patient, type)) 264 if (db_->LookupResource(hasher.HashInstance(), patient, type))
265 { 265 {
266 assert(type == ResourceType_Instance); 266 assert(type == ResourceType_Instance);
267 return StoreStatus_AlreadyStored; 267 return StoreStatus_AlreadyStored;
268 } 268 }
269
270 // Ensure there is enough room in the storage for the new instance
271 uint64_t instanceSize = 0;
272 for (Attachments::const_iterator it = attachments.begin();
273 it != attachments.end(); it++)
274 {
275 instanceSize += it->GetCompressedSize();
276 }
277
278 Recycle(instanceSize, hasher.HashPatient());
269 279
270 // Create the instance 280 // Create the instance
271 instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance); 281 instance = db_->CreateResource(hasher.HashInstance(), ResourceType_Instance);
272 282
273 DicomMap dicom; 283 DicomMap dicom;
353 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series); 363 db_->LogChange(ChangeType_CompletedSeries, series, ResourceType_Series);
354 } 364 }
355 365
356 t->Commit(); 366 t->Commit();
357 367
368 // We can remove the files once the SQLite transaction has been
369 // successfully committed. Some files might have to be deleted
370 // because of recycling.
371 listener_->CommitFilesToRemove();
372
358 return StoreStatus_Success; 373 return StoreStatus_Success;
359 } 374 }
360 catch (OrthancException& e) 375 catch (OrthancException& e)
361 { 376 {
362 LOG(ERROR) << "EXCEPTION2 [" << e.What() << "]" << " " << db_->GetErrorMessage(); 377 LOG(ERROR) << "EXCEPTION [" << e.What() << "]"
378 << " (SQLite status: " << db_->GetErrorMessage() << ")";
363 } 379 }
364 380
365 return StoreStatus_Failure; 381 return StoreStatus_Failure;
366 } 382 }
367 383
738 { 754 {
739 boost::mutex::scoped_lock lock(mutex_); 755 boost::mutex::scoped_lock lock(mutex_);
740 db_->GetLastExportedResource(target); 756 db_->GetLastExportedResource(target);
741 return true; 757 return true;
742 } 758 }
759
760
761 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize)
762 {
763 return false;
764 }
765
766
767 void ServerIndex::Recycle(uint64_t instanceSize,
768 const std::string& newPatientId)
769 {
770 if (!IsRecyclingNeeded(instanceSize))
771 {
772 return;
773 }
774
775
776 //throw OrthancException(ErrorCode_FullStorage);
777 }
743 } 778 }