Use original index type for existing shards.

pull/7976/head
Ben Johnson 2017-02-02 10:43:48 -07:00
parent c246f3d9b0
commit 76235f1e00
No known key found for this signature in database
GPG Key ID: 81741CD251883081
3 changed files with 11 additions and 15 deletions

View File

@ -92,20 +92,23 @@ func RegisteredIndexes() []string {
// NewIndex returns an instance of an index based on its format.
// If the path does not exist then the DefaultFormat is used.
func NewIndex(id uint64, path string, options EngineOptions) (Index, error) {
// Create a new index.
if _, err := os.Stat(path); os.IsNotExist(err) && options.Config.Index != "inmem" {
return newIndexFuncs[options.IndexVersion](id, path, options), nil
}
format := options.IndexVersion
// Use default format.
format := options.Config.Index
// Use default format unless existing directory exists.
_, err := os.Stat(path)
if os.IsNotExist(err) {
// nop, use default
} else if err != nil {
return nil, err
} else if err == nil {
format = "tsi1"
}
// Lookup index by format.
fn := newIndexFuncs[format]
if fn == nil {
return nil, fmt.Errorf("invalid index format: %q", format)
}
return fn(id, path, options), nil
}

View File

@ -258,14 +258,6 @@ func (s *Shard) Open() error {
// Initialize underlying index.
ipath := filepath.Join(s.path, "index")
// Create directory if this is not an in-memory index.
if s.options.IndexVersion != "inmem" {
if err := os.MkdirAll(ipath, 0700); err != nil {
return err
}
}
idx, err := NewIndex(s.id, ipath, s.options)
if err != nil {
return err

View File

@ -195,6 +195,7 @@ func (s *Store) loadShards() error {
if err != nil {
return err
}
for _, sh := range shardDirs {
n++
go func(db, rp, sh string) {