On Thu, Dec 02, 2010 at 07:30:24PM +0000, Iustin Pop wrote:
> Tuples are good for two, three, at most four elements. Beyond that, the
> continuous pattern matching and construction/deconstruction becomes
> tedious.
>
> Since in the future we'll probably keep more information in the
> AllocSolution type, we change it now from a triple to a "real" data
> type. We also do some cleanups: adding a real emptyAlloc value, instead
> of the previous hardcoded ones, and add some more comments on how we do
> the multi-evacuation.
> ---
> Ganeti/HTools/Cluster.hs | 58 +++++++++++++++++++++++++++++++--------------
> Ganeti/HTools/QC.hs | 8 +++---
> hail.hs | 21 +++++++++-------
> 3 files changed, 56 insertions(+), 31 deletions(-)
>
> diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs
> index 8ba4edc..7838842 100644
> --- a/Ganeti/HTools/Cluster.hs
> +++ b/Ganeti/HTools/Cluster.hs
> @@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> MA
> module Ganeti.HTools.Cluster
> (
> -- * Types
> - AllocSolution
> + AllocSolution(..)
> , Table(..)
> , CStats(..)
> , AllocStats
> @@ -81,7 +81,19 @@ import qualified Ganeti.OpCodes as OpCodes
> -- * Types
>
> -- | Allocation\/relocation solution.
> -type AllocSolution = ([FailMode], Int, [Node.AllocElement])
> +data AllocSolution = AllocSolution
> + { asFailures :: [FailMode] -- ^ Failure counts
> + , asAllocs :: Int -- ^ Good allocation count
> + , asSolutions :: [Node.AllocElement] -- ^ The actual result, length
> + -- of the list depends on the
> + -- allocation/relocation mode
> +
> + }
> +
> +-- | The empty solution we start with when computing allocations
> +emptySolution :: AllocSolution
> +emptySolution = AllocSolution { asFailures = [], asAllocs = 0
> + , asSolutions = [] }
>
> -- | The complete state for the balancing solution
> data Table = Table Node.List Instance.List Score [Placement]
> @@ -533,10 +545,12 @@ collapseFailures flst =
> -- | Update current Allocation solution and failure stats with new
> -- elements
> concatAllocs :: AllocSolution -> OpResult Node.AllocElement -> AllocSolution
> -concatAllocs (flst, cntok, sols) (OpFail reason) = (reason:flst, cntok, sols)
> +concatAllocs as (OpFail reason) = as { asFailures = reason:asFailures as }
One small change here:
diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs
index 7838842..09b2814 100644
--- a/Ganeti/HTools/Cluster.hs
+++ b/Ganeti/HTools/Cluster.hs
@@ -545,7 +545,7 @@ collapseFailures flst =
-- | Update current Allocation solution and failure stats with new
-- elements
concatAllocs :: AllocSolution -> OpResult Node.AllocElement -> AllocSolution
-concatAllocs as (OpFail reason) = as { asFailures = reason:asFailures as }
+concatAllocs as (OpFail reason) = as { asFailures = reason : asFailures as }
concatAllocs as (OpGood ns@(_, _, _, nscore)) =
let -- Choose the old or new solution, based on the cluster score
I also looked through the Data.List sources and whether to use a space
or not around : in the code varies:
- never used in deconstruction patterns
- used in top-level concat operations, but not in lower-level; this is
unclear, so let me give an example: "… = y : nubBy' ys (y:xs)"; it
seems that many small (x:xs) or similar don't have spaces, for
brevity, but important ones (where the left or right side is not a
simple variable) do
iustin