commit 07c04d557a77fc1238ffee1702d5689d35fcaa7e
Merge: bb02b8f fda1a35
Author: Petr Pudlak <[email protected]>
Date: Tue Mar 3 12:57:17 2015 +0100
Merge branch 'stable-2.11' into stable-2.12
* stable-2.11
(no changes)
* stable-2.10
Relax expectation of accuracy
Improve rounding accuracty in updateStatistics
Update gnt-backup manual to reflect real behavior
Finalize local export only if successful
* stable-2.9
Stop MonD when removing a node from a cluster
Conflicts:
man/gnt-backup.rst
src/Ganeti/Utils.hs
test/hs/Test/Ganeti/Utils.hs
Resolution: Propagate changes in 2.10 (also to the files that have been
moved in 2.12).
diff --cc man/gnt-backup.rst
index a952288,85888f9..f9a9359
--- a/man/gnt-backup.rst
+++ b/man/gnt-backup.rst
@@@ -55,20 -52,12 +55,19 @@@ The ``--remove`` option can be used to
was exported. This is useful to make one last backup before
removing the instance.
+The ``--zero-free-space`` option can be used to zero the free space
+of the instance prior to exporting it, saving space if compression
+is used. The ``--zeroing-timeout-fixed`` and
+``--zeroing-timeout-per-mib`` options control the timeout, the former
+determining the minimum time to wait, and the latter how much longer
+to wait per MiB of data the instance has.
+
- The exit code of the command is 0 if all disks were backed up
- successfully, 1 if no data was backed up or if the configuration
- export failed, and 2 if just some of the disks failed to backup.
- The exact details of the failures will be shown during the command
- execution (and will be stored in the job log). It is recommended
- that for any non-zero exit code, the backup is considered invalid,
- and retried.
+ Should the snapshotting or transfer of any of the instance disks
+ fail, the backup will not complete and any previous backups will be
+ preserved. The exact details of the failures will be shown during the
+ command execution (and will be stored in the job log). It is
+ recommended that for any non-zero exit code, the backup is considered
+ invalid, and retried.
See **ganeti**\(7) for a description of ``--submit`` and other common
options.
diff --cc src/Ganeti/Utils/Statistics.hs
index bb9a1c7,0000000..826a906
mode 100644,000000..100644
--- a/src/Ganeti/Utils/Statistics.hs
+++ b/src/Ganeti/Utils/Statistics.hs
@@@ -1,87 -1,0 +1,87 @@@
+{-# LANGUAGE BangPatterns #-}
+
+
+{-| Utility functions for statistical accumulation. -}
+
+{-
+
+Copyright (C) 2014 Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-}
+
+module Ganeti.Utils.Statistics
+ ( Statistics
+ , getSumStatistics
+ , getStdDevStatistics
+ , getStatisticValue
+ , updateStatistics
+ ) where
+
+import Data.List (foldl')
+
+-- | Abstract type of statistical accumulations. They behave as if the given
+-- statistics were computed on the list of values, but they allow a
potentially
+-- more efficient update of a given value.
+data Statistics = SumStatistics Double
+ | StdDevStatistics Double Double Double deriving Show
+ -- count, sum, and not the sum of squares---instead the
+ -- computed variance for better precission.
+
+-- | Get a statistics that sums up the values.
+getSumStatistics :: [Double] -> Statistics
+getSumStatistics = SumStatistics . sum
+
+-- | Get a statistics for the standard deviation.
+getStdDevStatistics :: [Double] -> Statistics
+getStdDevStatistics xs =
+ let (nt, st) = foldl' (\(n, s) x ->
+ let !n' = n + 1
+ !s' = s + x
+ in (n', s'))
+ (0, 0) xs
+ mean = st / nt
+ nvar = foldl' (\v x -> let d = x - mean in v + d * d) 0 xs
+ in StdDevStatistics nt st (nvar / nt)
+
+-- | Obtain the value of a statistics.
+getStatisticValue :: Statistics -> Double
+getStatisticValue (SumStatistics s) = s
+getStatisticValue (StdDevStatistics _ _ var) = sqrt var
+
+-- | In a given statistics replace on value by another. This
+-- will only give meaningful results, if the original value
+-- was actually part of the statistics.
+updateStatistics :: Statistics -> (Double, Double) -> Statistics
+updateStatistics (SumStatistics s) (x, y) = SumStatistics $ s + (y - x)
+updateStatistics (StdDevStatistics n s var) (x, y) =
+ let !ds = y - x
+ !dss = y * y - x * x
- !dnnvar = n * dss - (2 * s + ds) * ds
++ !dnnvar = (n * dss - 2 * s * ds) - ds * ds
+ !s' = s + ds
+ !var' = max 0 $ var + dnnvar / (n * n)
+ in StdDevStatistics n s' var'
+
diff --cc test/hs/Test/Ganeti/Utils/Statistics.hs
index cefb6ff,0000000..764ebc8
mode 100644,000000..100644
--- a/test/hs/Test/Ganeti/Utils/Statistics.hs
+++ b/test/hs/Test/Ganeti/Utils/Statistics.hs
@@@ -1,65 -1,0 +1,65 @@@
+{-# LANGUAGE TemplateHaskell #-}
+
+{-| Unit tests for Ganeti statistics utils.
+
+-}
+
+{-
+
+Copyright (C) 2014 Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-}
+
+module Test.Ganeti.Utils.Statistics (testUtils_Statistics) where
+
+import Test.QuickCheck
+
+import Test.Ganeti.TestHelper
+
+import Ganeti.Utils (stdDev)
+import Ganeti.Utils.Statistics
+
+-- | Test the update function for standard deviations against the naive
+-- implementation.
+prop_stddev_update :: Property
+prop_stddev_update =
+ forAll (choose (0, 6) >>= flip vectorOf (choose (0, 1))) $ \xs ->
+ forAll (choose (0, 1)) $ \a ->
+ forAll (choose (0, 1)) $ \b ->
+ forAll (choose (1, 6) >>= flip vectorOf (choose (0, 1))) $ \ys ->
+ let original = xs ++ [a] ++ ys
+ modified = xs ++ [b] ++ ys
+ with_update = getStatisticValue
+ $ updateStatistics (getStdDevStatistics original) (a,b)
+ direct = stdDev modified
+ in printTestCase ("Value computed by update " ++ show with_update
+ ++ " differs too much from correct value " ++ show direct)
- (abs (with_update - direct) < 1e-12)
++ (abs (with_update - direct) < 1e-10)
+
+testSuite "Utils/Statistics"
+ [ 'prop_stddev_update
+ ]