From bddaa05935d9e66d5628f99241ee3615155acda0 Mon Sep 17 00:00:00 2001 From: Daniel Merrill Date: Fri, 13 Nov 2020 17:23:11 -0300 Subject: [PATCH] Fix search db reinstantiation and mirror bucket creation failure (#253) --- core/search/bleve/bleve.go | 13 ++++++++++++- core/textile/sync/queue.go | 7 +++++++ core/textile/sync/task-executors.go | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/search/bleve/bleve.go b/core/search/bleve/bleve.go index 9524aca2..ec2093b8 100644 --- a/core/search/bleve/bleve.go +++ b/core/search/bleve/bleve.go @@ -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 ( @@ -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 { diff --git a/core/textile/sync/queue.go b/core/textile/sync/queue.go index 62eef525..7e6651a8 100644 --- a/core/textile/sync/queue.go +++ b/core/textile/sync/queue.go @@ -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) diff --git a/core/textile/sync/task-executors.go b/core/textile/sync/task-executors.go index a5b3b2f1..33c70ba0 100644 --- a/core/textile/sync/task-executors.go +++ b/core/textile/sync/task-executors.go @@ -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 }