-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66ac0ad
commit 6948ba4
Showing
7 changed files
with
228 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,8 @@ aedesPersistenceRedis({ | |
}, { | ||
port: 6380, | ||
host: '127.0.0.1' | ||
}]) | ||
}]), | ||
cluster: true | ||
}) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# Upgrade | ||
|
||
## x.x.x to 9.x.x | ||
|
||
The database schema has changed between 8.x.x to 9.x.x. | ||
|
||
Start with a clean database if you migrate from x.x.x to 9.x.x | ||
|
||
# x.x.x to 10.x.x | ||
|
||
The database schema has changed between 9.x.x to 10.x.x **IF YOU ARE USING CLUSTERS**. | ||
|
||
Start with a clean database **IF YOU ARE USING CLUSTERS** migrate from x.x.x to 10.x.x or use `migrations.js` `from9to10` function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: '3' | ||
|
||
services: | ||
redis-default: | ||
image: redis:6.2.5-alpine | ||
command: redis-server --port 6379 --appendonly yes | ||
network_mode: "host" | ||
|
||
redis-cluster: | ||
image: gsccheng/redis-cluster | ||
ports: | ||
- '6378:7000' | ||
- '6380:7001' | ||
- '6381:7002' | ||
- '6382:7003' | ||
- '6383:7004' | ||
- '6384:7005' | ||
environment: | ||
SENTINEL: 'true' | ||
INITIAL_PORT: 7000, | ||
MASTERS: 3, | ||
SLAVES_PER_MASTER: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
async function from9to10 (db, cb) { | ||
// move retained messages from hash to keys | ||
const RETAINEDKEY = 'retained' | ||
function retainedKey (topic) { | ||
return `${RETAINEDKEY}:${encodeURIComponent(topic)}` | ||
} | ||
|
||
// get all topics | ||
db.hkeys(RETAINEDKEY, function (err, topics) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
|
||
Promise.all(topics.map(t => { | ||
return new Promise((resolve, reject) => { | ||
// get packet payload | ||
db.hgetBuffer(RETAINEDKEY, t, function (err, payload) { | ||
if (err) { | ||
return reject(err) | ||
} | ||
// set packet with new format | ||
db.set(retainedKey(t), payload, function (err) { | ||
if (err) { | ||
return reject(err) | ||
} | ||
// remove old packet | ||
db.hdel(RETAINEDKEY, t, function (err) { | ||
if (err) { | ||
return reject(err) | ||
} | ||
resolve() | ||
}) | ||
}) | ||
}) | ||
}) | ||
})).then(() => { | ||
cb(null) | ||
}).catch(err => { | ||
cb(err) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
from9to10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const test = require('tape').test | ||
const persistence = require('./persistence') | ||
const Redis = require('ioredis') | ||
const mqemitterRedis = require('mqemitter-redis') | ||
const abs = require('aedes-cached-persistence/abstract') | ||
|
||
function unref () { | ||
this.connector.stream.unref() | ||
} | ||
|
||
const nodes = [ | ||
{ host: 'localhost', port: 6378 }, | ||
{ host: 'localhost', port: 6380 }, | ||
{ host: 'localhost', port: 6381 }, | ||
{ host: 'localhost', port: 6382 }, | ||
{ host: 'localhost', port: 6383 }, | ||
{ host: 'localhost', port: 6384 } | ||
] | ||
|
||
const db = new Redis.Cluster(nodes) | ||
|
||
db.on('error', e => { | ||
console.trace(e) | ||
}) | ||
|
||
db.on('ready', function () { | ||
abs({ | ||
test, | ||
buildEmitter () { | ||
const emitter = mqemitterRedis() | ||
emitter.subConn.on('connect', unref) | ||
emitter.pubConn.on('connect', unref) | ||
|
||
return emitter | ||
}, | ||
persistence (cb) { | ||
const slaves = db.nodes('master') | ||
Promise.all(slaves.map(function (node) { | ||
return node.flushdb().catch(err => { | ||
console.error('flushRedisKeys-error:', err) | ||
}) | ||
})).then(() => { | ||
const conn = new Redis.Cluster(nodes) | ||
|
||
conn.on('error', e => { | ||
console.trace(e) | ||
}) | ||
|
||
conn.on('ready', function () { | ||
cb(null, persistence({ | ||
conn, | ||
cluster: true | ||
})) | ||
}) | ||
}) | ||
}, | ||
waitForReady: true | ||
}) | ||
|
||
test.onFinish(() => { | ||
process.exit(0) | ||
}) | ||
}) |