Add support for distributed filer metadata store.

This commit is contained in:
Chris Lu
2015-01-05 23:03:27 -08:00
parent 165734ce11
commit 49784d7f28
9 changed files with 197 additions and 11 deletions

View File

@@ -5,7 +5,9 @@ import (
"strconv"
"github.com/chrislusf/weed-fs/go/filer"
"github.com/chrislusf/weed-fs/go/filer/cassandra_store"
"github.com/chrislusf/weed-fs/go/filer/embedded_filer"
"github.com/chrislusf/weed-fs/go/filer/flat_namespace"
"github.com/chrislusf/weed-fs/go/glog"
)
@@ -18,8 +20,9 @@ type FilerServer struct {
filer filer.Filer
}
func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
func NewEmbeddedFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
replication string, redirectOnRead bool,
cassandra_server string, cassandra_keyspace string,
) (fs *FilerServer, err error) {
fs = &FilerServer{
master: master,
@@ -29,12 +32,21 @@ func NewFilerServer(r *http.ServeMux, port int, master string, dir string, colle
port: ":" + strconv.Itoa(port),
}
if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {
glog.Fatal("Can not start filer in dir", dir, ": ", err.Error())
return
if cassandra_server == "" {
if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {
glog.Fatalf("Can not start filer in dir %s : %v", err)
return
}
r.HandleFunc("/admin/mv", fs.moveHandler)
} else {
cassandra_store, err := cassandra_store.NewCassandraStore(cassandra_keyspace, cassandra_server)
if err != nil {
glog.Fatalf("Can not connect to cassandra server %s with keyspace %s: %v", cassandra_server, cassandra_keyspace, err)
}
fs.filer = flat_namespace.NewFlatNamesapceFiler(master, cassandra_store)
}
r.HandleFunc("/admin/mv", fs.moveHandler)
r.HandleFunc("/", fs.filerHandler)
return fs, nil

View File

@@ -179,7 +179,7 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
glog.V(4).Infoln("saving", path, "=>", assignResult.Fid)
if db_err := fs.filer.CreateFile(path, assignResult.Fid); db_err != nil {
operation.DeleteFile(fs.master, assignResult.Fid) //clean up
glog.V(0).Infoln("failing to write to filer server", r.RequestURI, db_err.Error())
glog.V(0).Infof("failing to write %s to filer server : %v", path, db_err)
writeJsonError(w, r, db_err)
return
}