'End the active bulk write operation on structure_key (course or library key).'

def _end_outermost_bulk_operation(self, bulk_write_record, structure_key):

    dirty = False
    for _id in (bulk_write_record.structures.viewkeys() - bulk_write_record.structures_in_db):
        dirty = True
        try:
            self.db_connection.insert_structure(bulk_write_record.structures[_id], bulk_write_record.course_key)
        except DuplicateKeyError:
            log.debug('Attempted    to    insert    duplicate    structure    %s', _id)
    for _id in (bulk_write_record.definitions.viewkeys() - bulk_write_record.definitions_in_db):
        dirty = True
        try:
            self.db_connection.insert_definition(bulk_write_record.definitions[_id], bulk_write_record.course_key)
        except DuplicateKeyError:
            log.debug('Attempted    to    insert    duplicate    definition    %s', _id)
    if ((bulk_write_record.index is not None) and (bulk_write_record.index != bulk_write_record.initial_index)):
        dirty = True
        if (bulk_write_record.initial_index is None):
            self.db_connection.insert_course_index(bulk_write_record.index, bulk_write_record.course_key)
        else:
            self.db_connection.update_course_index(bulk_write_record.index, from_index=bulk_write_record.initial_index, course_context=bulk_write_record.course_key)
    return dirty
