func newBarrier(count uint) *barrier {
	result := &barrier{inCh: make(chan bool), outCh: make(chan bool)}
	go result.loop(count)
	return result
}
newBarrier creates a new barrier. count is N.
package pstore
import (
	"github.com/Symantec/scotty/store"
	"github.com/Symantec/tricorder/go/tricorder/duration"
	"regexp"
	"time"
)
const (
	kDefaultBufferSize = 1000
)
type hookWriter struct {
	wrapped RecordWriter
	hooks   []RecordWriteHooker
}
func (h *hookWriter) Write(records []Record) error {
	result := h.wrapped.Write(records)
	for _, hook := range h.hooks {
		hook.WriteHook(records, result)
	}
	return result
}
type throttleWriter struct {
	wrapped          RecordWriter
	recordsPerSecond uint
}
func (t *throttleWriter) Write(records []Record) error {
	if t.recordsPerSecond == 0 {
		return t.wrapped.Write(records)
	}
	now := time.Now()
	result := t.wrapped.Write(records)
	throttleDuration := time.Second * time.Duration(len(records)) / time.Duration(t.recordsPerSecond)
	timeToBeDone := now.Add(throttleDuration)
	now = time.Now()
	if now.Before(timeToBeDone) {
		time.Sleep(timeToBeDone.Sub(now))
	}
	return result
}
func (w *RecordWriterWithMetrics) write(records []Record) error {
	if !w.criticalSection.Enter() {
		return ErrDisabled
	}
	defer w.criticalSection.Exit()
	ctime := time.Now()
	result := w.W.Write(records)
	timeTaken := time.Now().Sub(ctime)
	if result == nil {
		w.logWrite(uint(len(records)), timeTaken)
	} else {
		w.logWriteError(
			uint(len(records)), result, timeTaken)
	}
	return result
}
func (w *RecordWriterWithMetrics) setMetrics(m *RecordWriterMetrics) {
	temp := *m
	w.lock.Lock()
	defer w.lock.Unlock()
	temp.Paused = w.metrics.Paused
	temp.Disabled = w.metrics.Disabled
	w.metrics = temp
}
func (w *RecordWriterWithMetrics) _metrics(m *RecordWriterMetrics) {
	w.lock.Lock()
	defer w.lock.Unlock()
	*m = w.metrics
}
func (w *RecordWriterWithMetrics) logWrite(
	batchSize uint, timeTaken time.Duration) {
	w.logDistributions(batchSize, timeTaken)
	w.lock.Lock()
	defer w.lock.Unlock()
	w.metrics.logWrite(batchSize, timeTaken)
}
func (w *RecordWriterWithMetrics) logWriteError(
	batchSize uint, err error, timeTaken time.Duration) {
	w.logDistributions(batchSize, timeTaken)
	w.Logger.Printf("Error writing to persistent store: %v", err)
	w.lock.Lock()
	defer w.lock.Unlock()
	w.metrics.logWriteError(err.Error(), timeTaken)
}
func (w *RecordWriterWithMetrics) setPauseMetric(paused bool) {
	w.lock.Lock()
	defer w.lock.Unlock()
	w.metrics.Paused = paused
}
func (w *RecordWriterWithMetrics) setDisabledMetric(b bool) {
	w.lock.Lock()
	defer w.lock.Unlock()
	w.metrics.Disabled = b
}
func (w *RecordWriterWithMetrics) logDistributions(
	batchSize uint, timeTaken time.Duration) {
	if w.PerMetricWriteTimes != nil {
		w.PerMetricWriteTimes.Add(
			timeTaken / time.Duration(batchSize))
	}
	if w.BatchSizes != nil {
		w.BatchSizes.Add(float64(batchSize))
	}
}
func (w *RecordWriterMetrics) logWrite(
	batchSize uint, timeTaken time.Duration) {
	w.ValuesWritten += uint64(batchSize)
	w.WriteAttempts += 1
	w.SuccessfulWrites += 1
	w.LastSuccessfulWriteTS = time.Now()
	w.TimeSpentWriting += timeTaken
}
func (w *RecordWriterMetrics) logWriteError(err string, timeTaken time.Duration) {
	w.WriteAttempts += 1
	w.LastWriteError = err
	w.LastWriteErrorTS = time.Now()
	w.TimeSpentWriting += timeTaken
}
type consumerRequestType struct {
	Iterator store.NamedIterator
	HostName string
	TagGroup TagGroup
}
type barrier struct {
	inCh  chan bool
	outCh chan bool
}