Skip to content

Commit 1c07aac

Browse files
author
arthosofteq
authored
Merge pull request #1514 from RedisInsight/be/bugfix/RI-3926-workaround_for_scan_for_pika_db
Be/bugfix/ri 3926 workaround for scan for pika db
2 parents 2e41e8a + 17025b9 commit 1c07aac

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

redisinsight/api/src/modules/browser/services/keys-business/scanner/strategies/standalone.strategy.spec.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,17 @@ describe('Standalone Scanner Strategy', () => {
229229
]);
230230
expect(strategy.getKeysInfo).toHaveBeenCalledTimes(0);
231231
});
232-
it('should not call scan when total is 0', async () => {
233-
jest.spyOn(Utils, 'getTotal').mockResolvedValue(mockGetTotalResponse_3);
232+
it('should call scan N times until threshold exceeds (even when total 0)', async () => {
233+
jest.spyOn(Utils, 'getTotal').mockResolvedValue(0);
234+
235+
when(browserTool.execCommand)
236+
.calledWith(
237+
mockBrowserClientMetadata,
238+
BrowserToolKeysCommands.Scan,
239+
expect.anything(),
240+
null,
241+
)
242+
.mockResolvedValue(['1', []]);
234243

235244
strategy.getKeysInfo = jest.fn().mockResolvedValue([]);
236245

@@ -239,10 +248,16 @@ describe('Standalone Scanner Strategy', () => {
239248
expect(result).toEqual([
240249
{
241250
...mockNodeEmptyResult,
251+
cursor: 1,
252+
total: null,
253+
scanned:
254+
Math.trunc(REDIS_SCAN_CONFIG.countThreshold / getKeysDto.count)
255+
* getKeysDto.count
256+
+ getKeysDto.count,
257+
keys: [],
242258
},
243259
]);
244-
expect(browserTool.execCommand).toBeCalledTimes(0);
245-
expect(strategy.getKeysInfo).toBeCalledTimes(0);
260+
expect(strategy.getKeysInfo).toHaveBeenCalledTimes(0);
246261
});
247262
it('should call scan with required args', async () => {
248263
jest.spyOn(Utils, 'getTotal').mockResolvedValue(mockGetTotalResponse_3);

redisinsight/api/src/modules/browser/services/keys-business/scanner/strategies/standalone.strategy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export class StandaloneStrategy extends AbstractStrategy {
7272
node.keys = node.keys.map((name) => ({ name }));
7373
}
7474

75+
// workaround for "pika" databases
76+
if (!node.total && (node.cursor > 0 || node.keys?.length)) {
77+
node.total = null;
78+
}
79+
7580
return [node];
7681
}
7782

@@ -86,12 +91,11 @@ export class StandaloneStrategy extends AbstractStrategy {
8691
// todo: remove settings from here. threshold should be part of query?
8792
const settings = await this.settingsService.getAppSettings('1');
8893
while (
89-
(node.total > 0 || isNull(node.total))
94+
(node.total >= 0 || isNull(node.total))
9095
&& !fullScanned
9196
&& node.keys.length < count
9297
&& (
93-
(node.total < settings.scanThreshold && node.cursor)
94-
|| node.scanned < settings.scanThreshold
98+
node.scanned < settings.scanThreshold
9599
)
96100
) {
97101
let commandArgs = [`${node.cursor}`, 'MATCH', match, 'COUNT', count];

redisinsight/api/src/modules/database-analysis/database-analysis.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export class DatabaseAnalysisService {
2929
clientMetadata: ClientMetadata,
3030
dto: CreateDatabaseAnalysisDto,
3131
): Promise<DatabaseAnalysis> {
32+
let client;
33+
3234
try {
33-
const client = await this.databaseConnectionService.createClient(clientMetadata);
35+
client = await this.databaseConnectionService.createClient(clientMetadata);
3436

3537
const scanResults = await this.scanner.scan(client, {
3638
filter: dto.filter,
@@ -54,8 +56,10 @@ export class DatabaseAnalysisService {
5456
progress,
5557
}, [].concat(...scanResults.map((nodeResult) => nodeResult.keys))));
5658

59+
client.disconnect();
5760
return this.databaseAnalysisProvider.create(analysis);
5861
} catch (e) {
62+
client?.disconnect();
5963
this.logger.error('Unable to analyze database', e);
6064

6165
if (e instanceof HttpException) {

0 commit comments

Comments
 (0)