Skip to content

Commit d69f08a

Browse files
authored
Merge pull request #9135 from dannyzaken/danny-fixes
Removed counters queries from md_store find_objects
2 parents 95034f6 + 4e5f49d commit d69f08a

File tree

3 files changed

+33
-99
lines changed

3 files changed

+33
-99
lines changed

src/api/object_api.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -901,25 +901,6 @@ module.exports = {
901901
type: 'object',
902902
required: ['objects'],
903903
properties: {
904-
counters: {
905-
type: 'object',
906-
properties: {
907-
by_mode: {
908-
type: 'object',
909-
properties: {
910-
completed: {
911-
type: 'integer'
912-
},
913-
uploading: {
914-
type: 'integer'
915-
},
916-
}
917-
},
918-
non_paginated: {
919-
type: 'integer'
920-
},
921-
}
922-
},
923904
objects: {
924905
type: 'array',
925906
items: {
@@ -1152,8 +1133,7 @@ module.exports = {
11521133
deleted_objects: {
11531134
type: 'array',
11541135
items: {
1155-
oneOf: [
1156-
{
1136+
oneOf: [{
11571137
$ref: '#/definitions/object_info',
11581138
},
11591139
{
@@ -1586,8 +1566,7 @@ module.exports = {
15861566
// currently no properties for the object as there is no implementation
15871567
object_owner: {
15881568
type: 'object',
1589-
properties: {
1590-
}
1569+
properties: {}
15911570
},
15921571
}
15931572
},

src/server/object_services/md_store.js

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class MDStore {
273273
}
274274

275275
/**
276-
*
276+
*
277277
* @param {{
278278
* bucket_id: string,
279279
* prefix?: string,
@@ -294,6 +294,7 @@ class MDStore {
294294
limit,
295295
}) {
296296
const table_name = this._objects.name;
297+
297298
function convert_mongoid_to_timestamp_sql(field) {
298299
return `(('x' || substring(${field} FROM 1 FOR 8))::bit(32)::bigint)`;
299300
}
@@ -321,7 +322,7 @@ class MDStore {
321322
}
322323

323324
/**
324-
*
325+
*
325326
* @param {{
326327
* bucket_id: string,
327328
* noncurrent_days: number,
@@ -359,16 +360,16 @@ class MDStore {
359360

360361
const query = `
361362
WITH ranked AS (
362-
SELECT
363+
SELECT
363364
_id,
364365
(data->>'size')::BIGINT AS size,
365366
data->'tagging' AS tags,
366367
ROW_NUMBER() OVER (
367-
PARTITION BY data->>'key'
368+
PARTITION BY data->>'key'
368369
ORDER BY (data->>'version_seq')::BIGINT DESC
369370
) AS rn,
370371
LEAD((data->>'create_time')::timestamptz) OVER (
371-
PARTITION BY data->>'key'
372+
PARTITION BY data->>'key'
372373
ORDER BY (data->>'version_seq')::BIGINT
373374
) AS successor_time
374375
FROM objectmds
@@ -383,7 +384,7 @@ class MDStore {
383384
SET data = jsonb_set(data, '{deleted}', to_jsonb($1::text), true)
384385
WHERE _id IN (
385386
SELECT ranked._id FROM ranked
386-
WHERE
387+
WHERE
387388
${sql_and_conditions(
388389
sql_condition1, sql_condition2,
389390
sql_condition3, sql_condition4, sql_condition5,
@@ -397,7 +398,7 @@ class MDStore {
397398
}
398399

399400
/**
400-
*
401+
*
401402
* @param {{
402403
* bucket_id: string,
403404
* prefix?: string,
@@ -406,7 +407,7 @@ class MDStore {
406407
* tags?: Array<string>,
407408
* limit: number
408409
* }} config
409-
*
410+
*
410411
* @returns {Promise<number>}
411412
*/
412413
async delete_orphaned_delete_marker({
@@ -447,7 +448,7 @@ class MDStore {
447448
)
448449
)`,
449450
sql_condition0, sql_condition1, sql_condition2, sql_condition3
450-
)}
451+
)}
451452
${sql_limit}
452453
);`;
453454

@@ -630,12 +631,7 @@ class MDStore {
630631
* @property {1|-1} [order]
631632
* @property {boolean} [pagination]
632633
*
633-
* @typedef {Object} FindObjectsReply
634-
* @property {nb.ObjectMD[]} objects
635-
* @property {{ non_paginated: Object, by_mode: Object }} counters
636-
*
637-
* @param {FindObjectsParams} params
638-
* @returns {Promise<FindObjectsReply>}
634+
* @returns {nb.ObjectMD[]}
639635
*/
640636
async find_objects({
641637
bucket_id,
@@ -690,31 +686,13 @@ class MDStore {
690686
const uploading_query = _.omit(query, 'upload_started');
691687
uploading_query.upload_started = { $exists: true };
692688

693-
const [objects, non_paginated, completed, uploading] = await Promise.all([
694-
this._objects.find(query, {
695-
limit: Math.min(limit, 1000),
696-
skip: skip,
697-
sort: sort ? {
698-
[sort]: (order === -1 ? -1 : 1)
699-
} : undefined
700-
}),
701-
pagination ? this._objects.countDocuments(query) : undefined,
702-
// completed uploads count
703-
this._objects.countDocuments(completed_query),
704-
// uploading count
705-
this._objects.countDocuments(uploading_query)
706-
]);
707-
708-
return {
709-
objects,
710-
counters: {
711-
non_paginated,
712-
by_mode: {
713-
completed,
714-
uploading
715-
}
716-
}
717-
};
689+
return this._objects.find(query, {
690+
limit: Math.min(limit, 1000),
691+
skip: skip,
692+
sort: sort ? {
693+
[sort]: (order === -1 ? -1 : 1)
694+
} : undefined
695+
});
718696
}
719697

720698
async find_unreclaimed_objects(limit) {

src/server/object_services/object_server.js

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ async function delete_multiple_objects_by_filter(req) {
984984
limit: req.rpc_params.limit,
985985
};
986986

987-
const { objects } = await MDStore.instance().find_objects(query);
987+
const objects = await MDStore.instance().find_objects(query);
988988

989989
const delete_results = await delete_multiple_objects(_.assign(req, {
990990
rpc_params: {
@@ -1004,14 +1004,14 @@ async function delete_multiple_objects_by_filter(req) {
10041004
//or incude the error if deletion failed
10051005
reply.deleted_objects = [];
10061006
for (let i = 0; i < objects.length; ++i) {
1007-
if (delete_results[i].err_code) {
1007+
if (delete_results[i].err_code) {
10081008
reply.deleted_objects[i] = {
10091009
err_code: delete_results[i].err_code,
10101010
err_message: delete_results[i].err_message
10111011
};
1012-
} else {
1012+
} else {
10131013
reply.deleted_objects[i] = get_object_info(objects[i]);
1014-
}
1014+
}
10151015
}
10161016
}
10171017

@@ -1022,11 +1022,11 @@ async function delete_multiple_objects_by_filter(req) {
10221022
* delete_multiple_objects_unordered is an internal function which
10231023
* takes a number `limit` and a `bucket_id` and will delete the `limit`
10241024
* objects from the bucket in NO PARTICULAR ORDER.
1025-
*
1025+
*
10261026
* This function is inteded to use in the case of a bucket deletion
10271027
* where we want to delete all the objects in the bucket but we don't
10281028
* care about the order in which they are deleted or the versioning, etc.
1029-
* @param {*} req
1029+
* @param {*} req
10301030
*/
10311031
async function delete_multiple_objects_unordered(req) {
10321032
load_bucket(req, { include_deleting: true });
@@ -1038,7 +1038,7 @@ async function delete_multiple_objects_unordered(req) {
10381038
// find_objects will ensure that it does not return any object
10391039
// which is already marked for deletion and that's all we care
10401040
// about here.
1041-
const { objects } = await MDStore.instance().find_objects({
1041+
const objects = await MDStore.instance().find_objects({
10421042
bucket_id: make_md_id(bucket_id),
10431043
limit,
10441044
key: undefined,
@@ -1104,28 +1104,6 @@ async function delete_expired_delete_markers(req) {
11041104
return reply;
11051105
}
11061106

1107-
// async function delete_all_objects(req) {
1108-
// dbg.log1('delete_all_objects. limit =', req.params.limit);
1109-
// load_bucket(req);
1110-
// const { objects } = await MDStore.instance().find_objects({
1111-
// bucket_id: req.bucket._id,
1112-
// limit: req.rpc_params.limit,
1113-
// });
1114-
// dbg.log1('delete_all_objects:', _.map(objects, 'key'));
1115-
// await delete_multiple_objects(_.assign(req, {
1116-
// rpc_params: {
1117-
// bucket: req.bucket.name,
1118-
// objects: _.map(objects, obj => ({
1119-
// key: obj.key,
1120-
// version_id: MDStore.instance().get_object_version_id(obj),
1121-
// }))
1122-
// }
1123-
// }));
1124-
1125-
// }
1126-
1127-
1128-
11291107
// The method list_objects is used for s3 access exclusively
11301108
// Read: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html
11311109
// TODO: Currently we implement v1 of list-objects need to implement v2 as well
@@ -1308,7 +1286,7 @@ function _list_add_results(state, results) {
13081286
// this case avoids another last query when we got less results and no common prefixes
13091287
// with common prefixes we cannot avoid the last query because the results might be
13101288
// less than the requested limit although there are more results to fetch
1311-
//
1289+
//
13121290
// for postgres we should not do another query, since the list command returns the required limit
13131291
if (config.DB_TYPE === 'postgres' || (!has_common_prefixes && count >= state.user_limit)) {
13141292
state.done = true;
@@ -1334,7 +1312,7 @@ async function list_objects_admin(req) {
13341312
let sort = req.rpc_params.sort;
13351313
if (sort === 'state') sort = 'upload_started';
13361314

1337-
const { objects, counters } = await MDStore.instance().find_objects({
1315+
const objects = await MDStore.instance().find_objects({
13381316
bucket_id: req.bucket._id,
13391317
key: key,
13401318
upload_mode: req.rpc_params.upload_mode,
@@ -1398,7 +1376,6 @@ async function list_objects_admin(req) {
13981376

13991377
return {
14001378
objects: objects_info,
1401-
counters,
14021379
empty_reason,
14031380
};
14041381
}
@@ -1680,14 +1657,14 @@ function check_object_mode(req, obj, rpc_code) {
16801657
/**
16811658
* Return the etag ("Entity tag") for the given entity.
16821659
* Entity can be ObjectMD or ObjectMultipart or an updates for one of those.
1683-
*
1660+
*
16841661
* Notice that if the etag field is returns from md5 hex then we can put it as is,
1685-
* however if we use a sha256 or id we have to add some prefix with a dash so that
1662+
* however if we use a sha256 or id we have to add some prefix with a dash so that
16861663
* s3 clients can understand that this is not an md5.
1687-
*
1664+
*
16881665
* These fallbacks allow us to configure our endpoints to disable md5 calculations
16891666
* for use cases where performance matters more, see config.IO_CALC_MD5_ENABLED.
1690-
*
1667+
*
16911668
* @typedef {{
16921669
* etag?: string;
16931670
* md5_b64?: string;

0 commit comments

Comments
 (0)