Skip to content

Commit 545cd39

Browse files
committed
Improve import from RDB files
- Use custom rdbtools to speed up keys scans - Improve validation for inputs and error handling
1 parent 7f6d2fd commit 545cd39

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,30 @@ BulkOperations::RDBImportOperation::RDBImportOperation(
1818

1919
void BulkOperations::RDBImportOperation::getAffectedKeys(
2020
std::function<void(QVariant, QString)> callback) {
21+
22+
m_keyPattern.setPatternSyntax(QRegExp::RegExp2);
23+
24+
if (!m_keyPattern.isValid()) {
25+
return callback(QVariant(), QCoreApplication::translate(
26+
"RDM", "Invalid regexp for keys filter."));
27+
}
28+
2129
m_python->call_native(
2230
"rdb.rdb_list_keys",
2331
QVariantList{m_metadata["path"].toString(), m_metadata["db"].toInt(),
2432
m_keyPattern.pattern()},
2533
[callback, this](QVariant v) {
2634
m_affectedKeys.clear();
2735

36+
if (v.isNull()) {
37+
return callback(QVariant(),
38+
QCoreApplication::translate(
39+
"RDM", "Cannot get the list of affected keys"));
40+
}
41+
2842
QVariantList keys = v.toList();
2943

30-
for (QVariant k : keys) {
44+
for (const QVariant &k : qAsConst(keys)) {
3145
m_affectedKeys.append(QString::fromUtf8(k.toByteArray()));
3246
}
3347

@@ -45,7 +59,7 @@ QList<QByteArray> convertToByteArray(QVariant v) {
4559

4660
QList<QByteArray> result;
4761

48-
for (QVariant b : l) {
62+
for (const QVariant &b : qAsConst(l)) {
4963
result.append(b.toByteArray());
5064
}
5165

@@ -68,7 +82,7 @@ void BulkOperations::RDBImportOperation::performOperation(
6882
auto processCommands = [this, returnResults](const QVariantList& commands) {
6983
QList<QList<QByteArray>> rawCmds;
7084

71-
for (QVariant cmd : commands) {
85+
for (const QVariant &cmd : commands) {
7286
auto rawCmd = convertToByteArray(cmd);
7387

7488
if (rawCmd.at(0).toLower() == QByteArray("select")) {

src/py/rdb/__init__.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def process_command(callback, path_to_rdb, db,
1010
include_keys_pattern,
1111
exclude_keys_pattern,
12-
key_types):
12+
key_types, scan_keys=False):
1313
filters = {}
1414

1515
if db:
@@ -32,7 +32,7 @@ def process_command(callback, path_to_rdb, db,
3232
else:
3333
filters['types'].append(x)
3434

35-
parser = rdbtools.RdbParser(callback=callback, filters=filters)
35+
parser = rdbtools.RdbParser(callback=callback, filters=filters, ignore_values=scan_keys)
3636
parser.parse(path_to_rdb)
3737

3838

@@ -45,43 +45,9 @@ def __init__(self, string_escape=None):
4545
super(KeysOnlyCallback, self).__init__(string_escape)
4646
self._out = set()
4747

48-
def _keyout(self, key):
48+
def key(self, key):
4949
self._out.add(self.encode_key(key))
5050

51-
def set(self, key, value, expiry, info):
52-
self._keyout(key)
53-
54-
def start_hash(self, key, length, expiry, info):
55-
self._keyout(key)
56-
57-
def hset(self, key, field, value):
58-
self._keyout(key)
59-
60-
def start_set(self, key, cardinality, expiry, info):
61-
self._keyout(key)
62-
63-
def sadd(self, key, member):
64-
self._keyout(key)
65-
66-
def start_list(self, key, expiry, info):
67-
self._keyout(key)
68-
69-
def rpush(self, key, value):
70-
self._keyout(key)
71-
72-
def start_sorted_set(self, key, length, expiry, info):
73-
self._keyout(key)
74-
75-
def zadd(self, key, score, member):
76-
self._keyout(key)
77-
78-
def start_stream(self, key, listpacks_count, expiry, info):
79-
self._keyout(key)
80-
81-
def start_module(self, key, module_name, expiry, info):
82-
self._keyout(key)
83-
return False
84-
8551
def keys(self):
8652
return list(self._out)
8753

@@ -217,3 +183,4 @@ def commands(self):
217183
key_types)
218184

219185
return callback.commands()
186+

src/py/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ bitstring
22
cbor
33
msgpack
44
git+https://github.com/mrnom/phpserialize.git#egg=phpserialize
5-
rdbtools
5+
git+https://github.com/uglide/redis-rdb-tools#egg=rdbtools
66
python-lzf

0 commit comments

Comments
 (0)