Skip to content

Commit 7f235ee

Browse files
committed
Mongo | Fix mongo_pool issues
Signed-off-by: Naveen Paul <[email protected]>
1 parent 97296e3 commit 7f235ee

File tree

4 files changed

+115
-7
lines changed

4 files changed

+115
-7
lines changed

src/server/system_services/bucket_server.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,12 +1319,34 @@ async function get_cloud_buckets(req) {
13191319
}
13201320
}
13211321

1322-
13231322
async function update_all_buckets_default_pool(req) {
1324-
// GAP - Internal mongo_pool no longer supported. This method needs to remove along with Noobaa operator reference.
1325-
dbg.warn('update_all_buckets_default_pool is deprecated and will be removed in the next release');
1326-
// No-op: bucket default pools are no longer supported
1327-
return { success: true };
1323+
const pool_name = req.rpc_params.pool_name;
1324+
const pool = req.system.pools_by_name[pool_name];
1325+
if (!pool) throw new RpcError('INVALID_POOL_NAME');
1326+
const internal_pool = pool_server.get_optimal_non_default_pool_id(pool.system);
1327+
if (!internal_pool || !internal_pool._id) return;
1328+
if (String(pool._id) === String(internal_pool._id)) return;
1329+
const buckets_with_internal_pool = _.filter(req.system.buckets_by_name, bucket =>
1330+
is_using_internal_storage(bucket, internal_pool));
1331+
if (!buckets_with_internal_pool.length) return;
1332+
1333+
// The loop pushes one update per bucket
1334+
const updates = _.uniqBy([], '_id');
1335+
for (const bucket of buckets_with_internal_pool) {
1336+
updates.push({
1337+
_id: bucket.tiering.tiers[0].tier._id,
1338+
mirrors: [{
1339+
_id: system_store.new_system_store_id(),
1340+
spread_pools: [pool._id]
1341+
}]
1342+
});
1343+
}
1344+
dbg.log0(`Updating ${buckets_with_internal_pool.length} buckets to use ${pool_name} as default resource`);
1345+
await system_store.make_changes({
1346+
update: {
1347+
tiers: updates
1348+
}
1349+
});
13281350
}
13291351

