这是indexloc提供的服务,不要输入任何密码
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 metastore/metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func (m *Metastore) TouchShardMetadata(indexName string, shardName string) error
}

func (m *Metastore) DeleteIndexMetadata(indexName string) error {

indexMetadata, err := m.GetIndexMetadata(indexName)
if err != nil {
m.logger.Error(err.Error(), zap.String("index_name", indexName))
Expand Down Expand Up @@ -458,6 +459,10 @@ func (m *Metastore) DeleteIndexMetadata(indexName string) error {
return err
}

m.mutex.Lock()
delete(m.indexMetadataMap, indexName)
defer m.mutex.Unlock()

return nil
}

Expand Down
32 changes: 26 additions & 6 deletions metastore/storage_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,24 @@ func NewFileSystemStorageWithPath(path string, logger *zap.Logger) (*FileSystemS
switch {
case event.Op&fsnotify.Create == fsnotify.Create:
storageEvent.Type = StorageEventTypePut
if util.IsFile(event.Name) {
content, err := ioutil.ReadFile(event.Name)
if err != nil {
logger.Error(err.Error(), zap.String("path", event.Name))
continue
}
storageEvent.Value = content
}
case event.Op&fsnotify.Write == fsnotify.Write:
storageEvent.Type = StorageEventTypePut
if util.IsFile(event.Name) {
content, err := ioutil.ReadFile(event.Name)
if err != nil {
logger.Error(err.Error(), zap.String("path", event.Name))
continue
}
storageEvent.Value = content
}
case event.Op&fsnotify.Remove == fsnotify.Remove:
storageEvent.Type = StorageEventTypeDelete
case event.Op&fsnotify.Rename == fsnotify.Rename:
Expand Down Expand Up @@ -183,19 +199,15 @@ func (m *FileSystemStorage) Put(path string, content []byte) error {

fullPath := filepath.Join(m.path, path)

m.logger.Info("put", zap.String("path", fullPath))

// Create directory.
dir := filepath.Dir(fullPath)
if err := os.MkdirAll(dir, 0700); err != nil {
m.logger.Error(err.Error(), zap.String("path", dir))
return err
}

// Write file.
if err := ioutil.WriteFile(fullPath, content, 0600); err != nil {
m.logger.Error(err.Error(), zap.String("path", fullPath))
return err
}

// Add the created path to the watch list.
// Do not add m.path to watchSet twice.
watchDir := filepath.Dir(fullPath)
Expand All @@ -208,6 +220,12 @@ func (m *FileSystemStorage) Put(path string, content []byte) error {
m.watchSet[watchDir] = true
}

// Write file.
if err := ioutil.WriteFile(fullPath, content, 0600); err != nil {
m.logger.Error(err.Error(), zap.String("path", fullPath))
return err
}

return nil
}

Expand All @@ -217,6 +235,8 @@ func (m *FileSystemStorage) Delete(path string) error {

fullPath := filepath.Join(m.path, path)

m.logger.Info("delete", zap.String("path", fullPath))

// Remove file.
if err := os.Remove(fullPath); err != nil {
m.logger.Error(err.Error(), zap.String("path", fullPath))
Expand Down