> On July 20, 2016, 2:36 a.m., Klaus Ma wrote: > > include/mesos/resources.hpp, line 124 > > <https://reviews.apache.org/r/45959/diff/8/?file=1447679#file1447679line124> > > > > Seems `Option` is not necessary.
sharedCount is None when it is is regular non-shared resource, and is an integer for a shared resource which references to the number of copies of the shared resource. So, I think `Option` should be fine here. > On July 20, 2016, 2:36 a.m., Klaus Ma wrote: > > include/mesos/resources.hpp, line 484 > > <https://reviews.apache.org/r/45959/diff/8/?file=1447679#file1447679line484> > > > > Why not `list`? It may avoid un-necessary resizing. `std::list` does a memory allocation for every insert and a deallocation on every remove. `std::vector` reserves memory for certain number of entries (dependent on platform and implementation) but not on every insert (and hence memory allocation is done in a batch, and same for memory deallocation). To alleviate move/copy operations on insert and remove from `std::vector`, we always do a `std::vector::push_back()` on insertion which is O(1), and for erase we swap the entry with the last entry using `std::vector::back()` and remove the last entry with a `std::vector::pop_back()` resulting in O(1). > On July 20, 2016, 2:36 a.m., Klaus Ma wrote: > > include/mesos/resources.hpp, line 84 > > <https://reviews.apache.org/r/45959/diff/8/?file=1447679#file1447679line84> > > > > I think this's dangous, the developer need to check this converting and > > decide which `operator` is used. If miss used, it's hard to debuging. Can you please explain why this is dangerous? This operator implicitly converts a `Resource_` to return the corresponding `Resource`. Since `Resource_` is nested private class (and is hence hidden), callers would care about `Resource` only (this would ensure backward compatibility with existing code). > On July 20, 2016, 2:36 a.m., Klaus Ma wrote: > > src/common/resources.cpp, line 882 > > <https://reviews.apache.org/r/45959/diff/8/?file=1447680#file1447680line882> > > > > one `isShared()` is enough. `isShared` is checked in `subtractable`. Updated in `Resources::Resource_& Resources::Resource_::operator+=(const Resource_& that)` as well as in `Resources::Resource_& Resources::Resource_::operator-=(const Resource_& that)`. - Anindya ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/45959/#review142892 ----------------------------------------------------------- On July 19, 2016, 10:51 p.m., Anindya Sinha wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/45959/ > ----------------------------------------------------------- > > (Updated July 19, 2016, 10:51 p.m.) > > > Review request for mesos, Benjamin Mahler, Joris Van Remoortere, and Jiang > Yan Xu. > > > Bugs: MESOS-4892 > https://issues.apache.org/jira/browse/MESOS-4892 > > > Repository: mesos > > > Description > ------- > > A new class Resource_ is added that allows 'Resources' to group > identical shared resource objects together into a single 'Resource_' > object and tracked by its shared count. Non-shared resource objects > are not grouped. > > For resource addition and subtraction, the shared count is adjusted for > shared resources as follows: > a) Addition: If shared resource is absent from original, then the > resource is added initialized with a consumer count of 1. Otherwise, > the share count for the shared resource is incremented. > b) Subtraction: If shared resource's share count is already 1, then > the shared resource is removed from the original. Otherwise, its > consumer count is decremented. > > Note that v1 changes for shared resources are in the next commit. > > > Diffs > ----- > > include/mesos/resources.hpp a557e97c65194d4aad879fb88d8edefd1c95b8d8 > src/common/resources.cpp b1bd2784aefdebf91892638b40b215373b998574 > src/master/validation.cpp 50ba372d1301d16d1738a3e4f4882b51f9ce06cd > src/tests/mesos.hpp e4eccfc3810bed3649a3ab80e252849470de4c72 > src/tests/resources_tests.cpp 4111e080b84079e100b731c9a56861b204f17388 > > Diff: https://reviews.apache.org/r/45959/diff/ > > > Testing > ------- > > New tests added to demonstrate arithmetic operations for shared resources > with consumer counts. > Tests successful. > > > Thanks, > > Anindya Sinha > >
