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

colflow: fix emitting of flow stats and simplify the creator a bit #62222

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Mar 19, 2021

We introduced isGatewayNode boolean on the flow creator a couple of
months ago which is used to decide whether the last outbox should emit
the flow level memory and disk stats. However, we forget to properly
initialize it in the constructor, and this commit fixes that issue. The
impact though is very limited - we would just emit some redundant stats,
and because they are used for maximum, they would get ignored.

Additionally, this commit simplifies the flow creator by removing
materializerAdded field because it is essentially a duplicate of
isGatewayNode.

Release note: None

@yuzefovich yuzefovich added the backport-21.1.x 21.1 is EOL label Mar 19, 2021
@yuzefovich yuzefovich requested review from asubiotto and a team March 19, 2021 01:23
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich yuzefovich force-pushed the fix-is-gateway branch 2 times, most recently from 46eaa78 to e8c9d7f Compare March 19, 2021 01:43
@yuzefovich yuzefovich changed the title colflow: fix emitting of flow stats colflow: fix emitting of flow stats and simplify the creator a bit Mar 19, 2021
@yuzefovich yuzefovich removed the backport-21.1.x 21.1 is EOL label Mar 19, 2021
Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/colflow/vectorized_flow.go, line 461 at r1 (raw file):

	// node. This field doesn't have to be accessed atomically because all
	// writes to it happen before the outboxes' goroutines are started.
	numOutboxes int32

I think it still needs to be accessed atomically because they are different goroutines. Using an atomic value will ensure we flush the CPU cache which will make the updated value available to any following goroutines running on other cores.

We introduced `isGatewayNode` boolean on the flow creator a couple of
months ago which is used to decide whether the last outbox should emit
the flow level memory and disk stats. However, we forget to properly
initialize it in the constructor, and this commit fixes that issue. The
impact though is very limited - we would just emit some redundant stats,
and because they are used for maximum, they would get ignored.

Additionally, this commit simplifies the flow creator by removing
`materializerAdded` field because it is essentially a duplicate of
`isGatewayNode`.

Release note: None
Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto)


pkg/sql/colflow/vectorized_flow.go, line 461 at r1 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

I think it still needs to be accessed atomically because they are different goroutines. Using an atomic value will ensure we flush the CPU cache which will make the updated value available to any following goroutines running on other cores.

Ok, reverted. I tried searching for documentation of this scenario and didn't find any, do you have some links maybe?

@RaduBerinde
Copy link
Member


pkg/sql/colflow/vectorized_flow.go, line 461 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

Ok, reverted. I tried searching for documentation of this scenario and didn't find any, do you have some links maybe?

https://golang.org/ref/mem
http://www.cs.cmu.edu/~410-f10/doc/Intel_Reordering_318147.pdf

In general, you must either use locks (or other synchronization primitives) or atomic stuff. Note that atomic.Store is not a simple store, it uses XCHG which is a "locked" instruction (which flushes the store buffer and ensures a total ordering among all cores w.r.t other locked instructions). (code in $GOPATH/src/runtime/internal/atomic/asm_amd64.s).

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/colflow/vectorized_flow.go, line 461 at r1 (raw file):

Previously, RaduBerinde wrote…

https://golang.org/ref/mem
http://www.cs.cmu.edu/~410-f10/doc/Intel_Reordering_318147.pdf

In general, you must either use locks (or other synchronization primitives) or atomic stuff. Note that atomic.Store is not a simple store, it uses XCHG which is a "locked" instruction (which flushes the store buffer and ensures a total ordering among all cores w.r.t other locked instructions). (code in $GOPATH/src/runtime/internal/atomic/asm_amd64.s).

Interesting, thanks for the links. My reading is that whenever in doubt, just use the sync things and don't try to be smart :)

@craig
Copy link
Contributor

craig bot commented Mar 23, 2021

Build succeeded:

@craig craig bot merged commit 7b4bdfb into cockroachdb:master Mar 23, 2021
@yuzefovich yuzefovich deleted the fix-is-gateway branch March 23, 2021 16:22
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

4 participants