Ejemplo n.º 1
0
func loadIndex() error {
	segm, err := gcse.IndexSegments.FindMaxDone()
	if segm == nil || err != nil {
		return err
	}

	if indexSegment != nil && !gcse.SegmentLess(indexSegment, segm) {
		// no new index
		return nil
	}

	db := &index.TokenSetSearcher{}
	f, err := segm.Join(gcse.IndexFn).Open()
	if err != nil {
		return err
	}
	defer f.Close()

	if err := db.Load(f); err != nil {
		return err
	}

	indexSegment = segm
	log.Printf("Load index from %v (%d packages)", segm, db.DocCount())

	indexDBBox.Set(db)
	updateTime := time.Now()

	if st, err := segm.Join(gcse.IndexFn).Stat(); err == nil {
		updateTime = st.ModTime()
	}

	gIndexUpdated = updateTime

	var projects villa.StrSet
	db.Search(nil, func(docID int32, data interface{}) error {
		hit := data.(gcse.HitInfo)
		projects.Put(hit.ProjectURL)
		return nil
	})
	gProjectCount = len(projects)

	db = nil
	gcse.DumpMemStats()
	runtime.GC()
	gcse.DumpMemStats()

	return nil
}
Ejemplo n.º 2
0
func loadIndex() error {
	segm, err := gcse.IndexSegments.FindMaxDone()
	if segm == nil || err != nil {
		return err
	}

	if indexSegment != nil && !gcse.SegmentLess(indexSegment, segm) {
		// no new index
		return nil
	}

	db := &index.TokenSetSearcher{}
	f, err := segm.Join(gcse.IndexFn).Open()
	if err != nil {
		return err
	}
	defer f.Close()

	if err := db.Load(f); err != nil {
		return err
	}

	indexSegment = segm
	log.Printf("Load index from %v (%d packages)", segm, db.DocCount())

	indexDBBox.Set(db)
	updateTime := time.Now()

	if st, err := segm.Join(gcse.IndexFn).Stat(); err == nil {
		updateTime = st.ModTime()
	}

	indexUpdated = updateTime

	db = nil
	gcse.DumpMemStats()
	runtime.GC()
	gcse.DumpMemStats()

	return nil
}
Ejemplo n.º 3
0
func loadIndex() error {
	segm, err := gcse.IndexSegments.FindMaxDone()
	if segm == nil || err != nil {
		return err
	}
	if indexSegment != nil && !gcse.SegmentLess(indexSegment, segm) {
		// no new index
		return nil
	}
	db := &searcherDB{}
	if err := func() error {
		f, err := segm.Join(gcse.IndexFn).Open()
		if err != nil {
			return err
		}
		defer f.Close()

		return db.ts.Load(f)
	}(); err != nil {
		return err
	}
	db.storeDB = &bh.RefCountBox{
		DataPath: func() string {
			return segm.Join(configs.FnStore).S()
		},
	}
	hitsPath := segm.Join(gcse.HitsArrFn)
	if db.hits, err = index.OpenConstArray(hitsPath.S()); err != nil {
		log.Printf("OpenConstArray %v failed: %v", hitsPath, err)
		return err
	}
	// Calculate db.projectCount
	var projects stringsp.Set
	db.ts.Search(nil, func(docID int32, data interface{}) error {
		hit := data.(gcse.HitInfo)
		projects.Add(hit.ProjectURL)
		return nil
	})
	db.projectCount = len(projects)
	gcse.AddBiValueAndProcess(bi.Max, "index.proj-count", db.projectCount)

	// Update db.indexUpdated
	db.indexUpdated = time.Now()
	if st, err := segm.Join(gcse.IndexFn).Stat(); err == nil {
		db.indexUpdated = st.ModTime()
	}
	indexSegment = segm
	log.Printf("Load index from %v (%d packages)", segm, db.PackageCount())

	// Exchange new/old database and close the old one.
	oldDB := getDatabase()
	databaseValue.Store(db)
	oldDB.Close()
	oldDB = nil
	gcse.DumpMemStats()

	runtime.GC()
	gcse.DumpMemStats()

	return nil
}