Example #1
0
        /// <summary>Wait for a quorum of loggers to respond to the given call.</summary>
        /// <remarks>
        /// Wait for a quorum of loggers to respond to the given call. If a quorum
        /// can't be achieved, throws a QuorumException.
        /// </remarks>
        /// <param name="q">the quorum call</param>
        /// <param name="timeoutMs">the number of millis to wait</param>
        /// <param name="operationName">textual description of the operation, for logging</param>
        /// <returns>a map of successful results</returns>
        /// <exception cref="QuorumException">if a quorum doesn't respond with success</exception>
        /// <exception cref="System.IO.IOException">if the thread is interrupted or times out
        ///     </exception>
        internal virtual IDictionary <AsyncLogger, V> WaitForWriteQuorum <V>(QuorumCall <AsyncLogger
                                                                                         , V> q, int timeoutMs, string operationName)
        {
            int majority = GetMajoritySize();

            try
            {
                q.WaitFor(loggers.Count, majority, majority, timeoutMs, operationName);
            }
            catch (Exception)
            {
                // either all respond
                // or we get a majority successes
                // or we get a majority failures,
                Sharpen.Thread.CurrentThread().Interrupt();
                throw new IOException("Interrupted waiting " + timeoutMs + "ms for a " + "quorum of nodes to respond."
                                      );
            }
            catch (TimeoutException)
            {
                throw new IOException("Timed out waiting " + timeoutMs + "ms for a " + "quorum of nodes to respond."
                                      );
            }
            if (q.CountSuccesses() < majority)
            {
                q.RethrowException("Got too many exceptions to achieve quorum size " + GetMajorityString
                                       ());
            }
            return(q.GetResults());
        }