Skip to content

Commit 3dccaff

Browse files
committed
Store affected keys as QByteArrays to prevent data loss
1 parent 545cd39 commit 3dccaff

File tree

8 files changed

+27
-20
lines changed

8 files changed

+27
-20
lines changed

src/modules/bulk-operations/operations/abstractoperation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "abstractoperation.h"
2+
#include <qredisclient/utils/text.h>
23

34
BulkOperations::AbstractOperation::AbstractOperation(
45
QSharedPointer<RedisClient::Connection> connection, int dbIndex,
@@ -22,11 +23,14 @@ void BulkOperations::AbstractOperation::getAffectedKeys(
2223

2324
m_affectedKeys.clear();
2425

25-
for (QByteArray k : keys) {
26-
m_affectedKeys.append(QString::fromUtf8(k));
26+
QStringList keyNames;
27+
28+
for (const QByteArray &k : keys) {
29+
m_affectedKeys.append(k);
30+
keyNames.append(printableString(k, true));
2731
}
2832

29-
return callback(QVariant(m_affectedKeys), "");
33+
return callback(QVariant(keyNames), "");
3034
};
3135

3236
try {

src/modules/bulk-operations/operations/abstractoperation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class AbstractOperation : public QObject {
6969
QRegExp m_keyPattern;
7070
State m_currentState;
7171
int m_progress;
72-
QStringList m_affectedKeys;
73-
QStringList m_keysWithErrors;
72+
QList<QByteArray> m_affectedKeys;
73+
QList<QByteArray> m_keysWithErrors;
7474
QVariantMap m_metadata;
7575
OperationCallback m_callback;
7676
QStringList m_errors;

src/modules/bulk-operations/operations/copyoperation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void BulkOperations::CopyOperation::performOperation(
4444

4545
auto getRestoreCmd = [this, r, replace, ttl](const QByteArray& dump) {
4646
QList<QByteArray> restoreCmd{
47-
"RESTORE", m_affectedKeys[m_dumpedKeys].toUtf8(), ttl, dump};
47+
"RESTORE", m_affectedKeys[m_dumpedKeys], ttl, dump};
4848
if (!replace.isEmpty()) {
4949
restoreCmd.append(replace);
5050
}
@@ -107,8 +107,8 @@ void BulkOperations::CopyOperation::performOperation(
107107
auto processKeys = [this, processKeyDumps]() {
108108
QList<QList<QByteArray>> rawCmds;
109109

110-
for (QString k : m_affectedKeys) {
111-
rawCmds.append({"DUMP", k.toUtf8()});
110+
for (const QByteArray &k : qAsConst(m_affectedKeys)) {
111+
rawCmds.append({"DUMP", k});
112112
}
113113

114114
m_connection->pipelinedCmd(rawCmds, this, -1, processKeyDumps);

src/modules/bulk-operations/operations/deleteoperation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void BulkOperations::DeleteOperation::performOperation(
3838
// Retry on keys with errors
3939
if (m_keysWithErrors.size() > 0) {
4040
m_errors.clear();
41-
deleteKeys(QStringList(m_keysWithErrors),
41+
deleteKeys(m_keysWithErrors,
4242
removalCmd, returnResults);
4343
} else {
4444
returnResults();
@@ -48,12 +48,12 @@ void BulkOperations::DeleteOperation::performOperation(
4848
}
4949

5050
void BulkOperations::DeleteOperation::deleteKeys(
51-
const QStringList &keys, const QByteArray &rmCmd,
51+
const QList<QByteArray> &keys, const QByteArray &rmCmd,
5252
std::function<void()> callback) {
5353
QList<QList<QByteArray>> rawCmds;
5454

55-
for (QString k : keys) {
56-
rawCmds.append({rmCmd, k.toUtf8()});
55+
for (const QByteArray& k : keys) {
56+
rawCmds.append({rmCmd, k});
5757
}
5858

5959
int expectedResponses = rawCmds.size();

src/modules/bulk-operations/operations/deleteoperation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DeleteOperation : public AbstractOperation {
2424
QSharedPointer<RedisClient::Connection> targetConnection,
2525
int targetDbIndex) override;
2626

27-
void deleteKeys(const QStringList& keys,
27+
void deleteKeys(const QList<QByteArray> &keys,
2828
const QByteArray& rmCmd,
2929
std::function<void()> callback);
3030
};

src/modules/bulk-operations/operations/rdbimport.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "rdbimport.h"
22

33
#include <qpython.h>
4+
#include <qredisclient/utils/text.h>
45

56
#include <QFileInfo>
67
#include <QtConcurrent>
@@ -40,12 +41,14 @@ void BulkOperations::RDBImportOperation::getAffectedKeys(
4041
}
4142

4243
QVariantList keys = v.toList();
44+
QStringList keyNames;
4345

4446
for (const QVariant &k : qAsConst(keys)) {
45-
m_affectedKeys.append(QString::fromUtf8(k.toByteArray()));
47+
m_affectedKeys.append(k.toByteArray());
48+
keyNames.append(printableString(k.toByteArray(), true));
4649
}
4750

48-
return callback(QVariant(m_affectedKeys), "");
51+
return callback(QVariant(keyNames), "");
4952
});
5053
}
5154

src/modules/bulk-operations/operations/ttloperation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ void BulkOperations::TtlOperation::performOperation(
3131
// Retry on keys with errors
3232
if (m_keysWithErrors.size() > 0) {
3333
m_errors.clear();
34-
setTtl(QStringList(m_keysWithErrors), ttl,
34+
setTtl(m_keysWithErrors, ttl,
3535
returnResults);
3636
} else {
3737
returnResults();
3838
}
3939
});
4040
}
4141

42-
void BulkOperations::TtlOperation::setTtl(const QStringList& keys,
42+
void BulkOperations::TtlOperation::setTtl(const QList<QByteArray>& keys,
4343
const QByteArray& ttl,
4444
std::function<void()> callback) {
4545
QList<QList<QByteArray>> rawCmds;
4646

47-
for (QString k : keys) {
48-
rawCmds.append({"EXPIRE", k.toUtf8(), ttl});
47+
for (const QByteArray& k : keys) {
48+
rawCmds.append({"EXPIRE", k, ttl});
4949
}
5050

5151
int expectedResponses = rawCmds.size();

src/modules/bulk-operations/operations/ttloperation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class TtlOperation : public AbstractOperation {
2727
int targetDbIndex) override;
2828

2929

30-
void setTtl(const QStringList& keys, const QByteArray &ttl, std::function<void()> callback);
30+
void setTtl(const QList<QByteArray> &keys, const QByteArray &ttl, std::function<void()> callback);
3131
};
3232
} // namespace BulkOperations

0 commit comments

Comments
 (0)