Upgrading Rocket.Chat along with deprecated MongoDB mmapv1 to wiredTiger storage engine

Hi everyone!
I’m trying to migrate my deprecated MongoDB from mmapv1 storage engine to wiredTiger storage engine to be able to update Rocket.Chat.

Right now the set up is through Ubuntu 22.04 / Docker.
You can see below details of the Rocket.chat containers:

Rocket.Chat Container

±-----------------------------------------------+
| SERVER RUNNING |
±-----------------------------------------------+
| |
| Rocket.Chat Version: 4.5.0 |
| NodeJS Version: 14.18.3 - x64 |
| MongoDB Version: 4.0.28 |
| MongoDB Engine: mmapv1 |
| Platform: linux |
| Process Port: 3000 |
| Site URL: https:// |
| ReplicaSet OpLog: Enabled |
| Commit Hash: 3901xxxxxx |
| Commit Branch: HEAD |
| |
±-----------------------------------------------+
±---------------------------------------------------------------------+
| DEPRECATION |
±---------------------------------------------------------------------+
| |
| YOUR CURRENT MONGODB VERSION (4.0.28) IS DEPRECATED. |
| IT WILL NOT BE SUPPORTED ON ROCKET.CHAT VERSION 5.0.0 AND GREATER, |
| PLEASE UPGRADE MONGODB TO VERSION 4.2 OR GREATER |
| |
±---------------------------------------------------------------------+

MongoDB container

