sql: make scanNode embed a reference to the table descriptor, not a copy#17309
sql: make scanNode embed a reference to the table descriptor, not a copy#17309knz merged 2 commits intocockroachdb:masterfrom
Conversation
6301ad1 to
8e1906a
Compare
|
Last time I looked at this, |
|
LGTM. I don't see any place that's modifying it. Review status: 0 of 6 files reviewed at latest revision, all discussions resolved, all commit checks successful. Comments from Reviewable |
|
I'm not sure where diff --git a/pkg/sql/scan.go b/pkg/sql/scan.go
index c68fdbbce..2a88dab8b 100644
--- a/pkg/sql/scan.go
+++ b/pkg/sql/scan.go
@@ -19,8 +19,10 @@ package sql
import (
"bytes"
"fmt"
+ "reflect"
"sync"
+ "github.com/kr/pretty"
"github.com/pkg/errors"
"golang.org/x/net/context"
@@ -29,6 +31,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/util"
+ "github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
)
@@ -41,9 +44,10 @@ var scanNodePool = sync.Pool{
// A scanNode handles scanning over the key/value pairs for a table and
// reconstructing them into rows.
type scanNode struct {
- p *planner
- desc sqlbase.TableDescriptor
- index *sqlbase.IndexDescriptor
+ p *planner
+ desc sqlbase.TableDescriptor
+ descPtr *sqlbase.TableDescriptor
+ index *sqlbase.IndexDescriptor
// Set if an index was explicitly specified.
specifiedIndex *sqlbase.IndexDescriptor
@@ -129,7 +133,12 @@ func (n *scanNode) Start(runParams) error {
n.valNeededForCol, false /* returnRangeInfo */, &n.p.alloc)
}
-func (n *scanNode) Close(context.Context) {
+func (n *scanNode) Close(ctx context.Context) {
+ if n.descPtr != nil && !reflect.DeepEqual(n.desc, *n.descPtr) {
+ log.Fatalf(ctx, "scanNode.desc unexpectedly modified:\n%s",
+ pretty.Diff(n.desc, *n.descPtr))
+ }
+
*n = scanNode{}
scanNodePool.Put(n)
}
@@ -198,6 +207,7 @@ func (n *scanNode) initTable(
wantedColumns []parser.ColumnID,
) error {
n.desc = *desc
+ n.descPtr = desc
if !p.skipSelectPrivilegeChecks {
if err := p.CheckPrivilege(&n.desc, privilege.SELECT); err != nil { |
|
Very interesting.. Can you also store another copy of |
It is definitely something modifying the |
|
Create view modifies the desc in scanNode . that's what I'm working on now. If you avoid tests that run create view you should see the desc stay constant.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
|
Oh, but then this should go in after that is fixed, no? |
|
So thanks to Peter's suggestion I am going to do this in two steps. I will first amend the fix in this PR to ensure the leased descriptor is not modified in-place by CREATE VIEW (and check with Peter's patch this indeed is sufficient). Then in my separate PR #17310 I will ensure this is obsolete. |
|
All right, PTAL. The first commit includes both my original change and the assertion; the code is extended to ensure CREATE VIEW does not trip the assertion. The second commit removes the assertion. You can check the 1st commit separately to see that all tests pass. |
|
Review status: 0 of 6 files reviewed at latest revision, all discussions resolved, some commit checks pending. Comments from Reviewable |
|
Reviewed 6 of 6 files at r1. pkg/sql/scan.go, line 137 at r1 (raw file):
Are the Comments from Reviewable |
|
Yes they hiding tests that hand scanNode with mostly-null descriptors (hand-crafted). |
This patch both makes scanNode use its descriptors mainly by reference, and keep a copy of the descriptor to check it hasn't been changed when the scanNode is teared down. The CREATE VIEW logic is modified to ensure the descriptors it collects from scanNodes are not modified in-place.
|
All right for the sake of double-checking I removed the comparison to zero in the assertion and fixed the tests that were tripping it. |
Prior to this patch scanNode was hosting a copy of the table descriptor.
This is not necessary since the scanNode is not modifying it.