2020-04-22 01:50:30 +00:00
|
|
|
package meta_cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2/leveldb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MetaCache struct {
|
|
|
|
filer2.FilerStore
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMetaCache(dbFolder string) *MetaCache {
|
|
|
|
return &MetaCache{
|
2020-04-22 04:16:13 +00:00
|
|
|
FilerStore: openMetaStore(dbFolder),
|
2020-04-22 01:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 04:16:13 +00:00
|
|
|
func openMetaStore(dbFolder string) filer2.FilerStore {
|
2020-04-22 01:50:30 +00:00
|
|
|
|
2020-04-22 05:00:34 +00:00
|
|
|
os.RemoveAll(dbFolder)
|
2020-04-22 01:50:30 +00:00
|
|
|
os.MkdirAll(dbFolder, 0755)
|
|
|
|
|
|
|
|
store := &leveldb.LevelDBStore{}
|
2020-04-22 05:00:34 +00:00
|
|
|
config := &cacheConfig{
|
|
|
|
dir: dbFolder,
|
|
|
|
}
|
2020-04-22 01:50:30 +00:00
|
|
|
|
|
|
|
if err := store.Initialize(config, ""); err != nil {
|
|
|
|
glog.Fatalf("Failed to initialize metadata cache store for %s: %+v", store.GetName(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return store
|
|
|
|
|
2020-04-22 04:16:13 +00:00
|
|
|
}
|