comparison OrthancServer/Sources/ServerIndex.cpp @ 4575:e23bacd4fffc db-changes

clarifications in ServerIndex::Recycle()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Mar 2021 18:30:06 +0100
parents 855e43bb293c
children f6cd49af7526
comparison
equal deleted inserted replaced
4574:855e43bb293c 4575:e23bacd4fffc
1110 1110
1111 1111
1112 void ServerIndex::Recycle(uint64_t instanceSize, 1112 void ServerIndex::Recycle(uint64_t instanceSize,
1113 const std::string& newPatientId) 1113 const std::string& newPatientId)
1114 { 1114 {
1115 if (!IsRecyclingNeeded(instanceSize)) 1115 if (IsRecyclingNeeded(instanceSize))
1116 { 1116 {
1117 return; 1117 // Check whether other DICOM instances from this patient are
1118 } 1118 // already stored
1119 1119 int64_t patientToAvoid;
1120 // Check whether other DICOM instances from this patient are 1120 bool hasPatientToAvoid;
1121 // already stored 1121
1122 int64_t patientToAvoid; 1122 if (newPatientId.empty())
1123 ResourceType type; 1123 {
1124 bool hasPatientToAvoid = db_.LookupResource(patientToAvoid, type, newPatientId); 1124 hasPatientToAvoid = false;
1125 1125 }
1126 if (hasPatientToAvoid && type != ResourceType_Patient) 1126 else
1127 { 1127 {
1128 throw OrthancException(ErrorCode_InternalError); 1128 ResourceType type;
1129 } 1129 hasPatientToAvoid = db_.LookupResource(patientToAvoid, type, newPatientId);
1130 1130 if (type != ResourceType_Patient)
1131 // Iteratively select patient to remove until there is enough 1131 {
1132 // space in the DICOM store 1132 throw OrthancException(ErrorCode_InternalError);
1133 int64_t patientToRecycle; 1133 }
1134 while (true) 1134 }
1135 { 1135
1136 // If other instances of this patient are already in the store, 1136 // Iteratively select patient to remove until there is enough
1137 // we must avoid to recycle them 1137 // space in the DICOM store
1138 bool ok = hasPatientToAvoid ? 1138 int64_t patientToRecycle;
1139 db_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) : 1139 while (true)
1140 db_.SelectPatientToRecycle(patientToRecycle); 1140 {
1141 // If other instances of this patient are already in the store,
1142 // we must avoid to recycle them
1143 bool ok = (hasPatientToAvoid ?
1144 db_.SelectPatientToRecycle(patientToRecycle, patientToAvoid) :
1145 db_.SelectPatientToRecycle(patientToRecycle));
1141 1146
1142 if (!ok) 1147 if (!ok)
1143 { 1148 {
1144 throw OrthancException(ErrorCode_FullStorage); 1149 throw OrthancException(ErrorCode_FullStorage);
1145 } 1150 }
1146 1151
1147 LOG(TRACE) << "Recycling one patient"; 1152 LOG(TRACE) << "Recycling one patient";
1148 db_.DeleteResource(patientToRecycle); 1153 db_.DeleteResource(patientToRecycle);
1149 1154
1150 if (!IsRecyclingNeeded(instanceSize)) 1155 if (!IsRecyclingNeeded(instanceSize))
1151 { 1156 {
1152 // OK, we're done 1157 // OK, we're done
1153 break; 1158 break;
1154 } 1159 }
1155 } 1160 }
1156 } 1161 }
1162 }
1163
1157 1164
1158 void ServerIndex::SetMaximumPatientCount(unsigned int count) 1165 void ServerIndex::SetMaximumPatientCount(unsigned int count)
1159 { 1166 {
1160 boost::mutex::scoped_lock lock(mutex_); 1167 boost::mutex::scoped_lock lock(mutex_);
1161 maximumPatients_ = count; 1168 maximumPatients_ = count;