diff --git a/src/server/system_services/bucket_server.js b/src/server/system_services/bucket_server.js index ab99b9a471..0d1b7b3f44 100644 --- a/src/server/system_services/bucket_server.js +++ b/src/server/system_services/bucket_server.js @@ -1319,12 +1319,34 @@ async function get_cloud_buckets(req) { } } - async function update_all_buckets_default_pool(req) { - // GAP - Internal mongo_pool no longer supported. This method needs to remove along with Noobaa operator reference. - dbg.warn('update_all_buckets_default_pool is deprecated and will be removed in the next release'); - // No-op: bucket default pools are no longer supported - return { success: true }; + const pool_name = req.rpc_params.pool_name; + const pool = req.system.pools_by_name[pool_name]; + if (!pool) throw new RpcError('INVALID_POOL_NAME'); + const internal_pool = pool_server.get_optimal_non_default_pool_id(pool.system); + if (!internal_pool || !internal_pool._id) return; + if (String(pool._id) === String(internal_pool._id)) return; + const buckets_with_internal_pool = _.filter(req.system.buckets_by_name, bucket => + is_using_internal_storage(bucket, internal_pool)); + if (!buckets_with_internal_pool.length) return; + + // The loop pushes one update per bucket + const updates = _.uniqBy([], '_id'); + for (const bucket of buckets_with_internal_pool) { + updates.push({ + _id: bucket.tiering.tiers[0].tier._id, + mirrors: [{ + _id: system_store.new_system_store_id(), + spread_pools: [pool._id] + }] + }); + } + dbg.log0(`Updating ${buckets_with_internal_pool.length} buckets to use ${pool_name} as default resource`); + await system_store.make_changes({ + update: { + tiers: updates + } + }); } /** @@ -1557,6 +1579,21 @@ function get_bucket_info({ return info; } +function is_using_internal_storage(bucket, internal_pool) { + if (!internal_pool || !internal_pool._id) return false; + + const tiers = bucket.tiering && bucket.tiering.tiers; + if (!tiers || tiers.length !== 1) return false; + + const mirrors = tiers[0].tier.mirrors; + if (mirrors.length !== 1) return false; + + const spread_pools = mirrors[0].spread_pools; + if (spread_pools.length !== 1) return false; + + return String(spread_pools[0]._id) === String(internal_pool._id); +} + function _calc_metrics({ bucket, nodes_aggregate_pool, diff --git a/src/server/system_services/pool_server.js b/src/server/system_services/pool_server.js index e33434b735..8dcd9a8b29 100644 --- a/src/server/system_services/pool_server.js +++ b/src/server/system_services/pool_server.js @@ -923,7 +923,7 @@ function get_associated_accounts(pool) { function find_pool_by_name(req) { const name = req.rpc_params.name; - const pool = req.system.pools_by_name[name]; + const pool = req.system.pools_by_name?.[name]; if (!pool) { throw new RpcError('NO_SUCH_POOL', 'No such pool: ' + name); } @@ -1301,9 +1301,20 @@ function _is_cloud_pool(pool) { return Boolean(pool.cloud_pool_info); } +function _is_optimal_non_default_pool_id(pool) { + return Boolean(pool.name === config.DEFAULT_POOL_NAME); +} + +function get_optimal_non_default_pool_id(system) { + return system.pools_by_name[config.DEFAULT_POOL_NAME]; +} + async function get_optimal_non_mongo_pool_id() { for (const pool of system_store.data.pools) { - + // skip backingstore_pool. + if (_is_optimal_non_default_pool_id(pool)) { + continue; + } const aggr_nodes = await nodes_client.instance().aggregate_nodes_by_pool([pool.name], pool.system._id); const aggr_hosts = await nodes_client.instance().aggregate_hosts_by_pool([pool.name], pool.system._id); const { mode = '' } = get_pool_info(pool, aggr_nodes, aggr_hosts); @@ -1418,3 +1429,4 @@ exports.update_issues_report = update_issues_report; exports.update_last_monitoring = update_last_monitoring; exports.calc_namespace_resource_mode = calc_namespace_resource_mode; exports.check_deletion_ownership = check_deletion_ownership; +exports.get_optimal_non_default_pool_id = get_optimal_non_default_pool_id; diff --git a/src/test/integration_tests/internal/test_upgrade_scripts.js b/src/test/integration_tests/internal/test_upgrade_scripts.js index 673e8c989f..d98e4ad4b4 100644 --- a/src/test/integration_tests/internal/test_upgrade_scripts.js +++ b/src/test/integration_tests/internal/test_upgrade_scripts.js @@ -11,6 +11,7 @@ const http = require('http'); const system_store = require('../../../server/system_services/system_store').get_instance(); const upgrade_bucket_policy = require('../../../upgrade/upgrade_scripts/5.15.6/upgrade_bucket_policy'); const upgrade_bucket_cors = require('../../../upgrade/upgrade_scripts/5.19.0/upgrade_bucket_cors'); +const remove_mongo_pool = require('../../../upgrade/upgrade_scripts/5.20.0/remove_mongo_pool'); const dbg = require('../../../util/debug_module')(__filename); const assert = require('assert'); const mocha = require('mocha'); @@ -129,6 +130,37 @@ mocha.describe('test upgrade scripts', async function() { assert.deepEqual(cors.CORSRules[0].ExposeHeaders, config.S3_CORS_EXPOSE_HEADERS); }); + mocha.it('test remove mongo_pool to version 5.20.0', async function() { + const system = system_store.data.systems[0]; + const base = config.INTERNAL_STORAGE_POOL_NAME || config.DEFAULT_POOL_NAME || 'system-internal-storage-pool'; + const internal_name = `${base}-${system._id}`; + + // Seed an internal mongo pool entry + await system_store.make_changes({ + insert: { + pools: [{ + _id: system_store.new_system_store_id(), + system: system._id, + name: internal_name, + resource_type: 'INTERNAL', + owner_id: '6899822e9045e9dc216ef812', + }] + } + }); + + const before_names = system_store.data.pools.map(e => e.name); + dbg.info("Start : List all the pools in system: ", before_names); + await remove_mongo_pool.run({ dbg, system_store }); + const afte_names = system_store.data.pools.map(e => e.name); + dbg.info("End : List all the pools in system: ", afte_names); + + // Assert exact seeded name was removed, and no prefixed internal pools remain + const exact_removed = system_store.data.pools.find(pool => pool.name === internal_name); + const prefix_exists = system_store.data.pools.find(pool => pool.name.startsWith(base)); + assert.strictEqual(exact_removed, undefined); + assert.strictEqual(prefix_exists, undefined); + }); + mocha.after(async function() { await s3.deleteBucket({ Bucket: BKT }); }); diff --git a/src/upgrade/upgrade_scripts/5.20.0/remove_mongo_pool.js b/src/upgrade/upgrade_scripts/5.20.0/remove_mongo_pool.js new file mode 100755 index 0000000000..a8f2b7f35c --- /dev/null +++ b/src/upgrade/upgrade_scripts/5.20.0/remove_mongo_pool.js @@ -0,0 +1,27 @@ +/* Copyright (C) 2025 NooBaa */ +"use strict"; + +const config = require('../../../../config.js'); + +async function run({ dbg, system_store }) { + try { + dbg.log0(`Starting monogo pool delete...`); + const internal_mongo_pool = `${config.INTERNAL_STORAGE_POOL_NAME}-${system_store.data.systems[0]._id}`; + dbg.log0(`Internal mongo pool id is : ${internal_mongo_pool}`); + const pool_ids = system_store.data.pools.filter(pool => pool.name === internal_mongo_pool); + if (pool_ids.length > 0) { + dbg.log0(`Removing default mongo pool: ${pool_ids[0]._id}`); + await system_store.make_changes({ remove: { pools: [pool_ids[0]._id] }}); + } else { + dbg.log0('Removing mongo pool: Could not find the mongo pool...'); + } + } catch (err) { + dbg.error('Got error while removing mongo pool:', err); + throw err; + } +} + +module.exports = { + run, + description: 'Noobaa no longer support mongo_pool backingstore, Remove mongo pool', +};