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

cli: Support nodelocal file upload in CLI #42966

Merged
merged 1 commit into from
Dec 17, 2019
Merged

Conversation

g3orgia
Copy link
Contributor

@g3orgia g3orgia commented Dec 4, 2019

This change uses the changes made in #42748, which enabled
COPY to upload files. We are now implementing the CLI to include
a new command: nodelocal upload. This command takes in a
source file to upload, and a destination filename. It will
then use the COPY command to upload the file and drop it
on the gateway node's local file system, at:

externalIODir/destination/filename

This PR also includes the CLI testing for this feature as
well as a bug fix for the previous PR #42748:

  • If writing the file fails, we do not delete the file
    that was created. This PR fixes that.

Release note (cli change): Adds a nodelocal command
that can be used to upload file:
cockroach nodelocal upload location/of/file destination/of/file

@g3orgia g3orgia requested review from dt and maddyblue December 4, 2019 22:22
@g3orgia g3orgia requested a review from a team as a code owner December 4, 2019 22:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@g3orgia
Copy link
Contributor Author

g3orgia commented Dec 4, 2019

There's two things that still need to be changed in this PR:

  • Verify the version (which is commented out right now). I'm unsure which version I should be verifying. This needs to be changed before this PR gets merged.
  • Return the nodelocal URI of the file that was written. Is there a way of figuring out the gateway node's nodeID from the CLI? If not, I may need to make a separate PR to pass that information through.

pkg/sql/copy_file_upload_test.go Show resolved Hide resolved
@@ -112,6 +118,7 @@ func (f *fileUploadMachine) run(ctx context.Context) error {
err := f.c.run(ctx)
_ = f.writeToFile.Close()
if err != nil {
f.failureCleanup()
Copy link
Contributor

Choose a reason for hiding this comment

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

What about if f.writeError has an error? Can/should the API be changed so there's only 1 possible error produced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will think about restructuring this. However, since this is on two sides of an io.Pipe, we still need to capture either side's failures.

pkg/sql/conn_executor.go Outdated Show resolved Hide resolved
pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
if err != nil {
return err
}
_, err = stmt.Exec([]driver.Value{string(send[:n])})
Copy link
Contributor

Choose a reason for hiding this comment

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

can you just exec without casting to a string? that'd save a memory copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I exec as just bytes, it prints the string representation of the bytes to stdin, which gets received that way on the other side. I'm unsure how to receive that on the other side, and convert them back to strings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried stmt.Exec(send[:n])? I thought that's how lib/pq's Copy was supposed to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm doesn't seem like it. I'll look into how we can structure this better, make use of some of the better suited APIs.

pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
pkg/cli/nodelocal.go Show resolved Hide resolved
pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
@g3orgia
Copy link
Contributor Author

g3orgia commented Dec 16, 2019

Two changes:

  • Outputs nodelocal URL of uploaded file
  • Error handling using io.Pipe instead of creating our own channel

pkg/sql/copy_file_upload.go Outdated Show resolved Hide resolved
pkg/sql/copy_file_upload.go Outdated Show resolved Hide resolved
pkg/cli/nodelocal.go Outdated Show resolved Hide resolved
This change uses the changes made in cockroachdb#42748, which enabled
COPY to upload files. We are now implementing the CLI to include
a new command: `nodelocal upload`. This command takes in a
source file to upload, and a destination filename. It will
then use the COPY command to upload the file and drop it
on the gateway node's local file system, at:

`externalIODir/destination/filename`

This PR also includes the CLI testing for this feature as
well as a bug fix for the previous PR cockroachdb#42748:
- If writing the file fails, we do not delete the file
 that was created. This PR fixes that.

Release note (cli change): Adds a nodelocal command
that can be used to upload file:
`cockroach nodelocal upload location/of/file destination/of/file`
@g3orgia
Copy link
Contributor Author

g3orgia commented Dec 17, 2019

bors r+

craig bot pushed a commit that referenced this pull request Dec 17, 2019
42966: cli: Support nodelocal file upload in CLI r=g3orgia a=g3orgia

This change uses the changes made in #42748, which enabled
COPY to upload files. We are now implementing the CLI to include
a new command: `nodelocal upload`. This command takes in a
source file to upload, and a destination filename. It will
then use the COPY command to upload the file and drop it
on the gateway node's local file system, at:

`externalIODir/destination/filename`

This PR also includes the CLI testing for this feature as
well as a bug fix for the previous PR #42748:
- If writing the file fails, we do not delete the file
 that was created. This PR fixes that.

Release note (cli change): Adds a nodelocal command
that can be used to upload file:
`cockroach nodelocal upload location/of/file destination/of/file`

42973: sql/mutations: stats histograms r=mjibson a=mjibson



43203: sqlmigrations: copy entries into new system.namespace in 20.1 r=arulajmani a=arulajmani

In 20.1, CRDB started using a new system.namespace table that had an
additional primary key column, `ParentSchemaID`. Previously, all
namespace entries created before 20.1 could only be accessed through
the old table. This patch migrates them over to the new
`system.namespace` table.

In the migration:
- All databases (`parentID` = 0) are migrated over as is, with the
`parentSchemaID` set to 0.
- For every database, we add an entry for the `public` schema, which
has the ID 29.
- All tables (`parentID` != 0) are migrated over as is, with the
`parentSchemaID` set to 29.

Release note: none

Co-authored-by: Georgia Hong <georgiah@cockroachlabs.com>
Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
Co-authored-by: Arul Ajmani <arulajmani@gmail.com>
@craig
Copy link
Contributor

craig bot commented Dec 17, 2019

Build succeeded

@craig craig bot merged commit 488661c into cockroachdb:master Dec 17, 2019
@g3orgia g3orgia deleted the cli-upload branch December 17, 2019 18:53
@knz knz added this to To do in DB Server & Security via automation Mar 7, 2020
@knz knz moved this from To do to Done 20.1 in DB Server & Security Mar 7, 2020
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

3 participants