Skip to content
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

Uneeded create collection operation for the not-capped case #2161

Closed
fgalan opened this issue May 4, 2022 · 1 comment
Closed

Uneeded create collection operation for the not-capped case #2161

fgalan opened this issue May 4, 2022 · 1 comment

Comments

@fgalan
Copy link
Member

fgalan commented May 4, 2022

We have

@Override
public void createCollection(String dbName, String collectionName, long dataExpiration) throws MongoException {
LOGGER.debug("Creating Mongo collection=" + collectionName + " at database=" + dbName);
MongoDatabase db = getDatabase(dbName);
// create the collection
try {
db.createCollection(collectionName);
} catch (MongoException e) {
ErrorCategory errorCategory = ErrorCategory.fromErrorCode( e.getCode() );
if (errorCategory == ErrorCategory.fromErrorCode(48)){
LOGGER.debug("Collection already exists, nothing to create");
} else {
throw e;
} // if else
} // try catch
// check STH indexes documentation at https://github.com/telefonicaid/fiware-sth-comet/blob/master/doc/manuals/db_indexes.md
BasicDBObject keys;
IndexOptions options;
try {
keys = new BasicDBObject()
.append("_id.entityId", 1)
.append("_id.entityType", 1)
.append("_id.attrName", 1)
.append("_id.resolution", 1)
.append("_id.origin", 1);
options = new IndexOptions().name("cyg_agg_opt");
db.getCollection(collectionName).createIndex(keys, options);
} catch (Exception e) {

The "create the collection block" (L99-L109) is not needed, as the createIndex() operation in L122 will automatically create the collection in this case.

(Explicit create collection is needed for capped collections, which are dealt in the other createCollection() method we have in that class)

@fgalan
Copy link
Member Author

fgalan commented May 9, 2022

Fixed in PR #2164

@fgalan fgalan closed this as completed May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant