Skip to content

Commit

Permalink
Fix search db reinstantiation and mirror bucket creation failure (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmerrill6 authored Nov 13, 2020
1 parent 1e2b9c6 commit bddaa05
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
13 changes: 12 additions & 1 deletion core/search/bleve/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func NewSearchEngine(opts ...Option) *bleveFilesSearchEngine {
}

func (b *bleveFilesSearchEngine) Start() error {
if b.idx != nil {
log.Warn("Trying to open already opened search index")
return nil
}

path := filepath.Join(b.opts.dbPath, DbFileName)

var (
Expand Down Expand Up @@ -184,7 +189,13 @@ func (b *bleveFilesSearchEngine) QueryFileData(
}

func (b *bleveFilesSearchEngine) Shutdown() error {
return b.idx.Close()
err := b.idx.Close()
if err != nil {
return err
}

b.idx = nil
return nil
}

func generateIndexId(name, path, bucketSlug, dbId string) string {
Expand Down
7 changes: 7 additions & 0 deletions core/textile/sync/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ func (s *synchronizer) enqueueTask(task *Task, queue *list.List) {
}
}

func (s *synchronizer) enqueueTaskAtFront(task *Task, queue *list.List) {
if s.isTaskEnqueued(task) == false {
queue.PushFront(task)
s.queueHashMap[task.ID] = task
}
}

func (s *synchronizer) dequeueTask(queue *list.List) *Task {
queueItem := queue.Front()
s.taskQueue.Remove(queueItem)
Expand Down
11 changes: 11 additions & 0 deletions core/textile/sync/task-executors.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ func (s *synchronizer) processBucketRestoreTask(ctx context.Context, task *Task)

bucket := task.Args[0]

bucketSchema, err := s.model.FindBucket(ctx, bucket)
if err != nil {
return err
}

if bucketSchema.RemoteDbID == "" {
t := newTask(createBucketTask, []string{bucket, hex.EncodeToString(bucketSchema.EncryptionKey)})
s.enqueueTaskAtFront(t, s.taskQueue)
return errors.New("trying to restore a bucket that has not been replicated. Recreating mirror bucket.")
}

if err := s.restoreBucket(ctx, bucket); err != nil {
return err
}
Expand Down

0 comments on commit bddaa05

Please sign in to comment.