> On Sept. 14, 2016, 1:59 p.m., Benjamin Bannier wrote:
> > src/common/resources.cpp, line 1745
> > <https://reviews.apache.org/r/51517/diff/2/?file=1495047#file1495047line1745>
> >
> >     It would be great if you could avoid using `default` when switching 
> > over enum values. See https://issues.apache.org/jira/browse/MESOS-3754 for 
> > some background.
> 
> Anindya Sinha wrote:
>     Done at both call sites.
> 
> Benjamin Bannier wrote:
>     Sorry for being unclear, but I think since these enums are just glorified 
> names for integers you still need to handle unknown values. What about a 
> pattern like this:
>     
>         ostream& operator<<(ostream& stream, const 
> Resource::DiskInfo::Source& source)
>         {
>           switch (source.type()) {
>             case Resource::DiskInfo::Source::MOUNT:
>               return stream << "MOUNT:" + source.mount().root();
>             case Resource::DiskInfo::Source::PATH:
>               return stream << "PATH:" + source.path().root();
>           }
>     
>           UNREACHABLE();
>         }
> 
> Jiang Yan Xu wrote:
>     This style LGTM. Just to clarify, "since these enums are just glorified 
> names" you mean because we haven't turned on `-Wswitch`? In the proposed new 
> style we use `UNREACHABLE();` for readability and not for "unknown values" 
> right?
> 
> Anindya Sinha wrote:
>     Updated.
> 
> Benjamin Bannier wrote:
>     Thanks for accommodating these last minute requests Anindya.
>     
>     In general above pattern could still trigger `UNREACHABLE` at runtime when
>     
>     a) a caller forces an uncovered integer into `Type`, e.g., with 
> `source.set_type(static_cast<Resource::DiskInfo::Source::Type>(42));`, or
>     b) when new values are added to the `Type` enum, but code switching over 
> values is not recompiled.
>     
>     It looks like neither issue is likely for this particular code, but the 
> suggested pattern should be a pretty safe general solution.

OK then `-Wswitch` can only help to some extent I guess. In Mesos code itself 
we would certainly discourage code that would introduce the two above cases. I 
guess it's valuable to mention these in MESOS-3754? In cases where you can't 
directly return from switch cases it seems we cannot completely eliminate the 
need for

```
default:
  UNREACHABLE();
```

when considering the above cases, no?

Of course none of these concerns are applicable to this patch. Just thought you 
should share these points on MESOS-3754 too. :)


- Jiang Yan


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/51517/#review148967
-----------------------------------------------------------


On Sept. 14, 2016, 3:32 p.m., Anindya Sinha wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/51517/
> -----------------------------------------------------------
> 
> (Updated Sept. 14, 2016, 3:32 p.m.)
> 
> 
> Review request for mesos and Jiang Yan Xu.
> 
> 
> Bugs: MESOS-6060
>     https://issues.apache.org/jira/browse/MESOS-6060
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> We also log the disk type (MOUNT or PATH) for each persistent disk as
> well as the root path for these disks while logging resources. Note
> that this is logged only when source is present, otherwise there is
> no additional content logged.
> 
> 
> Diffs
> -----
> 
>   src/common/resources.cpp f841e91b81975a887e64a76a709708ed7946025f 
>   src/tests/resources_tests.cpp f627862870279e5a778aa83e1ddcaa88c27ba1cb 
>   src/v1/resources.cpp 4410a8f95ef0ebe6ec7aee38cd47f6f83f863867 
> 
> Diff: https://reviews.apache.org/r/51517/diff/
> 
> 
> Testing
> -------
> 
> All tests passed.
> 
> 
> Thanks,
> 
> Anindya Sinha
> 
>

Reply via email to