22-06-10T11:51:07.462+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=c7593367e1ae
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] db version v4.0.28
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] git version: af1a9dc12adcfa83cc19571cb3faba26eeddac92
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] allocator: tcmalloc
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] modules: none
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] build environment:
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] distarch: x86_64
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] target_arch: x86_64
2022-06-10T11:51:07.470+0000 I CONTROL [initandlisten] options: { net: { bindIpAll: true }, replication: { oplogSizeMB: 128, replSet: “rs0” }, storage: { engine: “mmapv1”, mmapv1: { smallFiles: true } } }
2022-06-10T11:51:07.470+0000 I STORAGE [initandlisten]
2022-06-10T11:51:07.470+0000 I STORAGE [initandlisten] ** WARNING: Support for MMAPV1 storage engine has been deprecated and will be
2022-06-10T11:51:07.470+0000 I STORAGE [initandlisten] ** removed in version 4.2. Please plan to migrate to the wiredTiger
2022-06-10T11:51:07.470+0000 I STORAGE [initandlisten] ** storage engine.
2022-06-10T11:51:07.470+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/deprecated-mmapv1
2022-06-10T11:51:07.470+0000 I STORAGE [initandlisten]
2022-06-10T11:51:07.484+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
2022-06-10T11:51:07.484+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2022-06-10T11:51:07.490+0000 I JOURNAL [durability] Durability thread started
2022-06-10T11:51:07.490+0000 I JOURNAL [journal writer] Journal writer thread started
2022-06-10T11:51:07.495+0000 I CONTROL [initandlisten]
2022-06-10T11:51:07.495+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2022-06-10T11:51:07.495+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2022-06-10T11:51:07.495+0000 I CONTROL [initandlisten]
2022-06-10T11:51:07.608+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory ‘/data/db/diagnostic.data’
2022-06-10T11:51:07.613+0000 I REPL [initandlisten] Rollback ID is 1
2022-06-10T11:51:07.614+0000 I REPL [initandlisten] Recovering from an unstable checkpoint (top of oplog: { ts: Timestamp(1654861250, 1), t: 617 }, appliedThrough: { ts: Timestamp(0, 0), t: -1 })
2022-06-10T11:51:07.614+0000 I REPL [initandlisten] No oplog entries to apply for recovery. appliedThrough is null.
2022-06-10T11:51:07.644+0000 I REPL [replexec-0] New replica set config in use: { _id: “rs0”, version: 1, protocolVersion: 1, writeConcernMajorityJournalDefault: true, members: [ { _id: 0, host: “localhost:27017”, arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 } ], settings: { chainingAllowed: true, heartbeatIntervalMillis: 2000, heartbeatTimeoutSecs: 10, electionTimeoutMillis: 10000, catchUpTimeoutMillis: -1, catchUpTakeoverDelayMillis: 30000, getLastErrorModes: {}, getLastErrorDefaults: { w: 1, wtimeout: 0 }, replicaSetId: ObjectId(‘60029f5619ed4eaf0e49e6ba’) } }
2022-06-10T11:51:07.644+0000 I REPL [replexec-0] This node is localhost:27017 in the config
2022-06-10T11:51:07.644+0000 I REPL [replexec-0] transition to STARTUP2 from STARTUP
2022-06-10T11:51:07.644+0000 I REPL [replexec-0] Starting replication storage threads
2022-06-10T11:51:07.645+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2022-06-10T11:51:07.645+0000 I REPL [replexec-0] transition to RECOVERING from STARTUP2
2022-06-10T11:51:07.645+0000 I REPL [replexec-0] Starting replication fetcher thread
2022-06-10T11:51:07.645+0000 I REPL [replexec-0] Starting replication applier thread
2022-06-10T11:51:07.645+0000 I REPL [replexec-0] Starting replication reporter thread
2022-06-10T11:51:07.646+0000 I NETWORK [LogicalSessionCacheRefresh] Starting new replica set monitor for rs0/localhost:27017
2022-06-10T11:51:07.646+0000 I REPL [rsSync-0] Starting oplog application
2022-06-10T11:51:07.646+0000 I REPL [rsSync-0] transition to SECONDARY from RECOVERING
2022-06-10T11:51:07.646+0000 I REPL [rsSync-0] conducting a dry run election to see if we could be elected. current term: 617
2022-06-10T11:51:07.646+0000 I ASIO [ReplicaSetMonitor-TaskExecutor] Connecting to localhost:27017
2022-06-10T11:51:07.646+0000 I REPL [replexec-0] dry election run succeeded, running for election in term 618
2022-06-10T11:51:07.647+0000 I NETWORK [listener] connection accepted from 127.0.0.1:36758 #2 (1 connection now open)
2022-06-10T11:51:07.648+0000 I NETWORK [conn2] received client metadata from 127.0.0.1:36758 conn2: { driver: { name: “NetworkInterfaceTL”, version: “4.0.28” }, os: { type: “Linux”, name: “Ubuntu”, architecture: “x86_64”, version: “16.04” } }
2022-06-10T11:51:07.657+0000 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Unable to reach primary for set rs0
2022-06-10T11:51:07.677+0000 I REPL [replexec-0] election succeeded, assuming primary role in term 618
2022-06-10T11:51:07.677+0000 I REPL [replexec-0] transition to PRIMARY from SECONDARY
2022-06-10T11:51:07.677+0000 I REPL [replexec-0] Resetting sync source to empty, which was :27017
2022-06-10T11:51:07.678+0000 I REPL [replexec-0] Entering primary catch-up mode.
2022-06-10T11:51:07.678+0000 I REPL [replexec-0] Exited primary catch-up mode.
2022-06-10T11:51:07.678+0000 I REPL [replexec-0] Stopping replication producer
2022-06-10T11:51:07.678+0000 I REPL [ReplBatcher] Oplog buffer has been drained in term 618
2022-06-10T11:51:07.680+0000 I REPL [rsSync-0] transition to primary complete; database writes are now permitted
2022-06-10T11:51:08.010+0000 I NETWORK [listener] connection accepted from 172.19.0.4:43068 #3 (2 connections now open)

Now, when trying to migrate to wiredTiger storage engine, I use the following docker-compose file as per in the documentation, together with the docker directory.
After stooping all the containers, I do the necessary modifications to match my setup:

version: '2'

services:
  rocketchat:
    image: rocketchat/rocket.chat:4.5.0
    command: >
      bash -c
        "for (( ; ; )); do
          node main.js &&
          s=$$? && break || s=$$?;
          echo \"Could not start Rocket.Chat. Waiting 5 secs...\";
          sleep 5;
        done; (exit $$s)"
    restart: unless-stopped
    volumes:
      - /home/ubu/rocket/uploads:/app/uploads
    environment:
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - MAIL_URL=smtp://smtp.email
    depends_on:
      - mongo
    ports:
      - 3170:3000
    labels:
      - "traefik.backend=rocketchat"
      - "traefik.frontend.rule=Host: your.domain.tld"

  mongo:
    image: mongo:4.0
    restart: unless-stopped
    volumes:
      - ./data/db:/data/db
#      - ./data/db:/data/configdb
      - ./data/dump:/dump
    command: >
      bash -c
        "while [ ! -f /data/db/WiredTiger ]; do
          echo \"wiredTiger migration hasn't started yet. Waiting 30 secs...\";
          sleep 30;
        done;
        docker-entrypoint.sh mongod --oplogSize 128 --replSet rs0 --storageEngine=wiredTiger;"
    depends_on:
      - migrator
    labels:
      - "traefik.enable=false"

  migrator:
    build: ./docker/
    volumes:
     - /home/ubu/rocket/data/db:/data/db

  mongo-init-replica:
    image: mongo:4.0
    command: >
      bash -c
        "for (( ; ; )); do
          mongo mongo/rocketchat --eval \"
            rs.initiate({
              _id: 'rs0',
              members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
          s=$$? && break || s=$$?;
          echo \"Could not reach MongoDB. Waiting 5 secs ...\";
          sleep 5;
        done; (exit $$s)"
    depends_on:
      - mongo

Once it is run the below is the output:

Rocket.Chat Container

/app/bundle/programs/server/node_modules/fibers/future.js:313
throw(ex);
^

MongoServerSelectionError: connect ECONNREFUSED 172.19.0.3:27017
at Timeout._onTimeout (/app/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/sdam/topology.js:437:30)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7) {
reason: TopologyDescription {
type: ‘Single’,
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
‘mongo:27017’ => ServerDescription {
address: ‘mongo:27017’,
error: Error: connect ECONNREFUSED 172.19.0.3:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
name: ‘MongoNetworkError’
},
roundTripTime: -1,
lastUpdateTime: 12189726,
lastWriteDate: null,
opTime: null,
type: ‘Unknown’,
topologyVersion: undefined,
minWireVersion: 0,
maxWireVersion: 0,
hosts: ,
passives: ,
arbiters: ,
tags:
}
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
Could not start Rocket.Chat. Waiting 5 secs…

MongoDB Container

wiredTiger migration hasn’t started yet. Waiting 30 secs…
wiredTiger migration hasn’t started yet. Waiting 30 secs…
wiredTiger migration hasn’t started yet. Waiting 30 secs…
wiredTiger migration hasn’t started yet. Waiting 30 secs…
wiredTiger migration hasn’t started yet. Waiting 30 secs…

Rocket Migrator

2022-06-10T12:27:49.181+0000 E QUERY [js] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:356:17
@(connect):2:6
exception: connect failed
MongoDB shell version v4.0.28
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2022-06-10T12:27:50.240+0000 E QUERY [js] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:356:17
@(connect):2:6
exception: connect failed
MongoDB shell version v4.0.28
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2022-06-10T12:27:51.306+0000 E QUERY [js] Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:356:17
@(connect):2:6
exception: connect failed
MongoDB shell version v4.0.28
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb

I guess at this point the Rocket Migrator should be migrating MongoDB from mmapv1 storage engine to wiredTiger storage engine but as you can see it doesn’t even connect.

Appreciate any help!!
Thank you!
Alex

P.S. Just clarifying that I do dockers as my hobby so I don’t know much about it, just trying to learn atm. If I need to clarify something please let me know. Also if someone can help me please note that I might need some help to understand the terms since I’m not very related to this databases and stuff :slight_smile:
Thank you again!

Hi!

Have you seen this post from one of our users?

this migrations is in fact a backup and restore procedure.

Also, linking here for reference our oficial docs for this:

Let me know if this helps. Thanks!

Hi Duda!
Really appreciate your fast reply!

As in Scotti’s guide, I was running Rocket.Chat from a random directory but from /opt/rocketchat .
That was a great hope for me…
Although, after modifying my Rocket.chat’s directories to /opt/rocketchat , unfortunatelly I’m getting exactly the same errors once the containers are running,
except for the below:

root@ubuntu:/opt/rocketchat# docker-compose up --build -d
Building migrator
Sending build context to Docker daemon 4.608kB
Step 1/3 : FROM mongo:4.0
—> 362f994056cd
Step 2/3 : COPY entrypoint.sh /usr/local/bin/
—> 242766cfd41d
Step 3/3 : ENTRYPOINT [“entrypoint.sh”]
—> Running in 24111c09df86
Removing intermediate container 24111c09df86
—> dce1f471b6ff
Successfully built dce1f471b6ff
Successfully tagged rocketchat_migrator:latest
Pulling rocketchat (rocketchat/rocket.chat:latest)…
latest: Pulling from rocketchat/rocket.chat
5eb5b503b376: Already exists
53f484eb7703: Already exists
423d488a1c7f: Already exists
a61f2cdd00c2: Already exists
d8d26a06e41d: Already exists
51d345d997ec: Pull complete
4b23bfd2d1fc: Pull complete
3f9254e55a74: Pull complete
Digest: sha256:a092057e2f0c527f46ebf8e66fe83c473aa043ddc20d775c2140e242d65da09e
Status: Downloaded newer image for rocketchat/rocket.chat:latest
Creating rocketchat_migrator_1 … done
Recreating rocketchat-mongo-1 … done
Recreating rocketchat-rocketchat-1 … done
Recreating rocketchat-mongo-init-replica-1 … done

That before it used to be only:

root@ubuntu:/opt/rocketchat# docker-compose up --build -d
Successfully tagged rocketchat_migrator:latest
Pulling rocketchat (rocketchat/rocket.chat:latest)…
latest: Pulling from rocketchat/rocket.chat
5eb5b503b376: Already exists
53f484eb7703: Already exists
423d488a1c7f: Already exists
a61f2cdd00c2: Already exists
d8d26a06e41d: Already exists
51d345d997ec: Pull complete
4b23bfd2d1fc: Pull complete
3f9254e55a74: Pull complete
Digest: sha256:a092057e2f0c527f46ebf8e66fe83c473aa043ddc20d775c2140e242d65da09e
Status: Downloaded newer image for rocketchat/rocket.chat:latest
Creating rocketchat_migrator_1 … done
Recreating rocketchat-mongo-1 … done
Recreating rocketchat-rocketchat-1 … done
Recreating rocketchat-mongo-init-replica-1 … done

For the rest everything the same…
No luck yet.

Thank you for your help, really appreciate it!
Alex

I also followed the videos for the upgrade. However I stayed at the same Rocket.Chat version all they way through the nmap1 → WiredTiger + DB upgrade, BEFORE I also updated Rocket.Chat itself. Have no clue if it makes a difference or not, but it worked for me.

That workeeeed! Thanks a lot!

Now it’s running Rocket.Chat :latest and MongoDB:4.2 of course with WiredTiger.

However not working when trying to update to MongoDB:4.4

:smiling_face_with_tear:

I will try again and see what happens.

Thank you again!

My DB upgrade was done by:

MongoDB upgrade

Change two references in docker-compose.yml file. Change it to the version which you are converting TO. E.g. change 4.0 → 4.2.
Run:

docker-compose stop mongo
docker-compose rm mongo
docker-compose up -d mongo

docker exe -it rocketchat_mongo_1 bash

mongo

db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )

exit
exit

Change the ‘4.2’ in the adminCommand to the relevant version.

Repeat it for each DB upgrade, e.g. 4.2 → 4.4 and 4-4 > 5.0.

Make sure you’ve also uncommented:

./data/dump:/dump

in the docker-compose-yml file, and created the directory

mkdir /opt/rocketchat/data/dump

if you wish to create database backups/dumps. Actually don’t know if it’s also needed for DB conversions.

Okay! It’s updated, RocketChat to 4.8.1 and MongoDB to 5.0!!!

Basically I was ignoring this part for some reason:

docker exe -it rocketchat_mongo_1 bash

mongo

db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )

exit
exit

After updating MongoDB from 4.0 to 4.2 it was working so for some reason I thought this bash setup was not needed, and continued updating to next MongoDB but of course after 4.2 wasn’t working, that was the issue.
After following your instructions everything went smooth and as expected!!

Thank you very much for your support and advises!

Best regards,

Alex

Glad I could help. After my own hard struggle, it’s only nice to be able to give something back :slight_smile:

2 Likes

and that’s the beauty of Open Source!

Thanks for sharing!

1 Like

Definitively! :star_struck:
Thank you again!