MCPcopy Create free account
hub / github.com/apache/mesos / shrink

Method shrink

src/common/resources.cpp:1288–1318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1286
1287
1288bool Resources::shrink(Resource* resource, const Value::Scalar& target)
1289{
1290 if (resource->scalar() <= target) {
1291 return true; // Already within target.
1292 }
1293
1294 // Some `disk` resources (e.g. MOUNT disk) are indivisible.
1295 // We use a containement check to verify this. Specifically,
1296 // if it contains a smaller version of itself, then it can
1297 // safely be chopped into a smaller amount.
1298 //
1299 // NOTE: If additional types of resources become indivisible,
1300 // this code needs updating!
1301 if (resource->has_disk()) {
1302 Resource original = *resource;
1303
1304 Value::Scalar oldScalar = resource->scalar();
1305 *resource->mutable_scalar() = target;
1306
1307 if (mesos::contains(original, *resource)) {
1308 return true;
1309 }
1310
1311 // Restore the old value.
1312 *resource->mutable_scalar() = std::move(oldScalar);
1313 return false;
1314 }
1315
1316 *resource->mutable_scalar() = target;
1317 return true;
1318}
1319
1320
1321Resources Resources::getReservationAncestor(

Callers

nothing calls this directly

Calls 1

containsFunction · 0.70

Tested by

no test coverage detected