Esempio n. 1
0
def generate_shard_prune_playbook(migration):
    """Create a playbook for deleting unused files.
    :returns: List of nodes that have files to remove
    """
    # get shard allocation from DB directly instead of using plan in case they are different
    full_plan = get_db_allocations(migration.target_couch_config)
    shard_suffix_by_db = {
        db_name: shard_allocation_doc.usable_shard_suffix
        for db_name, shard_allocation_doc in full_plan.items()
    }
    _, deletable_files_by_node = figure_out_what_you_can_and_cannot_delete(
        full_plan, shard_suffix_by_db)
    if not any(deletable_files_by_node.values()):
        return None

    deletable_files_by_node = {
        node.split('@')[1]: files
        for node, files in deletable_files_by_node.items() if files
    }
    prune_playbook = render_template(
        'prune.yml.j2', {
            'deletable_files_by_node': deletable_files_by_node,
            'couch_data_dir': migration.couchdb2_data_dir
        }, TEMPLATE_DIR)
    with open(migration.prune_playbook_path, 'w', encoding='utf-8') as f:
        f.write(prune_playbook)

    return list(deletable_files_by_node)
Esempio n. 2
0
def generate_shard_prune_playbook(migration):
    """Create a playbook for deleting unused files.
    :returns: List of nodes that have files to remove
    """
    # get shard allocation from DB directly instead of using plan in case they are different
    full_plan = get_db_allocations(migration.target_couch_config)
    shard_suffix_by_db = {
        db_name: shard_allocation_doc.usable_shard_suffix
        for db_name, shard_allocation_doc in full_plan.items()
    }
    _, deletable_files_by_node = figure_out_what_you_can_and_cannot_delete(full_plan, shard_suffix_by_db)
    if not any(deletable_files_by_node.values()):
        return None

    deletable_files_by_node = {
        node.split('@')[1]: files
        for node, files in deletable_files_by_node.items()
        if files
    }
    prune_playbook = render_template('prune.yml.j2', {
        'deletable_files_by_node': deletable_files_by_node,
        'couch_data_dir': migration.couchdb2_data_dir
    }, TEMPLATE_DIR)
    with open(migration.prune_playbook_path, 'w') as f:
        f.write(prune_playbook)

    return list(deletable_files_by_node)
Esempio n. 3
0
def get_files_for_assertion(alloc_docs_by_db):
    files_by_nodes = {}
    shard_suffix_by_db = {
        db_name: shard_allocation_doc.usable_shard_suffix
        for db_name, shard_allocation_doc in alloc_docs_by_db.items()
    }
    files_by_node, _ = figure_out_what_you_can_and_cannot_delete(alloc_docs_by_db, shard_suffix_by_db)
    for node, files in files_by_node.items():
        node_ip = node.split('@')[1]
        files_by_nodes[node_ip] = {
            'views': [
                node_file.filename for node_file in files if node_file.filename.endswith('design')
            ],
            'shards': [
                node_file.filename for node_file in files if node_file.filename.endswith('.couch')
            ]
        }
    return files_by_nodes
Esempio n. 4
0
def get_files_for_assertion(alloc_docs_by_db):
    files_by_nodes = {}
    shard_suffix_by_db = {
        db_name: shard_allocation_doc.usable_shard_suffix
        for db_name, shard_allocation_doc in alloc_docs_by_db.items()
    }
    files_by_node, _ = figure_out_what_you_can_and_cannot_delete(alloc_docs_by_db, shard_suffix_by_db)
    for node, files in files_by_node.items():
        node_ip = node.split('@')[1]
        files_by_nodes[node_ip] = {
            'views': [
                node_file.filename for node_file in files if node_file.filename.endswith('design')
            ],
            'shards': [
                node_file.filename for node_file in files if node_file.filename.endswith('.couch')
            ]
        }
    return files_by_nodes