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

sql: assert no dependencies on storage or CGo #31325

Merged
merged 1 commit into from Oct 15, 2018

Conversation

Projects
None yet
6 participants
@jordanlewis
Member

jordanlewis commented Oct 12, 2018

No longer necessary for sql to depend on either storage or CGo - let's keep it that way!

All commits but last one from dependent PRs.

Closes #30001.

@jordanlewis jordanlewis requested a review from dt Oct 12, 2018

@jordanlewis jordanlewis requested review from cockroachdb/cli-prs as code owners Oct 12, 2018

@cockroach-teamcity

This comment has been minimized.

Show comment
Hide comment
@cockroach-teamcity

cockroach-teamcity Oct 12, 2018

Member

This change is Reviewable

Member

cockroach-teamcity commented Oct 12, 2018

This change is Reviewable

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 15, 2018

Member

Yay, this can merge now.

Member

jordanlewis commented Oct 15, 2018

Yay, this can merge now.

@dt

dt approved these changes Oct 15, 2018

🎉

@jordanlewis

This comment has been minimized.

Show comment
Hide comment
@jordanlewis

jordanlewis Oct 15, 2018

Member

bors r+

Member

jordanlewis commented Oct 15, 2018

bors r+

craig bot pushed a commit that referenced this pull request Oct 15, 2018

Merge #31325 #31337 #31362
31325: sql: assert no dependencies on storage or CGo r=jordanlewis a=jordanlewis

No longer necessary for sql to depend on either storage or CGo - let's keep it that way!

All commits but last one from dependent PRs.

Closes #30001.

31337: distsqlrun: fix tablereader microbenchmark r=jordanlewis a=jordanlewis

It wasn't doing any work besides the initial fetch by accident. Oops!
Numbers look much more realistic now.

```
name                      old time/op    new time/op    delta
TableReader/rows=16-8       68.1µs ± 2%    77.7µs ± 1%    +14.20%
(p=0.000 n=10+10)
TableReader/rows=256-8       139µs ± 3%     243µs ±11%    +75.45%
(p=0.000 n=10+10)
TableReader/rows=4096-8      745µs ± 1%    2172µs ± 1%   +191.62%
(p=0.000 n=10+9)
TableReader/rows=65536-8    9.94ms ± 2%   33.45ms ± 1%   +236.60%
(p=0.000 n=10+10)

name                      old speed      new speed      delta
TableReader/rows=16-8     3.76MB/s ± 2%  3.29MB/s ± 1%    -12.44%
(p=0.000 n=10+10)
TableReader/rows=256-8    29.5MB/s ± 3%  16.9MB/s ±10%    -42.89%
(p=0.000 n=10+10)
TableReader/rows=4096-8   88.0MB/s ± 1%  30.2MB/s ± 1%    -65.71%
(p=0.000 n=10+9)
TableReader/rows=65536-8   106MB/s ± 2%    31MB/s ± 1%    -70.29%
(p=0.000 n=10+10)

name                      old alloc/op   new alloc/op   delta
TableReader/rows=16-8       9.60kB ± 2%   10.06kB ± 2%     +4.78%
(p=0.000 n=10+10)
TableReader/rows=256-8      9.50kB ± 1%   17.93kB ± 2%    +88.67%
(p=0.000 n=9+9)
TableReader/rows=4096-8     9.58kB ± 2%  142.82kB ± 3%  +1390.41%
(p=0.000 n=8+10)
TableReader/rows=65536-8    20.8kB ±93%  2090.0kB ± 1%  +9924.14%
(p=0.000 n=10+9)

name                      old allocs/op  new allocs/op  delta
TableReader/rows=16-8         78.6 ± 1%      79.7 ± 1%     +1.40%
(p=0.001 n=10+10)
TableReader/rows=256-8        79.0 ± 0%      80.0 ± 0%     +1.27%
(p=0.000 n=9+8)
TableReader/rows=4096-8       79.0 ± 0%      83.7 ±12%     +5.95%
(p=0.000 n=8+10)
TableReader/rows=65536-8       100 ±45%       453 ± 3%   +354.81%
(p=0.000 n=10+9)
```

Release note: None

31362: ui: Have the range debug page correctly handle missing lease times r=BramGruneir a=BramGruneir

Before this change, the value was always assumed to be not-null and it was null
would crash. It will now correctly handled the missing value and display a
`no timestamp` warning.

Fixes #31260.

Release note (bug fix): The range debug page will now correctly handle cases in
which there is no lease start or expiration time.

