Upgrade to MongoDB 4.0
Antonios Giannopoulos DBA @ Rackspace/ObjectRocket linkedin.com/in/antonis/
1
Upgrade to MongoDB 4.0 Antonios Giannopoulos DBA @ - - PowerPoint PPT Presentation
Upgrade to MongoDB 4.0 Antonios Giannopoulos DBA @ Rackspace/ObjectRocket linkedin.com/in/antonis/ 1 Introduction Antonios Giannopoulos www.objectrocket.com 2 Overview Upgrade Procedure Application Layer Middleware
Antonios Giannopoulos DBA @ Rackspace/ObjectRocket linkedin.com/in/antonis/
1
www.objectrocket.com
2
Antonios Giannopoulos
www.objectrocket.com
3
www.objectrocket.com
4
MongoDB 4.0 released on June 26,2018 Current minor version is 4.0.3 You can obtain it from:
www.objectrocket.com
5
www.objectrocket.com
6
Upgrade the secondary, one at a time
Connect a mongo shell to the primary
Upgrade the ex-Primary
Connect a mongo shell to the primary Enable backwards-incompatible 4.0 features db.adminCommand( { setFeatureCompatibilityVersion: "4.0" }
www.objectrocket.com
7 s1 s2
Stop Balancer
Upgrade config servers
Upgrade the shards
Upgrade the mongos
Enable backwards-incompatible 4.0 features db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } ) Restart the mongos
www.objectrocket.com
8
www.objectrocket.com
9
Your driver must be compactible with 4.0
www.objectrocket.com
10
www.objectrocket.com
11
www.objectrocket.com
12
The underling language version must also be compactible with your driver
Mongo 4.0 Compatible
www.objectrocket.com
13
Perform safe upgrades /always have rollback in mind Python supports “virtual environments” Python “virtualenv” creates an isolated environment for Python projects. Each project can have its own dependencies, regardless of what dependencies every other project has. There are no limits to the number of environments ,they’re just directories containing scripts
www.objectrocket.com
14
www.objectrocket.com
15
What about other languages: There are equivalents of “virtualenv” like JAVA use classpath Ruby use Ruby Version Manager (RVM)
www.objectrocket.com
16
Do not forget frameworks and their dependencies
Should I always use the latest driver?
www.objectrocket.com
17
Inspect the logs Manipulate the logs to export driver name & version Quick hack:
less /var/log/messages |grep "driver: { name" | awk '{print $16, $17, $18, $19}' | uniq
www.objectrocket.com
18
Inspect the system.profile Collect a representative sample On a sharded cluster, all shards must examined.
www.objectrocket.com
19
Each version Removes & Deprecates operators. Remove: Operator is no longer available Deprecate: Operator will be removed to the next version Take Actions:
www.objectrocket.com
20
Removed Operators:
If you have an existing partial index that includes the $isolated operator or a view that includes a $isolated operator, recreate the index
Deprecated Operators:
www.objectrocket.com
21
Exception handling
www.objectrocket.com
22
www.objectrocket.com
23
The monitoring system must be able to connect to MongoDB Vast majority relies on db.serverStatus() A newer version may be necessary to installed prior to upgrade
www.objectrocket.com
24
Automatic deployment scripts also connect to MongoDB For example:
A change to error code formats may affect deployment scripts User-roles may also change Management tools may also affected
www.objectrocket.com
25
They should all work but testing is recommended. In the case of restore, a downgrade may be required.
www.objectrocket.com
26
Removes support for:
Deprecates:
Compatibility matrix: https://bit.ly/2ys8Crs
www.objectrocket.com
27
Removes support for TLS 1.0
Latest PCI compliance standards require the use of TLS 1.1+
If you need to support TLS 1.0 (hopefully temporarily):
Test:
www.objectrocket.com
28
www.objectrocket.com
29
net.transportLayer cant be set to legacy anymore net.host: Resolves localhost IP address as configured instead of assuming 127.0.0.1 Can’t combine storage.journal.enabled: false with WiredTiger storage engine Can’t combine storage.indexBuildRetry with replication.replSetName When ssl.allowInvalidCertificates: true with x.509 authentication, an invalid certificate is only sufficient to establish a TLS/SSL connection but is insufficient for authentication.
www.objectrocket.com
30
In order to upgrade featureCompatibilityVersion must be set to 3.6 How to check:
How to set FCV to 3.6:
,where <version> ”3.6” It automatically enables 3.6 new features
www.objectrocket.com
31
3.6 new features
Sessions:
www.objectrocket.com
32
In order to upgrade pv must be set to pv1 How to check:
How to set pv1:
cfg = rs.conf(); cfg.protocolVersion=1; rs.reconfig(cfg);
Enjoy the benefits of pv1
www.objectrocket.com
33
Master-slave replication, no longer supported You must upgrade to a replica set Prior the upgrade Conversion involves downtime & affects high availability
rs.initiate( { _id: "<setname>", members: [ { _id: 0, host: "<host:port>" } ] } )
www.objectrocket.com
34
Removes MongoDB Challenge-Response (MONGODB-CR) auth mechanism Deprecated since 3.0 version. Only possible if you upgraded from 2.6 How to check:
db.getSiblingDB('admin').system.users.find({"credentials.MONGODB-CR":{$exists:true}})
How to upgrade to SCRAM:
db.adminCommand({authSchemaUpgrade: 1});
Considerations
www.objectrocket.com
35
MongoDB 4.0 deprecates MMAPv1 It’s likely the next version to support only WiredTiger You should consider a switch to WiredTiger Change to WiredTiger may be challenging:
www.objectrocket.com
36
storage: dbPath: <data dir> engine: mmapv1 mmapv1: <mmap configuration> storage: dbPath: <data dir> engine: wiredTiger mmapv1: <mmap configuration> wiredTiger: collectionConfig: blockCompressor: <value> engineConfig: cacheSizeGB: <value> directoryForIndexes: true journalCompressor: <value> indexConfig: prefixCompression: <value>
www.objectrocket.com
37
Switch to WT (without secondary reads) 1)Convert one secondary
2)Promote the secondary to become Primary
3)Burn Period
Freeze
www.objectrocket.com
38
Switch to WT (secondary reads) 1)Convert one secondary 3)Promote the secondary to become Primary 2)Burn Period (Secondary) 4)Burn Period (Primary) Important: Make sure less secondary can serve your workload
www.objectrocket.com
39
What can I do in advance?
Workloads that MMAPv1 may perform better
www.objectrocket.com
40
www.objectrocket.com
41
taskExecutorPoolSize: Number of Task Executor connection pools
AsyncRequestsSenderUseBaton: Default true Enables performance optimization on Linux for scatter/gather operations
www.objectrocket.com
42
db.adminCommand({setFeatureCompatibilityVersion: ”4.0"})
www.objectrocket.com
43
Enables:
www.objectrocket.com
44
Major Version Replica-set Sharded Cluster Reason 2.2 2.2.3 2.4 2.4.3 2.4.6 Chunk Migration 2.6 2.6.6 2.6.6 Optimizer 3.0 3.0.5 3.0.8 Data loss 3.2 3.2.6 3.2.11 ASIO bug 3.4 3.4.4 3.4.7 Minor bugs 3.6 3.6.3 3.6.8 sessions
www.objectrocket.com
45
www.objectrocket.com
46
Downgrade FCV to 3.6
Remove incompatible features:
db.updateUser( ”username", { mechanisms: [ "SCRAM-SHA-1" ], pwd: <newpwd> } )
www.objectrocket.com
47
Downgrade the secondary, one at a time
Connect a mongo shell to the primary
Upgrade the ex-Primary
www.objectrocket.com
s1 s2
Stop Balancer
Downgrade config servers
Downgrade the shards
Downgrade the mongos
Start Balancer
www.objectrocket.com
49
www.objectrocket.com
50
MongoDB 4.0 supports multi-document transactions
www.objectrocket.com
51
www.objectrocket.com
52
www.objectrocket.com
53
*excluding admin, local, and config database ** In 3.6 the type is BinData
www.objectrocket.com
54
Before 4.0
In 4.0
www.objectrocket.com
55
www.objectrocket.com
56
$near and $nearSphere supports querying on sharded collections Adds key option for the $geoNear aggregation operator and geoNear command Mongos can log slow statements: Command line options: slowms Configuration file options: operationProfiling.slowOpThresholdMs Mongos can rate limit slow statements: Command line options: --slowOpSampleRate Configuration file options: operationProfiling.slowOpSampleRate Mongo shell method supports convertShardKeyToHashed
www.objectrocket.com
57
Aggregation framework supports $convert Converts a value to specified type:
www.objectrocket.com
58
www.objectrocket.com
59
Address: 401 Congress Ave Suite 1950 Austin, TX 78701 Support: 1-800-961-4454 Sales: 1-888-440-3242 www.objectrocket.com
60