8
8
( function ( ) {
9
9
"use strict" ;
10
10
11
- const replSet = new ReplSetTest ( { nodes : 2 } ) ;
11
+ // Construct a replica set where the same node remains primary across restarts, because the
12
+ // system.profile collection is not replicated.
13
+ const replSet = new ReplSetTest ( {
14
+ nodes : [
15
+ { } ,
16
+ { rsConfig : { priority : 0 } } ,
17
+ ]
18
+ } ) ;
12
19
replSet . startSet ( ) ;
13
20
replSet . initiate ( ) ;
14
21
@@ -26,6 +33,7 @@ assertCatalogStats(db1, (stats) => {
26
33
assert . eq ( 0 , stats . capped ) ;
27
34
assert . eq ( 0 , stats . clustered ) ;
28
35
assert . eq ( 0 , stats . collections ) ;
36
+ assert . eq ( 0 , stats . systemProfile ) ;
29
37
assert . eq ( 0 , stats . timeseries ) ;
30
38
assert . eq ( 0 , stats . views ) ;
31
39
internalCollectionsAtStart = stats . internalCollections ;
@@ -39,14 +47,25 @@ assert.commandWorked(
39
47
assert . commandWorked ( db1 . createCollection ( 'view' , { viewOn : 'coll' , pipeline : [ ] } ) ) ;
40
48
assert . commandWorked ( db1 . createCollection ( 'ts' , { timeseries : { timeField : 't' } } ) ) ;
41
49
50
+ // A system.views and system.buckets collection should have been created.
51
+ let internalCollectionsCreated = 2 ;
52
+
53
+ // Create the profile collection.
54
+ assert . commandWorked ( db1 . setProfilingLevel ( 2 , 0 ) ) ;
55
+ assert . eq ( 1 , db1 . coll . find ( { } ) . itcount ( ) ) ;
56
+ internalCollectionsCreated += 1 ;
57
+
58
+ // Turn off profiler to avoid creating extra collections.
59
+ assert . commandWorked ( db1 . setProfilingLevel ( 0 , 100 ) ) ;
60
+
42
61
assertCatalogStats ( db1 , ( stats ) => {
43
62
assert . eq ( 1 , stats . capped ) ;
44
63
assert . eq ( 1 , stats . clustered ) ;
45
64
assert . eq ( 3 , stats . collections ) ;
65
+ assert . eq ( 1 , stats . systemProfile ) ;
46
66
assert . eq ( 1 , stats . timeseries ) ;
47
67
assert . eq ( 1 , stats . views ) ;
48
- // A system.views and system.buckets collection should have been created.
49
- assert . eq ( internalCollectionsAtStart + 2 , stats . internalCollections ) ;
68
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
50
69
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
51
70
} ) ;
52
71
@@ -56,10 +75,11 @@ assertCatalogStats(db1, (stats) => {
56
75
assert . eq ( 1 , stats . capped ) ;
57
76
assert . eq ( 1 , stats . clustered ) ;
58
77
assert . eq ( 3 , stats . collections ) ;
78
+ assert . eq ( 1 , stats . systemProfile ) ;
59
79
assert . eq ( 1 , stats . timeseries ) ;
60
80
assert . eq ( 1 , stats . views ) ;
61
81
// An system.views and system.buckets collection should have been created.
62
- assert . eq ( internalCollectionsAtStart + 2 , stats . internalCollections ) ;
82
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
63
83
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
64
84
} ) ;
65
85
@@ -70,14 +90,17 @@ assert.commandWorked(
70
90
assert . commandWorked ( db2 . createCollection ( 'view' , { viewOn : 'coll' , pipeline : [ ] } ) ) ;
71
91
assert . commandWorked ( db2 . createCollection ( 'ts' , { timeseries : { timeField : 't' } } ) ) ;
72
92
93
+ // An system.views and system.buckets collection should have been created.
94
+ internalCollectionsCreated += 2 ;
95
+
73
96
assertCatalogStats ( db1 , ( stats ) => {
74
97
assert . eq ( 2 , stats . capped ) ;
75
98
assert . eq ( 2 , stats . clustered ) ;
76
99
assert . eq ( 6 , stats . collections ) ;
100
+ assert . eq ( 1 , stats . systemProfile ) ;
77
101
assert . eq ( 2 , stats . timeseries ) ;
78
102
assert . eq ( 2 , stats . views ) ;
79
- // An system.views and system.buckets collection should have been created.
80
- assert . eq ( internalCollectionsAtStart + 4 , stats . internalCollections ) ;
103
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
81
104
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
82
105
} ) ;
83
106
@@ -92,9 +115,10 @@ assertCatalogStats(db1, (stats) => {
92
115
assert . eq ( 2 , stats . capped ) ;
93
116
assert . eq ( 2 , stats . clustered ) ;
94
117
assert . eq ( 6 , stats . collections ) ;
118
+ assert . eq ( 1 , stats . systemProfile ) ;
95
119
assert . eq ( 2 , stats . timeseries ) ;
96
120
assert . eq ( 2 , stats . views ) ;
97
- assert . eq ( internalCollectionsAtStart + 4 , stats . internalCollections ) ;
121
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
98
122
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
99
123
} ) ;
100
124
@@ -104,39 +128,49 @@ assert(db1.clustered.drop());
104
128
assert ( db1 . view . drop ( ) ) ;
105
129
assert ( db1 . ts . drop ( ) ) ;
106
130
131
+ // The system.buckets collection will be dropped, but not system.views.
132
+ internalCollectionsCreated -= 1 ;
133
+
107
134
assertCatalogStats ( db1 , ( stats ) => {
108
135
assert . eq ( 1 , stats . capped ) ;
109
136
assert . eq ( 1 , stats . clustered ) ;
110
137
assert . eq ( 3 , stats . collections ) ;
138
+ assert . eq ( 1 , stats . systemProfile ) ;
111
139
assert . eq ( 1 , stats . timeseries ) ;
112
140
assert . eq ( 1 , stats . views ) ;
113
- // The system.views collection will stick around
114
- assert . eq ( internalCollectionsAtStart + 3 , stats . internalCollections ) ;
141
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
115
142
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
116
143
} ) ;
117
144
118
145
db1 . dropDatabase ( ) ;
119
146
147
+ // The system.views and system.profile collections should be dropped.
148
+ internalCollectionsCreated -= 2 ;
149
+
120
150
assertCatalogStats ( db1 , ( stats ) => {
121
151
assert . eq ( 1 , stats . capped ) ;
122
152
assert . eq ( 3 , stats . collections ) ;
153
+ // The system.profile collection should be dropped.
154
+ assert . eq ( 0 , stats . systemProfile ) ;
123
155
assert . eq ( 1 , stats . timeseries ) ;
124
156
assert . eq ( 1 , stats . views ) ;
125
- // The system.views collection should be dropped
126
- assert . eq ( internalCollectionsAtStart + 2 , stats . internalCollections ) ;
157
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
127
158
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
128
159
} ) ;
129
160
130
161
db2 . dropDatabase ( ) ;
131
162
163
+ // The system.views and system.buckets collections should be dropped.
164
+ internalCollectionsCreated -= 2 ;
165
+
132
166
assertCatalogStats ( db1 , ( stats ) => {
133
167
assert . eq ( 0 , stats . capped ) ;
134
168
assert . eq ( 0 , stats . clustered ) ;
135
169
assert . eq ( 0 , stats . collections ) ;
170
+ assert . eq ( 0 , stats . systemProfile ) ;
136
171
assert . eq ( 0 , stats . timeseries ) ;
137
172
assert . eq ( 0 , stats . views ) ;
138
- // The system.views collection should be dropped
139
- assert . eq ( internalCollectionsAtStart , stats . internalCollections ) ;
173
+ assert . eq ( internalCollectionsAtStart + internalCollectionsCreated , stats . internalCollections ) ;
140
174
assert . eq ( internalViewsAtStart , stats . internalViews ) ;
141
175
} ) ;
142
176
0 commit comments