Example #1
0
func (s *StaticTable) initialize(schema *Schema) error {
	s.Schema = schema
	s.wg = new(sync.WaitGroup)

	// Load dimension tables
	for i, col := range schema.DimensionColumns {
		if !col.String {
			continue
		}
		if err := s.DimensionTables[i].Load(schema, i); err != nil {
			return err
		}
	}

	// Load each interval/segment
	for _, interval := range s.Intervals {
		interval.Segments = make([]*Segment, interval.NumSegments)
		for i := 0; i < interval.NumSegments; i++ {

			f, err := os.Open(interval.SegmentFilename(schema, i))
			if err != nil {
				return err
			}
			mapped, err := mmap.Map(f, mmap.RDONLY, 0)
			if err != nil {
				return err
			}
			interval.Segments[i] = &Segment{File: f, Bytes: mapped}
		}
	}

	return nil
}
Example #2
0
// freeze opens segment files as readonly mmaps and returns an immutable *Interval. iv should not be used
// after calling freeze.
func (iv *writeOnlyInterval) freeze(s *Schema) (*Interval, error) {
	if err := iv.closeCurrentSegment(); err != nil {
		return nil, err
	}

	iv.Segments = make([]*Segment, iv.NumSegments)
	for i := 0; i < iv.NumSegments; i++ {
		if !iv.DiskBacked {
			iv.Segments[i] = &Segment{Bytes: iv.buffers[i].Bytes()}
			continue
		}
		filename := iv.SegmentFilename(s, i)
		f, err := os.Open(filename)
		if err != nil {
			return nil, err
		}
		mapped, err := mmap.Map(f, mmap.RDONLY, 0)
		if err != nil {
			return nil, err
		}
		iv.Segments[i] = &Segment{File: f, Bytes: mapped}
	}
	return &iv.Interval, nil
}