2014-12-02 01:35:56 |
clayg |
description |
You can't rebalance an empty builder, because you can't have zero devices in a ring.
Even if rebalance worked validate is gunna check you have devices, because you can't have a zero devices in a ring.
You can't remove a device if it's the last one, because you dan't have zero devices in a ring.
You can't set the weight of all devices to 0, because you can't have zero devices in a ring.
If you try use write_ring on an empty builder, you get a *warning*, because you can't have zero devices in the ring...
... but it still does it - and you get a ring with zero devices.
I'm not sure exactly the history behind the write_ring's insane ability to create these quite useless bytes on disk - but from a code sanity point of view I think it would drastically better if most of the checks there that ever so carefully going about printing the *warning* were dropped right down into RingBuilder.get_ring and pushed out as *exceptions*.
Removing the ability entirely to have an invalid set of RingData on which write_ring can call save.
Swift definitely can't make any use of these empty rings, and it blows up in terrible Index/ValueError-y ways if you give it rings that didn't get proper validation.
If anyone ever things they *really* need an empty Ring on disk - they can run this:
>>> from swift.common.ring import RingData
>>> part_power = 10
>>> RingData([], [], part_power).save('footgun.ring.gz')
But let's not let RingBuilder give it up without a fight. |
You can't rebalance an empty builder, because you can't have zero devices in a ring.
Even if rebalance worked validate is gunna check you have devices, because you can't have a zero devices in a ring.
You can't remove a device if it's the last one, because you dan't have zero devices in a ring.
You can't set the weight of all devices to 0, because you can't have zero devices in a ring.
If you try use write_ring on an empty builder, you get a *warning*, because you can't have zero devices in the ring...
... but it still does it - and you get a ring with zero devices.
I'm not sure exactly the history behind the write_ring's insane ability to create these quite useless bytes on disk - but from a code sanity point of view I think it would drastically better if most of the checks there that are ever so carefully going about printing the *warning* were dropped right down into RingBuilder.get_ring and pushed out as *exceptions*.
Removing the ability entirely to have an invalid set of RingData on which write_ring can call save.
Swift definitely can't make any use of these empty rings, and it blows up in terrible Index/ValueError-y ways if you give it rings that didn't get proper validation.
If anyone ever thinks they *really* need an empty Ring on disk - they can run this:
>>> from swift.common.ring import RingData
>>> part_power = 10
>>> RingData([], [], part_power).save('footgun.ring.gz')
But let's not let RingBuilder give it up without a fight. |
|