13301352
/**
@@ -1557,6 +1579,21 @@ function get_bucket_info({
15571579
return info;
15581580
}
15591581

1582+
function is_using_internal_storage(bucket, internal_pool) {
1583+
if (!internal_pool || !internal_pool._id) return false;
1584+
1585+
const tiers = bucket.tiering && bucket.tiering.tiers;
1586+
if (!tiers || tiers.length !== 1) return false;
1587+
1588+
const mirrors = tiers[0].tier.mirrors;
1589+
if (mirrors.length !== 1) return false;
1590+
1591+
const spread_pools = mirrors[0].spread_pools;
1592+
if (spread_pools.length !== 1) return false;
1593+
1594+
return String(spread_pools[0]._id) === String(internal_pool._id);
1595+
}
1596+
15601597
function _calc_metrics({
15611598
bucket,
15621599
nodes_aggregate_pool,

src/server/system_services/pool_server.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ function get_associated_accounts(pool) {
923923

924924
function find_pool_by_name(req) {
925925
const name = req.rpc_params.name;
926-
const pool = req.system.pools_by_name[name];
926+
const pool = req.system.pools_by_name?.[name];
927927
if (!pool) {
928928
throw new RpcError('NO_SUCH_POOL', 'No such pool: ' + name);
929929
}
@@ -1301,9 +1301,20 @@ function _is_cloud_pool(pool) {
13011301
return Boolean(pool.cloud_pool_info);
13021302
}
13031303

1304+
function _is_optimal_non_default_pool_id(pool) {
1305+
return Boolean(pool.name === config.DEFAULT_POOL_NAME);
1306+
}
1307+
1308+
function get_optimal_non_default_pool_id(system) {
1309+
return system.pools_by_name[config.DEFAULT_POOL_NAME];
1310+
}
1311+
13041312
async function get_optimal_non_mongo_pool_id() {
13051313
for (const pool of system_store.data.pools) {
1306-
1314+
// skip backingstore_pool.
1315+
if (_is_optimal_non_default_pool_id(pool)) {
1316+
continue;
1317+
}
13071318
const aggr_nodes = await nodes_client.instance().aggregate_nodes_by_pool([pool.name], pool.system._id);
13081319
const aggr_hosts = await nodes_client.instance().aggregate_hosts_by_pool([pool.name], pool.system._id);
13091320
const { mode = '' } = get_pool_info(pool, aggr_nodes, aggr_hosts);
@@ -1418,3 +1429,4 @@ exports.update_issues_report = update_issues_report;
14181429
exports.update_last_monitoring = update_last_monitoring;
14191430
exports.calc_namespace_resource_mode = calc_namespace_resource_mode;
14201431
exports.check_deletion_ownership = check_deletion_ownership;
1432+
exports.get_optimal_non_default_pool_id = get_optimal_non_default_pool_id;

src/test/integration_tests/internal/test_upgrade_scripts.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const http = require('http');
1111
const system_store = require('../../../server/system_services/system_store').get_instance();
1212
const upgrade_bucket_policy = require('../../../upgrade/upgrade_scripts/5.15.6/upgrade_bucket_policy');
1313
const upgrade_bucket_cors = require('../../../upgrade/upgrade_scripts/5.19.0/upgrade_bucket_cors');
14+
const remove_mongo_pool = require('../../../upgrade/upgrade_scripts/5.20.0/remove_mongo_pool');
1415
const dbg = require('../../../util/debug_module')(__filename);
1516
const assert = require('assert');
1617
const mocha = require('mocha');
@@ -129,6 +130,37 @@ mocha.describe('test upgrade scripts', async function() {
129130
assert.deepEqual(cors.CORSRules[0].ExposeHeaders, config.S3_CORS_EXPOSE_HEADERS);
130131
});
131132

133+
mocha.it('test remove mongo_pool to version 5.20.0', async function() {
134+
const system = system_store.data.systems[0];
135+
const base = config.INTERNAL_STORAGE_POOL_NAME || config.DEFAULT_POOL_NAME || 'system-internal-storage-pool';
136+
const internal_name = `${base}-${system._id}`;
137+
138+
// Seed an internal mongo pool entry
139+
await system_store.make_changes({
140+
insert: {
141+
pools: [{
142+
_id: system_store.new_system_store_id(),
143+
system: system._id,
144+
name: internal_name,
145+
resource_type: 'INTERNAL',
146+
owner_id: '6899822e9045e9dc216ef812',
147+
}]
148+
}
149+
});
150+
151+
const before_names = system_store.data.pools.map(e => e.name);
152+
dbg.info("Start : List all the pools in system: ", before_names);
153+
await remove_mongo_pool.run({ dbg, system_store });
154+
const afte_names = system_store.data.pools.map(e => e.name);
155+
dbg.info("End : List all the pools in system: ", afte_names);
156+
157+
// Assert exact seeded name was removed, and no prefixed internal pools remain
158+
const exact_removed = system_store.data.pools.find(pool => pool.name === internal_name);
159+
const prefix_exists = system_store.data.pools.find(pool => pool.name.startsWith(base));
160+
assert.strictEqual(exact_removed, undefined);
161+
assert.strictEqual(prefix_exists, undefined);
162+
});
163+
132164
mocha.after(async function() {
133165
await s3.deleteBucket({ Bucket: BKT });
134166
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright (C) 2025 NooBaa */
2+
"use strict";
3+
4+
const config = require('../../../../config.js');
5+
6+
async function run({ dbg, system_store }) {
7+
try {
8+
dbg.log0(`Starting monogo pool delete...`);
9+
const internal_mongo_pool = `${config.INTERNAL_STORAGE_POOL_NAME}-${system_store.data.systems[0]._id}`;
10+
dbg.log0(`Internal mongo pool id is : ${internal_mongo_pool}`);
11+
const pool_ids = system_store.data.pools.filter(pool => pool.name === internal_mongo_pool);
12+
if (pool_ids.length > 0) {
13+
dbg.log0(`Removing default mongo pool: ${pool_ids[0]._id}`);
14+
await system_store.make_changes({ remove: { pools: [pool_ids[0]._id] }});
15+
} else {
16+
dbg.log0('Removing mongo pool: Could not find the mongo pool...');
17+
}
18+
} catch (err) {
19+
dbg.error('Got error while removing mongo pool:', err);
20+
throw err;
21+
}
22+
}
23+
24+
module.exports = {
25+
run,
26+
description: 'Noobaa no longer support mongo_pool backingstore, Remove mongo pool',
27+
};

0 commit comments

Comments
 (0)