![screen shot 2018-10-15 at 10 35 07](https://user-images.githubusercontent.com/1614265/46958094-08a46300-d067-11e8-92cb-182882f8dd19.png)


Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
Co-authored-by: Bram Gruneir <bram@cockroachlabs.com>
@craig

This comment has been minimized.

Show comment
Hide comment
@craig

craig bot commented Oct 15, 2018

Build succeeded

@craig craig bot merged commit d089a23 into cockroachdb:master Oct 15, 2018

3 checks passed

GitHub CI (Cockroach) TeamCity build finished
Details
bors Build succeeded
Details
license/cla Contributor License Agreement is signed.
Details
@benesch

This comment has been minimized.

Show comment
Hide comment
@benesch

benesch Oct 15, 2018

Member

omg 😍

Member

benesch commented Oct 15, 2018

omg 😍

@lopezator

This comment has been minimized.

Show comment
Hide comment
@lopezator

lopezator Oct 16, 2018

Related to #30001 tried to use this commit inside:

https://github.com/lopezator/sqlfmt

To avoid C dependencies, and doesn't seem to work at all still. I am receiving some errors on util library:

vendor/github.com/cockroachdb/cockroach/pkg/util/log/clog.go:1115:40: undefined: build.GetInfo vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:116:7: undefined: build.IsRelease vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:230:5: undefined: build.SeemsOfficial vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:245:10: undefined: build.GetInfo vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:493:6: undefined: build.IsRelease

However it works using CGO, so it looks it already has some kind of C dependency. Only because util library maybe?

lopezator commented Oct 16, 2018

Related to #30001 tried to use this commit inside:

https://github.com/lopezator/sqlfmt

To avoid C dependencies, and doesn't seem to work at all still. I am receiving some errors on util library:

vendor/github.com/cockroachdb/cockroach/pkg/util/log/clog.go:1115:40: undefined: build.GetInfo vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:116:7: undefined: build.IsRelease vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:230:5: undefined: build.SeemsOfficial vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:245:10: undefined: build.GetInfo vendor/github.com/cockroachdb/cockroach/pkg/util/log/crash_reporting.go:493:6: undefined: build.IsRelease

However it works using CGO, so it looks it already has some kind of C dependency. Only because util library maybe?

@dt

This comment has been minimized.

Show comment
Hide comment
@dt

dt Oct 16, 2018

Member

@lopezator This change broke the dependency from sql to storage and thus any transitive edge to our C++ dependencies that use a make-driven build process, like rocksdb, and banned them from coming back into the dependencies of sql, but that doesn't include plain old (go-built) cgo.

I think @mjibson has been looking at making the parser package cgo-free but it hasn't proved straightforward: anything that pulls in stdlib's tls, like our base config package or the lib/pq library that our errors package uses pick up a cgo dep via the stdlib's crypto/x509. Also, anything that pulls in our build info package, including our log package, will see cgo as well, since there's a little inline C in there to identify which cgo compiler is in use.

We might be able to eliminate that build C import at this point -- now that we're committed to make driven builds, we can likely just have make inject the c++ compiler used instead of compiling a little inline program to figure it out (cc @benesch?).

However we still have cgo deps via various stdlib packages, namely via tls and crypto/x509 and via net. We can cut the tls edge, both from the pgerror to lib/pq path, since the pgerror helper is only used in tests, and then we could move the base.DocsURL helper, but eventually we'll hit stdlib net and whatever other paths I haven't seen. I'm not sure we can practically avoid any stdlib packages in all our transitive deps, so if they use cgo, we might be out of luck? I dunno, @mjibson has been looking at this longer than I have so maybe he has further insight.

Member

dt commented Oct 16, 2018

@lopezator This change broke the dependency from sql to storage and thus any transitive edge to our C++ dependencies that use a make-driven build process, like rocksdb, and banned them from coming back into the dependencies of sql, but that doesn't include plain old (go-built) cgo.

I think @mjibson has been looking at making the parser package cgo-free but it hasn't proved straightforward: anything that pulls in stdlib's tls, like our base config package or the lib/pq library that our errors package uses pick up a cgo dep via the stdlib's crypto/x509. Also, anything that pulls in our build info package, including our log package, will see cgo as well, since there's a little inline C in there to identify which cgo compiler is in use.

We might be able to eliminate that build C import at this point -- now that we're committed to make driven builds, we can likely just have make inject the c++ compiler used instead of compiling a little inline program to figure it out (cc @benesch?).

However we still have cgo deps via various stdlib packages, namely via tls and crypto/x509 and via net. We can cut the tls edge, both from the pgerror to lib/pq path, since the pgerror helper is only used in tests, and then we could move the base.DocsURL helper, but eventually we'll hit stdlib net and whatever other paths I haven't seen. I'm not sure we can practically avoid any stdlib packages in all our transitive deps, so if they use cgo, we might be out of luck? I dunno, @mjibson has been looking at this longer than I have so maybe he has further insight.

@benesch

This comment has been minimized.

Show comment
Hide comment
@benesch

benesch Oct 16, 2018

Member

We might be able to eliminate that build C import at this point -- now that we're committed to make driven builds, we can likely just have make inject the c++ compiler used instead of compiling a little inline program to figure it out (cc @benesch?).

Definitely an option, but I'm not sure it buys us much. These packages whose dependency sets we're minimizing shouldn't be depending on build anyway. My laptop is currently out of commission while it upgrades to Mojave, but once I get it back I'll do some digging on where the edge to build is coming from.

It's ok to use the net package. Go has some crazy shenanigans where it will bundle its own DNS resolver that doesn't require cgo if you compile net with CGO_ENABLED=0.

tl;dr I think making it so that these library packages can be compiled without cgo is totally within reach.

Member

benesch commented Oct 16, 2018

We might be able to eliminate that build C import at this point -- now that we're committed to make driven builds, we can likely just have make inject the c++ compiler used instead of compiling a little inline program to figure it out (cc @benesch?).

Definitely an option, but I'm not sure it buys us much. These packages whose dependency sets we're minimizing shouldn't be depending on build anyway. My laptop is currently out of commission while it upgrades to Mojave, but once I get it back I'll do some digging on where the edge to build is coming from.

It's ok to use the net package. Go has some crazy shenanigans where it will bundle its own DNS resolver that doesn't require cgo if you compile net with CGO_ENABLED=0.

tl;dr I think making it so that these library packages can be compiled without cgo is totally within reach.

@dt

This comment has been minimized.

Show comment
Hide comment
@dt

dt Oct 16, 2018

Member

the edge to build is pervasive: the most direct edge here is via the base package but everything gets to logging eventually and logging get to build to determine if it is a release/dev build. I guess we could buildtag out the inline cgo in build ourselves for non-cgo builds?

Member

dt commented Oct 16, 2018

the edge to build is pervasive: the most direct edge here is via the base package but everything gets to logging eventually and logging get to build to determine if it is a release/dev build. I guess we could buildtag out the inline cgo in build ourselves for non-cgo builds?

@lopezator

This comment has been minimized.

Show comment
Hide comment
@lopezator

lopezator Oct 16, 2018

stdlib (CGO or not, as @benesch said shouldn't be a problem, I think).

The offending parts I detected for my particular usecase of sql package to use in:

https://github.com/lopezator/sqlfmt

Are:

https://github.com/cockroachdb/cockroach/blob/master/pkg/util/tracing/annotate.go#L17-L19

And the one mentioned by @dt :

https://github.com/cockroachdb/cockroach/blob/master/pkg/build/info.go#L26-L35

Removing them, makes my sqlfmt free of any CGO, and thus, capable of building using standard go and without needing any C paraphernalia, i.e:

GOOS=windows GOARCH=amd64 go build cmd/sqlfmt/main.go
GOOS=darwin GOARCH=amd64 go build cmd/sqlfmt/main.go

etc

lopezator commented Oct 16, 2018

stdlib (CGO or not, as @benesch said shouldn't be a problem, I think).

The offending parts I detected for my particular usecase of sql package to use in:

https://github.com/lopezator/sqlfmt

Are:

https://github.com/cockroachdb/cockroach/blob/master/pkg/util/tracing/annotate.go#L17-L19

And the one mentioned by @dt :

https://github.com/cockroachdb/cockroach/blob/master/pkg/build/info.go#L26-L35

Removing them, makes my sqlfmt free of any CGO, and thus, capable of building using standard go and without needing any C paraphernalia, i.e:

GOOS=windows GOARCH=amd64 go build cmd/sqlfmt/main.go
GOOS=darwin GOARCH=amd64 go build cmd/sqlfmt/main.go

etc

@jordanlewis jordanlewis deleted the jordanlewis:no-cgo branch Oct 16, 2018

@mjibson

This comment has been minimized.

Show comment
Hide comment
@mjibson

mjibson Oct 16, 2018

Member

@benesch the build package is annoyingly common. Over 100 packages have transitive dependencies on it including almost everything in sql, storage, util, server. It's because of two reasons: the log package uses it on crashes and a few things in SQL use it to get the docs URL of the current version. I tried mjibson@d1a209d at one point which causes build to poke into other packages to remove the dependency on it, but I'm not convinced it's a good idea, or maybe there's a better way.

Member

mjibson commented Oct 16, 2018

@benesch the build package is annoyingly common. Over 100 packages have transitive dependencies on it including almost everything in sql, storage, util, server. It's because of two reasons: the log package uses it on crashes and a few things in SQL use it to get the docs URL of the current version. I tried mjibson@d1a209d at one point which causes build to poke into other packages to remove the dependency on it, but I'm not convinced it's a good idea, or maybe there's a better way.

@dt

This comment has been minimized.

Show comment
Hide comment
@dt
Member

dt commented Oct 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment