-
Notifications
You must be signed in to change notification settings - Fork 104
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
Remove dataExpiration from createCollection (capped collection one) (mongo) #2159
Comments
I understand that all the calls to that createCollection() method use |
Cygnus is creating a capped collection just when: Lines 153 to 158 in d7a962a
I'm afraid that If just one of these options are provide then nothing is done
Maybe these documentation should be updated to reflect that both options should be provided with a value >0 to achieve that. According with mongo driver java: sizeInBytes(long sizeInBytes) maxDocuments(long maxDocuments) sizeInBytes does get? |
But using this sink config cygnus-ngsi.sinks.sth-sink.data_expiration = 10000 No errors are reported when createCollection (capped + creaetIndex): time=2022-05-03T14:21:30.986Z | lvl=DEBUG | corr=84f26ad1-8203-4e01-8506-dbed42cd5376; cbnotif=1 | trans=85b8945a-3c5f-49d6-8039-2323e239610d | srv=N/A | subsrv=N/A | comp=cygnus-ngsi | op=createCollection | msg=com.telefonica.iot.cygnus.backends.mongo.MongoBackendImpl[158] : Creating Mongo collection=sth_/device:dispAVG2_device at database=sth_smartcity with collections_size=100000 and max_documents=1000 options |
According with https://www.mongodb.com/docs/manual/tutorial/expire-data/ To create a TTL index, use the db.collection.createIndex() method with the expireAfterSeconds option on a field whose value is either a date or an array that contains date values. But currently cygnus is using: Line 129 in d7a962a
expireAfterSeconds != expireAfter |
We have checked in a CB-Cygnus-MongoDB scenario that the expiration index is created without problems. An isolate test using only MongoDB and the mongo shell has been done also to confirm that. Maybe there is a docu-bug in MongoDB official documentation. I have created the issue https://jira.mongodb.org/browse/DOCS-15313 trying to clarify it with MongoDB team. I suggest to keep this issue on hold while we get feedback from MongoDB team. |
With regards to the block: if (collectionsSize != 0 && maxDocuments != 0) {
CreateCollectionOptions options = new CreateCollectionOptions()
.capped(true)
.sizeInBytes(collectionsSize)
.maxDocuments(maxDocuments);
LOGGER.debug("Creating Mongo collection=" + collectionName + " at database=" + dbName + " with "
+ "collections_size=" + collectionsSize + " and max_documents=" + maxDocuments + " options");
db.createCollection(collectionName, options);
} It's not correct, as both collectionSize and maxDocuments can be used idependently, according to MongoDB documentation at https://www.mongodb.com/docs/manual/reference/method/db.createCollection/#mongodb-method-db.createCollection: So I'd suggest to use independent conditions and include a link to MongoDB documentation from Cygnus documentation in the case users want to know how to use them (e.g. which one takes preference over the other, etc.). |
related #2163 |
From MongoDB JIRA ticket:
Thus, it seems that TTL indexes can be created in capped collection, but they don't achieve the desire effect (in other words, they are useless). So, the question is:
In my opinion it's better option 1. Having an index that doesn't work as expected can be confusing for users without expertise in MongoDB. |
https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java
The dataExpiration parameters (and associtted logic in the function) should be removed, as, according to MongoDB documentation on capped collections (https://www.mongodb.com/docs/manual/core/capped-collections/):
The text was updated successfully, but these errors were encountered: