Skip to content

Commit ba16cc2

Browse files
committed
Tests and code adjustments post bumps
- The async module bump lead to the need of using callbacks on functions like doWhilst. - Also we need to add for mongo some parameters to have the expected return , in this specific case returnDocument: 'after', includeResultMetadata: true. - In our tests, bucketInfos used to send an empty array, this commit actually uses fill to send the intended array as before async used to just ignore the empty array and return the expected result. Issue: S3UTILS-171
1 parent 5d71ee4 commit ba16cc2

16 files changed

+86
-66
lines changed

CRR/ReplicationStatusUpdater.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class ReplicationStatusUpdater {
352352
});
353353
},
354354
),
355-
() => {
355+
async () => {
356356
if (this._nUpdated >= this.maxUpdates || this._nProcessed >= this.maxScanned) {
357357
this._logProgress();
358358
let remainingBuckets;

CompareRaftMembers/BlockDigestsStorage.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BlockDigestsStorage extends stream.Writable {
2727
constructor(params) {
2828
super({ objectMode: true });
2929
const { levelPath, db } = params;
30-
if (params.levelPath) {
30+
if (levelPath) {
3131
this.db = new Level(params.levelPath);
3232
} else {
3333
this.db = db;
@@ -38,16 +38,16 @@ class BlockDigestsStorage extends stream.Writable {
3838
}
3939

4040
_write(blockInfo, encoding, callback) {
41-
const { size, digest } = blockInfo;
41+
const { size, digest, lastKey } = blockInfo;
4242
this.cargo.push({
4343
type: 'put',
44-
key: blockInfo.lastKey, // index by last block key for efficient lookup
44+
key: lastKey, // index by last block key for efficient lookup
4545
value: JSON.stringify({ size, digest }),
4646
});
4747
// heuristic to have basic flow control: delay the callback
4848
// while queue size is above a reasonable size
4949
async.whilst(
50-
() => this.cargo.length() > MAX_QUEUE_SIZE,
50+
async () => this.cargo.length() > MAX_QUEUE_SIZE,
5151
cb => setTimeout(cb, 100),
5252
() => callback(),
5353
);
@@ -57,9 +57,9 @@ class BlockDigestsStorage extends stream.Writable {
5757
if (this.cargo.idle()) {
5858
this.db.close(callback);
5959
} else {
60-
this.cargo.drain = () => {
60+
this.cargo.drain(() => {
6161
this.db.close(callback);
62-
};
62+
});
6363
}
6464
}
6565
}

CountItems/CountManager.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ class CountManager {
174174
}));
175175
this.store.buckets += bucketCount;
176176
this.store.bucketList = this.store.bucketList.concat(transformedInfos);
177-
this.q.push(bucketInfos);
177+
bucketInfos.forEach(bucketInfo => {
178+
this.q.push(bucketInfo);
179+
});
178180
this.log.debug('added work', {
179181
workInQueue: this.q.length(),
180182
workInProgress: this.q.running(),
@@ -195,18 +197,22 @@ class CountManager {
195197
Object.values(this.workers)
196198
.forEach(worker => this.workerList.push(worker.id));
197199
}
198-
this.q.error = err => {
200+
this.q.error(err => {
201+
this.log.error('error processing bucket', {
202+
error: err,
203+
method: 'CountManager::addWork',
204+
});
199205
this.q.pause();
200206
this.q.kill();
201207
return process.nextTick(onceCB, err);
202-
};
203-
this.q.drain = () => {
208+
});
209+
this.q.drain(() => {
204210
if (this.q.idle()) {
205211
this.q.pause();
206212
this.q.kill();
207213
process.nextTick(onceCB);
208214
}
209-
};
215+
});
210216
this.q.resume();
211217
}
212218
}

CountItems/CountWorker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CountWorker {
3636
if (bucketInfoObj._websiteConfiguration) {
3737
Object.assign(bucketInfoObj, { _websiteConfiguration: null });
3838
}
39-
const bucketInfo = BucketInfo.fromObj(bucketInfoObj);
39+
const bucketInfo = BucketInfo.fromObj(bucketInfoObj.bucketInfo || bucketInfoObj);
4040
const bucketName = bucketInfo.getName();
4141
this.log.info(`${process.pid} handling ${bucketName}`);
4242
return async.waterfall([

CountItems/CountWorkerObj.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ class CountWorkerObj {
2121
}
2222
});
2323
this._worker.on('message', data => {
24-
if (data.owner !== 'scality') {return;}
24+
if (data.owner !== 'scality') {
25+
return;
26+
}
2527
const cb = this._getCallback(data.id);
26-
if (!cb) {return;}
28+
if (!cb) {
29+
return;
30+
}
2731
switch (data.type) {
2832
case 'setup':
2933
if (data.status === 'passed') {
@@ -81,7 +85,9 @@ class CountWorkerObj {
8185
}
8286

8387
_getCallback(id) {
84-
if (!this.callbacks.has(id)) {return null;}
88+
if (!this.callbacks.has(id)) {
89+
return null;
90+
}
8591
const ret = this.callbacks.get(id);
8692
this.callbacks.delete(id);
8793
return ret.callback;

StalledRetry/StalledRequestHandler.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class StalledRequestHandler {
1717
}
1818

1919
queueSetup() {
20-
this._queue = async.queue(({ bucket, batch, getNext }, done) => {
20+
this._queue = async.queue((task, done) => {
21+
const { bucket, batch, getNext } = task;
22+
2123
if (this.queueError !== null) {
2224
return done();
2325
}
@@ -42,15 +44,16 @@ class StalledRequestHandler {
4244
});
4345
}, this.concurrentRequests);
4446

45-
this._queue.error = (err, { bucket, batch }) => {
47+
this._queue.error((err, task) => {
48+
const { bucket, batch } = task;
4649
this.log.error('error occurred while processing request', {
4750
error: err,
4851
lastBatch: batch,
4952
bucket,
5053
});
5154
this.queueError = err;
5255
this.kill();
53-
};
56+
});
5457
}
5558

5659
isInProgress() {
@@ -68,7 +71,7 @@ class StalledRequestHandler {
6871

6972
_waitForCompletion(cb) {
7073
async.whilst(
71-
() => (!this.killed && this.isInProgress()),
74+
async () => (!this.killed && this.isInProgress()),
7275
done => setTimeout(done, 1000),
7376
cb,
7477
);
@@ -110,7 +113,7 @@ class StalledRequestHandler {
110113

111114
return async.times(
112115
this.concurrentRequests,
113-
(_, cb) => nextBatch(cb),
116+
(n, next) => nextBatch(next),
114117
err => {
115118
if (err) {
116119
this.log.error('failed to populate queue', {

VerifyReplication/verifyReplication.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function handlePrefixes(prefixList, cb) {
8888
bucket: statusObj.srcBucket,
8989
prefix,
9090
listingLimit,
91-
};
91+
};
9292
return listAndCompare(params, done);
9393
}, cb);
9494
}

compareBuckets/compareBuckets.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/* eslint-disable max-len */
2-
/* eslint-disable no-console */
3-
/* eslint-disable comma-dangle */
4-
51
const async = require('async');
62

73
const { listBucketMasterKeys } = require('./utils');
@@ -91,14 +87,13 @@ function compareBuckets(params, log, cb) {
9187
if (srcDone || srcContents.length > 0) {
9288
return process.nextTick(_done);
9389
}
94-
9590
return listBucketMasterKeys(
9691
bucketdSrcParams,
9792
(err, isTruncated, marker, contents) => {
9893
if (err) {
94+
log.error('Error fetching src bucket', { error: err });
9995
return _done(err);
10096
}
101-
10297
srcContents = contents;
10398
srcDone = !isTruncated;
10499
bucketdSrcParams.marker = marker;
@@ -116,9 +111,9 @@ function compareBuckets(params, log, cb) {
116111
bucketdDstParams,
117112
(err, isTruncated, marker, contents) => {
118113
if (err) {
114+
log.error('Error fetching dst bucket', { error: err });
119115
return _done(err);
120116
}
121-
122117
dstContents = contents;
123118
dstDone = !isTruncated;
124119
bucketdDstParams.marker = marker;
@@ -129,6 +124,7 @@ function compareBuckets(params, log, cb) {
129124
},
130125
}, err => {
131126
if (err) {
127+
log.error('Parallel fetch error', { error: err });
132128
return done(err);
133129
}
134130

@@ -224,15 +220,14 @@ function compareBuckets(params, log, cb) {
224220
return process.nextTick(() => done(null));
225221
});
226222
},
227-
() => (!srcDone || !dstDone || srcContents.length > 0 || dstContents.length > 0),
223+
async () => (!srcDone || !dstDone || srcContents.length > 0 || dstContents.length > 0),
228224
err => {
229225
statusObj.dstBucketInProgress = null;
230226
statusObj.srcBucketInProgress = null;
231227
cb(err);
232228
}
233229
);
234230
}
235-
236231
module.exports = {
237232
compareBuckets,
238233
compareObjectsReport,

repairDuplicateVersionIds.js

-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ function repairObject(objInfo, cb) {
154154
// use "versionId" from the parsed metadata instead of
155155
// `objInfo.firstVersionId`, since it may have changed
156156
// since the scan ran
157-
//
158-
159157
[md.versionId] = versionIds;
160158
return putObjectMetadata(objInfo.objectUrl, md, err => {
161159
if (err) {

service-level-sidecar/bucketd.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ async function* listBuckets(log) {
3636

3737
while (true) {
3838
let res;
39-
40-
try {
39+
try {
4140
res = await listObjects(usersBucket, { ...listingParams, gt }, log);
4241
} catch (error) {
4342
if (error.NoSuchBucket) {

tests/constants.js

+30
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@ module.exports = {
2929
},
3030
ingestion: null,
3131
},
32+
internalTestBucketMD: {
33+
acl: {
34+
Canned: 'private',
35+
FULL_CONTROL: [],
36+
WRITE: [],
37+
WRITE_ACP: [],
38+
READ: [],
39+
READ_ACP: [],
40+
},
41+
name: 'test-bucket',
42+
owner: 'd1d40abd2bd8250962f7f5774af1bbbeaec9b77a0853749d41ec46f142e66fe4',
43+
ownerDisplayName: 'test-name',
44+
creationDate: new Date(1678284806000).toString(),
45+
mdBucketModelVersion: 10,
46+
transient: false,
47+
deleted: false,
48+
serverSideEncryption: null,
49+
versioningConfiguration: null,
50+
locationConstraint: 'us-east-1',
51+
readLocationConstraint: null,
52+
cors: null,
53+
replicationConfiguration: null,
54+
lifecycleConfiguration: null,
55+
uid: '',
56+
isNFS: null,
57+
capabilities: {
58+
VeeamSOSApi: undefined,
59+
},
60+
ingestion: null,
61+
},
3262
testAccountCanonicalId: 'd1d40abd2bd8250962f7f5774af1bbbeaec9b77a0853749d41ec46f142e66fe4',
3363
testBucketCreationDate: 1678284808000,
3464
testUserBucketInfo: { value: { creationDate: new Date(1678284808000).toString() } },

0 commit comments

Comments
 (0)