Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new adapter read and write api #248

Merged
merged 42 commits into from
Jan 30, 2016
Merged

new adapter read and write api #248

merged 42 commits into from
Jan 30, 2016

Conversation

demmer
Copy link
Contributor

@demmer demmer commented Jan 22, 2016

This PR is a big rework of the implementation of read and write and the adapter API.

Instead instead of having adapters directly implement procs, add normal proc implementations of read and write along with a new set of abstract base classes for adapters that have a cleaner contract that is more isolated from the details of the rest of the runtime.

Also convert the test adapters and the file adapter to use the new API and add a new test adapter that simulates a timeseries database to test the logic for reading pseudo-live.

More details are in the individual commit messages.

Not yet ready for merge but initial review would be appreciated.

To do before merge:

  • Convert the file adapter
  • Convert the http adapter
  • Convert the stdio adapter
  • Convert the stochastic adapter
  • Rework emit so that ticks are generated by the source proc
  • Implement one of the external adapters using this contract

Fixes #168.

@demmer demmer force-pushed the adapters-are-not-procs branch 2 times, most recently from 34a3346 to fbf8b66 Compare January 22, 2016 23:31
@demmer
Copy link
Contributor Author

demmer commented Jan 22, 2016

@juttle/developers

@demmer demmer force-pushed the adapters-are-not-procs branch 2 times, most recently from f43d8ad to 7841362 Compare January 23, 2016 00:18

var format;
try {
format = contentType.parse(res).type.split('/')[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Know this was just a copy-paste but I'm confused by the logic...you take the content type of res and then use that to get a parser that you use on req? Seems like this should be contentType.parse(req).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree -- it turns out that either works, but it does seem confusing to parse the content type of the request and not the response.

I tightened things up so we don't use the req object at all any more.

@demmer demmer force-pushed the adapters-are-not-procs branch 2 times, most recently from 8542309 to 11e9769 Compare January 25, 2016 22:12
@demmer
Copy link
Contributor Author

demmer commented Jan 25, 2016

@davidvgalbraith I addressed all your comments, rebased, and then also made some additional changes. Everything from 0c7b30e onward is new.

Seems like we're close enough that it would make sense to merge this sooner rather than later and then start the process of converting the adapters. Once this merges I'd probably want to cut a new juttle release so we have something to base the adapter rework off of.

this.emit_eof();
} else {
this.reading.then(() => {
this.emit_eof();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will emit 2 EOFs if the read hits an error due to line 237. I don't think that's a big deal, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point -- that doesn't seem like a good thing.
Even worse, I noticed that if there is a pending call into the scheduler that never gets cancelled or cleaned up.

@davidvgalbraith
Copy link
Contributor

+1


toNative(points);

return points;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just return toNative(points).

@davidvgalbraith davidvgalbraith mentioned this pull request Jan 26, 2016
// Returns a promise once the adapter has completed writing all the data and
// the flowgraph can be shut down.
eof() {
throw new Error('write must be implemented');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "eof must be implemented".


eof: function() {
eof() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract says we're supposed to return a promise here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base class uses Promise.try so I didn't see any need here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well then we should change the contract. Are we synchronously done here after calling this.serializer.done() anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that seems like a good thing to do.

@demmer demmer force-pushed the adapters-are-not-procs branch 6 times, most recently from 7bcf95b to cf9a0bf Compare January 28, 2016 15:00
Mark Stemm and others added 13 commits January 29, 2016 11:55
So they are supported by any adapter.
Code coverage slipped a bit on functions due to the fact that the
new read and write implementations have shim support for the old
adapters that isn't being exercised as part of the tests. This can
bump back up once we remove the legacy adapter support.
The previous model in which adapters would convey statically whether
or not they should behave as a timed source or an untimed source
proved too limiting in practice, since it didn't lend itself well
to cases like influx or sql in which the behavior actually depends
on the other options given to the read call.

Instead, change things to give adapters more control over their
desired behavior for time options by adding two new API hooks,
defaultTimeRange() to return defaults for from and to, and
periodicLiveRead() which indicates to the read proc whether to do
the pseudo-live pattern for reading or leave it up to the adapter
to manage its own paging through time.
The previous code was stomping any location info that the adapter
put into the errors, so instead only add it if it's missing.
Add generic errors for procs to use when they encounter incompatible
option combinations.

Rework emit to use these instead of a bunch of one-off error strings.
The rework to use the base class ticking behavior conflicted with the
concurrent change to not add timestamps to the -points argument, so
reconcile these two changes.
@demmer
Copy link
Contributor Author

demmer commented Jan 29, 2016

@juttle/developers I took another pass at changing the API to better support adapters that wabt to determine their behavior relating to the time options at runtime instead of statically. I also rebased to reconcile all the latest changes to the various builtin adapters (thanks rodney) and addressed the various comments in the PR history.

I think this is ready to merge so we can get on with porting the actual adapters.

})
.catch(function(err) {
self.trigger('error', self.runtime_error('RT-INTERNAL-ERROR', {
.catch((err) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch can go after the following then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@davidvgalbraith
Copy link
Contributor

+1

@demmer
Copy link
Contributor Author

demmer commented Jan 30, 2016

Dave said "ship it red!"

demmer added a commit that referenced this pull request Jan 30, 2016
@demmer demmer merged commit e9f34a3 into master Jan 30, 2016
@demmer demmer deleted the adapters-are-not-procs branch January 30, 2016 01:05
@rlgomes
Copy link
Contributor

rlgomes commented Jan 30, 2016

I'll look at that file adapter test failure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants