-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add mongodb implementation for the db package #1089
Conversation
c83dc63
to
fbebe9c
Compare
f2bc278
to
34650cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, though I'm not familiar with mongo, and I have no idea how performant this might be. If it's over the network, compared to pebble or leveldb on disk, we might see significantly worse performance just due to the round-trip nature of the network.
db/mongodb/mongodb.go
Outdated
|
||
filter := bson.M{} | ||
if len(prefix) > 0 { | ||
filter = bson.M{"_id": bson.M{"$regex": primitive.Regex{Pattern: "^" + string(prefix)}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how slow this might be...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope mongo people made it efficient enough :/ But there is not other way, I have been looking for a better (non string regex bassed) mechanism, but there is nothing we can use.
db/mongodb/mongodb.go
Outdated
primitive.E{Key: "value", Value: v}, | ||
}}, | ||
} | ||
model := mongo.NewUpdateOneModel().SetFilter(bson.D{primitive.E{Key: "_id", Value: string(k)}}).SetUpsert(true).SetUpdate(update) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the point of a WriteTx is to bulk/batch writes; why are you using NewUpdateOneModel instead of NewUpdateManyModel? note that I'm not familiar with how mongo works at all, just wondering outloud.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the strategy is to accumulate single model updates in the memory batch.
Then on commit, I use collection.BulkWrite() that takes as parameter a list of models to apply.
This is the way it usually works for mongo, at least what I found it in the official docs.
The db interface has now an implementation for mongodb. So instead of pebble a user or consumer of the vocdoni-node API can choose to use mongodb. Its not faster than local KV, but useful when the host runing the database has no persistent storage available, so a remote storage is required. The mongodb url must be set on a env var, such as: MONGODB_URL="mongodb://root:vocdoni@localhost:27017/" go run ./cmd/node -t mongodb -c dev Signed-off-by: p4u <[email protected]>
34650cd
to
fe6e09a
Compare
The db interface has now an implementation for mongodb. So instead of pebble a user or consumer of the vocdoni-node API can choose to use mongodb. Its not faster than local KV, but useful when the host runing the database has no persistent storage available, so a remote storage is required.
The mongodb url must be set on a env var, such as:
MONGODB_URL="mongodb://root:vocdoni@localhost:27017/" go run ./cmd/node -t mongodb -c dev