Skip to content

Commit

Permalink
fix(search): don't delete virtual folder while update indexes (close A…
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Dec 11, 2022
1 parent 1640f06 commit 5043815
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/op/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func GetAllStorages() []driver.Driver {
return storagesMap.Values()
}

func HasStorage(mountPath string) bool {
return storagesMap.Has(mountPath)
}

func GetStorageByVirtualPath(virtualPath string) (driver.Driver, error) {
storageDriver, ok := storagesMap.Load(virtualPath)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/search/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func Update(parent string, objs []model.Obj) {
toDelete := old.Difference(now)
toAdd := now.Difference(old)
for i := range nodes {
if toDelete.Contains(nodes[i].Name) {
if toDelete.Contains(nodes[i].Name) && !op.HasStorage(path.Join(parent, nodes[i].Name)) {
log.Debugf("delete index: %s", path.Join(parent, nodes[i].Name))
err = instance.Del(ctx, path.Join(parent, nodes[i].Name))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/search/searcher/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Searcher interface {
Search(ctx context.Context, req model.SearchReq) ([]model.SearchNode, int64, error)
// Index obj with parent
Index(ctx context.Context, node model.SearchNode) error
// Index obj with parent in batches
// BatchIndex obj with parent
BatchIndex(ctx context.Context, nodes []model.SearchNode) error
// Get by parent
Get(ctx context.Context, parent string) ([]model.SearchNode, error)
Expand Down
5 changes: 5 additions & 0 deletions pkg/generic_sync/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func (m *MapOf[K, V]) Load(key K) (value V, ok bool) {
return e.load()
}

func (m *MapOf[K, V]) Has(key K) bool {
_, ok := m.Load(key)
return ok
}

func (e *entry[V]) load() (value V, ok bool) {
p := atomic.LoadPointer(&e.p)
if p == nil || p == expunged {
Expand Down

0 comments on commit 5043815

Please sign in to comment.