Skip to content

Commit 1df7ba3

Browse files
rueckstiesskangas
authored andcommitted
INT-1242 improve maxTimeMS behavior
3 states: - maxTimeMS hits without any documents returned - maxTimeMS hits but partial documents have already been returned - sampling takes longer but maxTimeMS is not reached (this case is possible because maxTimeMS counts only operational time spent actively working on the database, not wall time)
1 parent f15ea6f commit 1df7ba3

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"mongodb-js-metrics": "^1.0.0",
8888
"mongodb-language-model": "^0.3.3",
8989
"mongodb-ns": "^1.0.3",
90-
"mongodb-schema": "^4.1.0",
90+
"mongodb-schema": "^4.2.0",
9191
"ms": "^0.7.1",
9292
"node-notifier": "^4.3.1",
9393
"numeral": "^1.5.3",

src/app/models/sampled-schema.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ module.exports = Schema.extend({
106106
if (success) {
107107
success(model, resp, options);
108108
}
109-
model.trigger('sync');
110109
};
111110

112111
var start = new Date();
@@ -159,6 +158,7 @@ module.exports = Schema.extend({
159158
'total analysis time': totalTime - timeToFirstDoc,
160159
'average analysis time per doc': (totalTime - timeToFirstDoc) / sampleCount
161160
});
161+
model.trigger('sync');
162162
options.success({});
163163
};
164164

@@ -174,8 +174,6 @@ module.exports = Schema.extend({
174174
return options.success({});
175175
}
176176

177-
debug('count', count);
178-
179177
var status = 0;
180178
var numSamples = Math.min(options.size, count);
181179
var stepSize = Math.ceil(Math.max(1, numSamples / 10));
@@ -215,14 +213,10 @@ module.exports = Schema.extend({
215213
schemaStatusSubview.error = true;
216214
onFail(analysisErr);
217215
})
218-
.on('data', function() {
219-
if (sampleCount >= numSamples) {
216+
.on('end', function() {
217+
if (sampleCount === numSamples) {
220218
return onEnd();
221219
}
222-
// workaround, as 'data' seems to be emitted even when sample stage
223-
// has an error. @ChristianKvalheim investigating.
224-
debug('did not receive data from the driver.');
225-
onFail(new Error('did not receive data from driver.'));
226220
});
227221
});
228222
},
@@ -231,17 +225,13 @@ module.exports = Schema.extend({
231225
this.fetch();
232226
},
233227
stopAnalyzing: function() {
234-
if (!this.is_fetching) {
235-
return;
228+
if (this.is_fetching) {
229+
this.is_fetching = false;
230+
this.samplingStream.destroy();
231+
this.analyzingStream.destroy();
236232
}
237-
this.is_fetching = false;
238-
// @todo thomasr, uncomment this line once we figured out why
239-
// app.client.sample() is not emitting any events anymore.
240-
// for now, we can use app.client.find instead.
241-
242-
// this.samplingStream.destroy();
243-
this.analyzingStream.destroy();
244233
app.statusbar.hide(true);
234+
this.trigger('sync');
245235
},
246236
serialize: function() {
247237
var res = this.getAttributes({

src/app/statusbar/schema-subview.jade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ div#schema-status-subview
1010
| Analyzing Documents
1111

1212
div.buttons(data-hook='buttons')
13-
div#buttons-sampling
13+
div#buttons-error
1414
div.alert.alert-warning(role='alert', data-hook='sampling-info')
1515
| Sampling took longer than 
1616
span(data-hook='maxtimems') 10 seconds
@@ -20,9 +20,9 @@ div#schema-status-subview
2020
i.fa.fa-fw.fa-info-circle
2121
br
2222
div.btn.btn-info(data-hook='increase-maxtimems-button') Try for 1 minute
23-
div.btn.btn-info(data-hook='create-new-query-button') Create new query
23+
div.btn.btn-info(data-hook='next-action-button')
2424

25-
div#buttons-analyzing
25+
div#buttons-waiting
2626
div.alert.alert-info(role='alert', data-hook='analyzing-info') Document analysis is taking longer than expected.  
2727
a.help(data-hook='schema-long-running-queries')
2828
| Learn More

src/app/statusbar/schema-subview.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var subviewTemplate = jade.compileFile(path.resolve(__dirname, 'schema-subview.j
99

1010

1111
var SHOW_STEPS_MS = 3000;
12-
var SHOW_ANALYZING_BUTTONS_MS = 10000;
12+
var SHOW_ANALYZING_BUTTONS_MS = app.queryOptions.maxTimeMS + 1000;
1313

1414
module.exports = View.extend({
1515
template: subviewTemplate,
@@ -41,6 +41,13 @@ module.exports = View.extend({
4141
}
4242
},
4343
derived: {
44+
nextActionLabel: {
45+
deps: ['activeStep'],
46+
fn: function() {
47+
return this.activeStep === 'sampling' ?
48+
'Create new Query' : 'Show partial results';
49+
}
50+
},
4451
samplingState: {
4552
deps: ['activeStep', 'error'],
4653
fn: function() {
@@ -67,6 +74,10 @@ module.exports = View.extend({
6774
}
6875
},
6976
bindings: {
77+
nextActionLabel: {
78+
hook: 'next-action-button',
79+
type: 'text'
80+
},
7081
stepsVisible: {
7182
type: 'toggle',
7283
hook: 'steps',
@@ -77,15 +88,20 @@ module.exports = View.extend({
7788
hook: 'buttons',
7889
mode: 'visibility'
7990
},
91+
error: {
92+
type: 'toggle',
93+
no: '#buttons-waiting',
94+
yes: '#buttons-error'
95+
},
8096
activeStep: [
81-
{
82-
type: 'switch',
83-
hook: 'buttons',
84-
cases: {
85-
sampling: '#buttons-sampling',
86-
analyzing: '#buttons-analyzing'
87-
}
88-
},
97+
// {
98+
// type: 'switch',
99+
// hook: 'buttons',
100+
// cases: {
101+
// sampling: '#buttons-sampling',
102+
// analyzing: '#buttons-analyzing'
103+
// }
104+
// },
89105
{
90106
type: 'switchClass',
91107
name: 'is-active',
@@ -123,7 +139,8 @@ module.exports = View.extend({
123139
},
124140
events: {
125141
'click [data-hook=stop-analyzing-button]': 'stopAnalyzingClicked',
126-
'click [data-hook=create-new-query-button]': 'createNewQueryClicked',
142+
'click [data-hook=partial-results-button]': 'stopAnalyzingClicked',
143+
'click [data-hook=next-action-button]': 'nextActionClicked',
127144
'click [data-hook=increase-maxtimems-button]': 'resampleWithLongerTimoutClicked'
128145
},
129146
render: function() {
@@ -150,7 +167,10 @@ module.exports = View.extend({
150167
resampleWithLongerTimoutClicked: function() {
151168
this.schema.reSampleWithLongerTimeout();
152169
},
153-
createNewQueryClicked: function() {
170+
nextActionClicked: function() {
171+
if (this.schema && this.schema.count > 0) {
172+
return this.schema.stopAnalyzing();
173+
}
154174
app.statusbar.hide();
155175
},
156176
remove: function() {

0 commit comments

Comments
 (0)