Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Be more specific about which capped references to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Cowling committed Feb 18, 2014
1 parent 5e1b629 commit 84bd7e6
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions migrations/009_add_cap_to_realtime_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,27 @@ def get_realtime_collection_names(db):
if name.endswith("realtime")]


def remove_all_capped_references(db):
def get_all_capped_collections(db):
mongo_db = db._mongo['backdrop']
return [name for name in mongo_db.collection_names()
if mongo_db[name].options().get('capped') is True]


def remove_all_capped_references(db, capped_collections):
mongo_db = db._mongo['backdrop']
for record in mongo_db['buckets'].find():
# log.info("item {0}".format(record))
mongo_db['buckets'].update(
{"name": record['name']},
{"$set":
{
"capped_size": None,
}
},
upsert=False,
multi=False)
if record['name'] not in capped_collections:
log.info(
"Removing the cap reference for {0}".format(record['name']))
mongo_db['buckets'].update(
{"name": record['name']},
{"$set":
{
"capped_size": None,
}
},
upsert=False,
multi=False)


def remove_old_versions(db, collection_name):
Expand Down Expand Up @@ -107,8 +115,9 @@ def up(db):
mongo_db = db._mongo['backdrop']

# To start off, get rid of all references to caps in the metadata,
# because they were all wrong
remove_all_capped_references(db)
# if the collections they reference are not actually capped
all_capped = get_all_capped_collections(db)
remove_all_capped_references(db, all_capped)

realtime_collections_names = get_realtime_collection_names(db)

Expand Down

0 comments on commit 84bd7e6

Please sign in to comment.