SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
filer mongodb insert entry and find entry
bukton3c70163798a8
diff --git a/go.mod b/go.modindex f12b58d218..2efbec9e55 100644--- a/go.mod+++ b/go.mod@@ -75,7 +75,7 @@ require (github.com/wsxiaoys/terminal v0.0.0-20160513160801-0940f3fc43a0 // indirectgo.etcd.io/bbolt v1.3.3 // indirectgo.etcd.io/etcd v3.3.15+incompatible- go.mongodb.org/mongo-driver v1.3.2 // indirect+ go.mongodb.org/mongo-driver v1.3.2go.uber.org/multierr v1.2.0 // indirectgocloud.dev v0.16.0gocloud.dev/pubsub/natspubsub v0.16.0diff --git a/weed/filer2/mongodb/mongodb_store.go b/weed/filer2/mongodb/mongodb_store.goindex 75df851729..ae76c0bf13 100644--- a/weed/filer2/mongodb/mongodb_store.go+++ b/weed/filer2/mongodb/mongodb_store.go@@ -2,8 +2,11 @@ package mongodbimport ("context"+ "fmt""github.com/chrislusf/seaweedfs/weed/filer2"+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb""github.com/chrislusf/seaweedfs/weed/util"+ "go.mongodb.org/mongo-driver/bson""go.mongodb.org/mongo-driver/mongo""go.mongodb.org/mongo-driver/mongo/options""time"@@ -14,7 +17,15 @@ func init() {}type MongodbStore struct {- connect *mongo.Client+ connect *mongo.Client+ database string+ collectionName string+}++type Model struct {+ Directory string `bson:"directory"`+ Name string `bson:"name"`+ Meta []byte `bson:"meta"`}func (store *MongodbStore) GetName() string {@@ -22,6 +33,8 @@ func (store *MongodbStore) GetName() string {}func (store *MongodbStore) Initialize(configuration util.Configuration, prefix string) (err error) {+ store.database = configuration.GetString(prefix + "database")+ store.collectionName = "filemeta"return store.connection(configuration.GetString(prefix + "uri"))}@@ -45,15 +58,55 @@ func (store *MongodbStore) RollbackTransaction(ctx context.Context) error {}func (store *MongodbStore) InsertEntry(ctx context.Context, entry *filer2.Entry) (err error) {++ dir, name := entry.FullPath.DirAndName()+ meta, err := entry.EncodeAttributesAndChunks()+ if err != nil {+ return fmt.Errorf("encode %s: %s", entry.FullPath, err)+ }++ c := store.connect.Database(store.database).Collection(store.collectionName)++ _, err = c.InsertOne(ctx, Model{+ Directory: dir,+ Name: name,+ Meta: meta,+ })++ fmt.Println(err)+return nil}func (store *MongodbStore) UpdateEntry(ctx context.Context, entry *filer2.Entry) (err error) {- return nil+ return store.UpdateEntry(ctx, entry)}func (store *MongodbStore) FindEntry(ctx context.Context, fullpath util.FullPath) (entry *filer2.Entry, err error) {- return nil, nil++ dir, name := fullpath.DirAndName()+ var data Model++ var where = bson.M{ "directory": dir, "name": name }+ err = store.connect.Database(store.database).Collection(store.collectionName).FindOne(ctx, where).Decode(&data)+ if err != mongo.ErrNoDocuments && err != nil {+ return nil, filer_pb.ErrNotFound+ }++ if len(data.Meta) == 0 {+ return nil, filer_pb.ErrNotFound+ }++ entry = &filer2.Entry{+ FullPath: fullpath,+ }++ err = entry.DecodeAttributesAndChunks(data.Meta)+ if err != nil {+ return entry, fmt.Errorf("decode %s : %v", entry.FullPath, err)+ }++ return entry, nil}func (store *MongodbStore) DeleteEntry(ctx context.Context, fullpath util.FullPath) error {