Ejemplo n.º 1
0
func (p *MockRandomMergePolicy) FindMerges(mergeTrigger MergeTrigger,
	segmentInfos *SegmentInfos, writer *IndexWriter) (MergeSpecification, error) {

	var segments []*SegmentCommitInfo
	merging := writer.MergingSegments()

	for _, sipc := range segmentInfos.Segments {
		if _, ok := merging[sipc]; !ok {
			segments = append(segments, sipc)
		}
	}

	var merges []*OneMerge
	if n := len(segments); n > 1 && (n > 30 || p.random.Intn(5) == 3) {
		segments2 := make([]*SegmentCommitInfo, len(segments))
		for i, v := range p.random.Perm(len(segments)) {
			segments2[i] = segments[v]
		}
		segments = segments2

		// TODO: sometimes make more than 1 merge?
		segsToMerge := tu.NextInt(p.random, 1, n)
		if p.doNonBulkMerges {
			panic("not implemented yet")
		} else {
			merges = append(merges, NewOneMerge(segments[:segsToMerge]))
		}
	}
	return MergeSpecification(merges), nil
}
Ejemplo n.º 2
0
func NewAlcoholicMergePolicy( /*tz TimeZone, */ r *rand.Rand) *AlcoholicMergePolicy {
	now := time.Now()
	mp := &AlcoholicMergePolicy{
		NewLogMergePolicy(0, int64(tu.NextInt(r, 1024*1024, int(math.MaxInt32)))), r}
	mp.Size = func(info *SegmentInfoPerCommit) (int64, error) {
		n, err := info.SizeInBytes()
		if hour := now.Hour(); err == nil && (hour < 6 || hour > 20 ||
			mp.random.Intn(23) == 5) { // it's 5 o'clock somewhere
			// pick a random drink during the day
			return drinks[r.Intn(5)] * n, nil
		}
		return n, err
	}
	return mp
}
Ejemplo n.º 3
0
func NewAlcoholicMergePolicy( /*tz TimeZone, */ r *rand.Rand) *AlcoholicMergePolicy {
	mp := &AlcoholicMergePolicy{
		NewLogMergePolicy(0, int64(tu.NextInt(r, 1024*1024, int(math.MaxInt32)))), r}
	mp.SizeSPI = mp
	return mp
}