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

live loading from stdin #3266

Merged
merged 3 commits into from
Apr 9, 2019
Merged

live loading from stdin #3266

merged 3 commits into from
Apr 9, 2019

Conversation

gitlw
Copy link

@gitlw gitlw commented Apr 8, 2019

Adding the support of live loader reading from standard input
Refactored the code around chunk processing, mainly because the checking of
if err == io.EOF
is supposed to be checking the err returned by the ck.Chunk function, however in the current code, the err variable can be overwriten by the ck.Parse function.


This change is Reviewable

@gitlw gitlw requested a review from codexnull April 8, 2019 21:59
Copy link
Contributor

@codexnull codexnull left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @gitlw)


chunker/chunk.go, line 283 at r1 (raw file):

	var err error
	if file == "-" {
		f = os.Stdin

Data can already be loaded from standard input by using /dev/stdin as the filename, but is useful on systems that may not have that device (Windows).


dgraph/cmd/live/run.go, line 226 at r1 (raw file):

// to the loader.reqs channel
func (l *loader) processChunk(chunkBuf *bytes.Buffer, ck chunker.Chunker) {
	if chunkBuf != nil && chunkBuf.Len() > 0 {

Is the entire function body wrapped by this if statement? I the code would be clearer written like:

if chunBuf == nil || chunkBuf.Len() == 0 {
    return
}

<function body>

Copy link
Author

@gitlw gitlw 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: 2 of 3 files reviewed, 2 unresolved discussions (waiting on @codexnull)


chunker/chunk.go, line 283 at r1 (raw file):

Previously, codexnull (Javier Alvarado) wrote…

Data can already be loaded from standard input by using /dev/stdin as the filename, but is useful on systems that may not have that device (Windows).

Done.


dgraph/cmd/live/run.go, line 226 at r1 (raw file):

Previously, codexnull (Javier Alvarado) wrote…

Is the entire function body wrapped by this if statement? I the code would be clearer written like:

if chunBuf == nil || chunkBuf.Len() == 0 {
    return
}

<function body>

Done.

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

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

:lgtm: Got a comment. See if it would be worth doing. Will leave it to @codexnull for the final approval.

Reviewed 2 of 3 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @codexnull)


chunker/chunk.go, line 283 at r1 (raw file):

Previously, gitlw (Lucas Wang) wrote…

Done.

A file named dash can cause confusion for command line args. Why not just have a boolean arg in live loader to accept input from stdin?

Copy link
Contributor

@codexnull codexnull 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: all files reviewed, 2 unresolved discussions (waiting on @codexnull and @manishrjain)


chunker/chunk.go, line 283 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

A file named dash can cause confusion for command line args. Why not just have a boolean arg in live loader to accept input from stdin?

A file named dash to represent stdin/stdout is a Unix/Linux convention. (For example, I used this earlier today: curl -SsL 'https://github.com/dgraph-io/dgraph/releases/download/v1.0.13/dgraph-linux-amd64.tar.gz' | tar zxf -)

I don't think it's worth adding another flag for that, especially since you can already use /dev/stdin as the file if you don't want to use a dash.

@gitlw gitlw merged commit 3aa2408 into master Apr 9, 2019
@gitlw gitlw deleted the gitlw/live_loader_from_stdin branch April 9, 2019 23:21
mangalaman93 pushed a commit that referenced this pull request Apr 10, 2019
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants