Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,8 @@ type TrainableIndex interface {
Index
Train(*Batch) error
}

type IndexFileCopyable interface {
Comment thread
abhinavdangeti marked this conversation as resolved.
SetPathInBolt(key []byte, value []byte) error //dest index
CopyFile(file string, d index.IndexDirectory) error // source index
}
4 changes: 0 additions & 4 deletions index/scorch/persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,6 @@ func zapFileName(epoch uint64) string {
return fmt.Sprintf("%012x.zap", epoch)
}

func (s *Scorch) loadTrainedData(bucket *bolt.Bucket) error {
return s.trainer.loadTrainedData(bucket)
}

// bolt snapshot code

func (s *Scorch) loadFromBolt() error {
Expand Down
28 changes: 28 additions & 0 deletions index/scorch/scorch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -470,6 +471,24 @@ func (s *Scorch) Delete(id string) error {
return s.Batch(b)
}

func (s *Scorch) isTrained(batch *index.Batch) (bool, error) {
trained := true
if len(batch.IndexOps) > 0 && s.trainer != nil {
val, err := s.getInternal(util.BoltTrainCompleteKey)
if err != nil {
return false, err
}

if val != nil {
trained, err = strconv.ParseBool(string(val))
if err != nil {
return false, err
}
}
}
return trained, nil
}

// Batch applices a batch of changes to the index atomically
func (s *Scorch) Batch(batch *index.Batch) (err error) {
start := time.Now()
Expand All @@ -480,6 +499,15 @@ func (s *Scorch) Batch(batch *index.Batch) (err error) {
s.fireEvent(EventKindBatchIntroduction, time.Since(start))
}()

trained, err := s.isTrained(batch)
if err != nil {
return err
}

if !trained {
return fmt.Errorf("index is not trained yet")
}

resultChan := make(chan index.Document, len(batch.IndexOps))

var numUpdates uint64
Expand Down
3 changes: 3 additions & 0 deletions index/scorch/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type Stats struct {
MaxMemMergeZapTime uint64
TotMemMergeSegments uint64
TotMemorySegmentsAtRoot uint64

TotTrainedSamples uint64
TotTrainTime uint64
Comment thread
abhinavdangeti marked this conversation as resolved.
}

// atomically populates the returned map
Expand Down
Loading
Loading