Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ dependencies:
# We install and test with all the supported MongoDB versions
- case $CIRCLE_NODE_INDEX in [1,2]) sudo service mongodb stop ; MONGODB_VERSION=3.2.12 sudo -E .circle/install-and-run-mongodb.sh > /tmp/mongodb-install.log 2>&1 ;; [3,4]) sudo service mongodb stop ; MONGODB_VERSION=3.4.2 sudo -E .circle/install-and-run-mongodb.sh > /tmp/mongodb-install.log 2>&1 ;; esac:
background: true
# We sleep a bit to wait for the background process to start and script to
# finish
- case $CIRCLE_NODE_INDEX in [1,2]) sleep 10 ;; esac
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just make it a part of the previous line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly no because it runs in a background (background: true) and that's why we need it to be a separate step.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the next one? =)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can but I prefer separate lines to make it more readable (flow it's more sequential).

I already hate all the case lines which make it hard to read and follow so I plan to look into circleci-matrix or similar solution in the future so we can at the very least keep circle.yml more sane.

# Tail the logs so it's easier to see what is going on. Sadly when using "background: true"
# whole output is ignored.
- case $CIRCLE_NODE_INDEX in [1,2]) tail -50 /tmp/mongodb-install.log ;; [3,4]) tail -50 /tmp/mongodb-install.log ;; esac
Expand Down
37 changes: 37 additions & 0 deletions st2common/st2common/models/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ def db_ensure_indexes():

try:
model_class.ensure_indexes()
except OperationFailure as e:
# Special case for "uid" index. MongoDB 3.4 has dropped "_types" index option so we
# need to re-create the index to make it work and avoid "index with different options
# already exists" error.
# Note: This condition would only be encountered when upgrading existing StackStorm
# installation from MongoDB 3.2 to 3.4.
msg = str(e)
if 'already exists with different options' in msg and 'uid_1' in msg:
drop_obsolete_types_indexes(model_class=model_class)
else:
raise e
except Exception as e:
tb_msg = traceback.format_exc()
msg = 'Failed to ensure indexes for model "%s": %s' % (class_name, str(e))
Expand Down Expand Up @@ -157,6 +168,32 @@ def cleanup_extra_indexes(model_class):
return removed_count


def drop_obsolete_types_indexes(model_class):
"""
Special class for droping offending "types" indexes for which support has
been removed in mongoengine and MongoDB 3.4.
For more info, see: http://docs.mongoengine.org/upgrade.html#inheritance
"""
class_name = model_class.__name__

LOG.debug('Dropping obsolete types index for model "%s"' % (class_name))
collection = model_class._get_collection()
collection.update({}, {'$unset': {'_types': 1}}, multi=True)

info = collection.index_information()
indexes_to_drop = [key for key, value in info.iteritems()
if '_types' in dict(value['key']) or 'types' in value]

LOG.debug('Will drop obsolete types indexes for model "%s": %s' % (class_name,
str(indexes_to_drop)))

for index in indexes_to_drop:
collection.drop_index(index)

LOG.debug('Recreating indexes for model "%s"' % (class_name))
model_class.ensure_indexes()


def db_teardown():
mongoengine.connection.disconnect()

Expand Down