Skip to content

sql+pgwire: Fix contexts in sql and pgwire.#10094

Merged
knz merged 2 commits intocockroachdb:masterfrom
knz:fix-contexts-pgwire
Oct 20, 2016
Merged

sql+pgwire: Fix contexts in sql and pgwire.#10094
knz merged 2 commits intocockroachdb:masterfrom
knz:fix-contexts-pgwire

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Oct 19, 2016

I need this for #9259 and also I wanted to get protocol errors logged with the remote address properly.


This change is Reviewable

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 19, 2016

Can you help investigate? The acceptance tests are failing with
localcluster.go:679: unexpected extra event &{0 die} (after [])

Never saw this before.

@andreimatei
Copy link
Copy Markdown
Contributor

I haven't looked at anything, but I believe that acceptance error means that a node has crashed. We have some magic listening to docker container events 8-)

@RaduBerinde
Copy link
Copy Markdown
Member

Great, thanks! LGTM modulo one typo.


Reviewed 1 of 2 files at r1, 5 of 5 files at r2.
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


pkg/server/server.go, line 471 at r2 (raw file):

  s.stopper.RunWorker(func() {
      netutil.FatalIfUnexpected(httpServer.ServeWith(s.stopper, pgL, func(conn net.Conn) {
          pgCtx := s.pgServer.AmbientCtx.AnnotateCtx(context.Background())

can init this once, before running netutil.FatalIf..


pkg/server/server.go, line 472 at r2 (raw file):

      netutil.FatalIfUnexpected(httpServer.ServeWith(s.stopper, pgL, func(conn net.Conn) {
          pgCtx := s.pgServer.AmbientCtx.AnnotateCtx(context.Background())
          pgCtx = log.WithLogTagStr(ctx, "client", conn.RemoteAddr().String())

s/ctx/pgCtx. Maybe just use ctx instead of pgCtx (assuming the linter doesn't complain).


pkg/sql/session.go, line 379 at r1 (raw file):

// This needs to be called before resetForNewSQLTransaction() is called for
// starting another SQL txn.
func (ts *txnState) finishSQLTxn(ctx context.Context) {

maybe name sessionCtx since we are also using a different context ts.Ctx in there


pkg/sql/pgwire/v3.go, line 653 at r2 (raw file):

) error {
  tracing.AnnotateTrace()
  results := c.executor.ExecuteStatements(c.session, stmts, pinfo)

We should probably pass ctx into the executor and make use of it there as well, can you add a TODO?


Comments from Reviewable

@knz knz force-pushed the fix-contexts-pgwire branch from 9936a72 to 4b4562e Compare October 19, 2016 23:48
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 19, 2016

Review status: 1 of 6 files reviewed at latest revision, 4 unresolved discussions.


pkg/server/server.go, line 471 at r2 (raw file):

Previously, RaduBerinde wrote…

can init this once, before running netutil.FatalIf..

Done.

pkg/server/server.go, line 472 at r2 (raw file):

Previously, RaduBerinde wrote…

s/ctx/pgCtx. Maybe just use ctx instead of pgCtx (assuming the linter doesn't complain).

It does complain unfortunately...

pkg/sql/session.go, line 379 at r1 (raw file):

Previously, RaduBerinde wrote…

maybe name sessionCtx since we are also using a different context ts.Ctx in there

Done.

pkg/sql/pgwire/v3.go, line 653 at r2 (raw file):

Previously, RaduBerinde wrote…

We should probably pass ctx into the executor and make use of it there as well, can you add a TODO?

I'm not sure I agree (c.session already carries the right context), but I added the explanatory comment nonetheless.

(Incidentally this made me think of filing #10096. Not directly relevant but still somewhat.)


Comments from Reviewable

@RaduBerinde
Copy link
Copy Markdown
Member

:lgtm:


Review status: 1 of 6 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


pkg/server/server.go, line 472 at r3 (raw file):

      pgCtx := s.pgServer.AmbientCtx.AnnotateCtx(context.Background())
      netutil.FatalIfUnexpected(httpServer.ServeWith(s.stopper, pgL, func(conn net.Conn) {
          connCtx = log.WithLogTagStr(pgCtx, "client", conn.RemoteAddr().String())

shouldn't this be :=? (same below)


pkg/sql/pgwire/v3.go, line 653 at r2 (raw file):

Previously, knz (kena) wrote…

I'm not sure I agree (c.session already carries the right context), but I added the explanatory comment nonetheless.

(Incidentally this made me think of filing #10096. Not directly relevant but still somewhat.)

Thanks. Yeah, it's not clear, we may want each statement to use its own context and only use the session context for a few specific things (like tracing across statements). It's mostly TBD at this point though.

Comments from Reviewable

@knz knz force-pushed the fix-contexts-pgwire branch from 4b4562e to 7d259b6 Compare October 20, 2016 05:55
@knz knz force-pushed the fix-contexts-pgwire branch from 7d259b6 to 3f29d40 Compare October 20, 2016 06:00
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 20, 2016

TFYR!

@knz knz merged commit 27e0aac into cockroachdb:master Oct 20, 2016
@knz knz deleted the fix-contexts-pgwire branch October 20, 2016 06:11
@alamaison
Copy link
Copy Markdown

I've not been able to test because I can't get cockroach to build:

# github.com/cockroachdb/cockroach/pkg/storage/engine/rocksdb
pkg/storage/engine/rocksdb/db.cc: In function 'DBStatus DBEngineAddFile(DBEngine*, DBSlice)':
pkg/storage/engine/rocksdb/db.cc:2028:59: warning: 'virtual rocksdb::Status rocksdb::DB::AddFile(const string&, bool)' is deprecated (declared at ../../../../../c-rocksdb/internal/include/rocksdb/db.h:840) [-Wdeprecated-declarations]
   rocksdb::Status status = db->rep->AddFile(ToString(path));
                                                           ^
pkg/storage/engine/rocksdb/db.cc: In constructor 'DBSstFileWriter::DBSstFileWriter(rocksdb::Options*)':
pkg/storage/engine/rocksdb/db.cc:2043:59: error: no matching function for call to 'rocksdb::SstFileWriter::SstFileWriter(rocksdb::EnvOptions, rocksdb::ImmutableCFOptions&, const rocksdb::Comparator*&)'
         rep(rocksdb::EnvOptions(), ioptions, o->comparator) {
                                                           ^
pkg/storage/engine/rocksdb/db.cc:2043:59: note: candidates are:
In file included from ../../../../../c-rocksdb/internal/include/rocksdb/db.h:24:0,
                 from pkg/storage/engine/rocksdb/db.cc:25:
../../../../../c-rocksdb/internal/include/rocksdb/sst_file_writer.h:52:3: note: rocksdb::SstFileWriter::SstFileWriter(const rocksdb::EnvOptions&, const rocksdb::Options&, const rocksdb::Comparator*)
   SstFileWriter(const EnvOptions& env_options, const Options& options,
   ^
../../../../../c-rocksdb/internal/include/rocksdb/sst_file_writer.h:52:3: note:   no known conversion for argument 2 from 'rocksdb::ImmutableCFOptions' to 'const rocksdb::Options&'
../../../../../c-rocksdb/internal/include/rocksdb/sst_file_writer.h:50:7: note: constexpr rocksdb::SstFileWriter::SstFileWriter(const rocksdb::SstFileWriter&)
 class SstFileWriter {
       ^
../../../../../c-rocksdb/internal/include/rocksdb/sst_file_writer.h:50:7: note:   candidate expects 1 argument, 3 provided
Makefile:79: recipe for target 'install' failed
make: *** [install] Error 2

Are there nightly build available anywhere?

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 20, 2016

Which platform are you building for?

@alamaison
Copy link
Copy Markdown

Ubuntu 14.04 x86_64. Used to docker container to run the build

@petermattis
Copy link
Copy Markdown
Collaborator

@alamaison RocksDB 4.9 changed some APIs we're using. We currently use RocksDB 4.8. This is all supposed to work automagically via glock and the GLOCKFILE. Make sure that the SHA you have checked out in github.com/cockroachdb/c-rocksdb matches the SHA for that repo in GLOCKFILE.

@tbg
Copy link
Copy Markdown
Member

tbg commented Oct 20, 2016

glock sync github.com/cockroachdb/cockroach

@alamaison
Copy link
Copy Markdown

Thanks. sync fixed it. Was on RocksDB 4.11 without it.

P.S. I meant to comment on #10087 but accidentally posted here instead

@RaduBerinde
Copy link
Copy Markdown
Member

pkg/server/server.go, line 470 at r4 (raw file):

  s.stopper.RunWorker(func() {
      pgCtx := s.pgServer.AmbientCtx.AnnotateCtx(context.Background())

If this is the only place we are using pgServer.AmbientCtx, why embed it there at all? We might as well j ust do s.AnnotateCtx here no?


Comments from Reviewable

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Oct 21, 2016

@RaduBerinde perhaps, but I was following the comments next to the definition of AmbientContext, which was instructing me to "plumb AmbientContext to all the servers". Perhaps we could talk about why we would want multiple ambient contexts as opposed to a single one?

@RaduBerinde
Copy link
Copy Markdown
Member

We want multiple contexts because each layer's ambient context can add tags (and other stuff) to the parent's (server has nX, store has nX,sY, replica has nX,sY,rZ).

The intention is to be embedded in servers/components that use it, in our case it's the Server code that annotates the context, so it seems a little weird that we copy and use it from the pgServer. I think that maybe the code for these workers belongs in pgServer not in Server, and that's the culprit of the weirdness. Either way, it's not a big deal, just wanted to see if I'm missing something.

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.

6 participants