Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-4202 make the ft reindex logic atomic #1651

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions core/indexer/fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,16 @@ func (i *indexer) ftInit() error {
return err
}
if docCount == 0 {
// query objects that are existing in the store
// if they are not existing in the object store, they will be indexed and added via reindexOutdatedObjects or on receiving via any-sync
ids, err := i.store.ListIdsCrossSpace()
if err != nil {
return err
}
for _, id := range ids {
if err := i.store.AddToIndexQueue(i.runCtx, id); err != nil {
return err
}
if err := i.store.AddToIndexQueue(i.runCtx, ids...); err != nil {
return err
}

}
}
return nil
Expand Down
19 changes: 14 additions & 5 deletions pkg/lib/localstore/objectstore/indexer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ import (
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
)

func (s *dsObjectStore) AddToIndexQueue(ctx context.Context, id string) error {
func (s *dsObjectStore) AddToIndexQueue(ctx context.Context, ids ...string) error {
txn, err := s.fulltextQueue.WriteTx(ctx)
if err != nil {
return fmt.Errorf("start write tx: %w", err)
}
arena := s.arenaPool.Get()
defer func() {
arena.Reset()
s.arenaPool.Put(arena)
}()
obj := arena.NewObject()
obj.Set("id", arena.NewString(id))

_, err := s.fulltextQueue.UpsertOne(ctx, obj)
return err
obj := arena.NewObject()
for _, id := range ids {
obj.Set("id", arena.NewString(id))
requilence marked this conversation as resolved.
Show resolved Hide resolved
_, err = s.fulltextQueue.UpsertOne(txn.Context(), obj)
if err != nil {
return fmt.Errorf("upsert: %w", err)
}
}
return txn.Commit()
}

func (s *dsObjectStore) BatchProcessFullTextQueue(ctx context.Context, limit int, processIds func(ids []string) error) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/localstore/objectstore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ObjectStore interface {
}

type IndexerStore interface {
AddToIndexQueue(ctx context.Context, id string) error
AddToIndexQueue(ctx context.Context, id ...string) error
ListIdsFromFullTextQueue(limit int) ([]string, error)
RemoveIdsFromFullTextQueue(ids []string) error
GetGlobalChecksums() (checksums *model.ObjectStoreChecksums, err error)
Expand Down
8 changes: 5 additions & 3 deletions pkg/lib/localstore/objectstore/spaceindex/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ func (q *dummyFulltextQueue) RemoveIdsFromFullTextQueue(ids []string) error {
return nil
}

func (q *dummyFulltextQueue) AddToIndexQueue(ctx context.Context, id string) error {
func (q *dummyFulltextQueue) AddToIndexQueue(ctx context.Context, ids ...string) error {
q.lock.Lock()
defer q.lock.Unlock()
if !lo.Contains(q.ids, id) {
q.ids = append(q.ids, id)
for _, id := range ids {
if !lo.Contains(q.ids, id) {
q.ids = append(q.ids, id)
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/localstore/objectstore/spaceindex/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type SourceDetailsFromID interface {

type FulltextQueue interface {
RemoveIdsFromFullTextQueue(ids []string) error
AddToIndexQueue(ctx context.Context, id string) error
AddToIndexQueue(ctx context.Context, ids ...string) error
ListIdsFromFullTextQueue(limit int) ([]string, error)
}

Expand Down
Loading