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

[auto_discovery] process templates larger than the page buffer size #145

Merged
merged 5 commits into from
Jul 11, 2017

Conversation

truthbk
Copy link
Member

@truthbk truthbk commented Jul 10, 2017

We must be able to process templates as large as necessary - customer encountered we were just processing 64K configurations at most when reading from the pipe - consistent with the default page buffer on linux. Let's read the entire buffer... Also, this is necessary to avoid blocking the writing side indefinitely.

@truthbk truthbk added this to the Next milestone Jul 10, 2017
if(adPipe != null) {
int offset = 0;
byte[] buffer = new byte[0];
while (adPipe.available() > 0) {
Copy link

@theduderog theduderog Jul 10, 2017

Choose a reason for hiding this comment

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

Is there a possible race condition here where adPipe.available() might return 0 after the read but before the writer is unblocked? Would it be safer to introduce a separator to look for?

Copy link
Member

Choose a reason for hiding this comment

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

hmm good point, what do you think @truthbk?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd have to look at the internals, I'm not sure. I haven't encountered issues while testing, but this is a valid point.

Copy link
Member

@olivielpeau olivielpeau left a comment

Choose a reason for hiding this comment

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

LGTM! Feel free to merge once you've removed the unused variable ;)

byte[] buffer = new byte[len];
adPipe.read(buffer);
if(adPipe != null) {
int offset = 0;
Copy link
Member

Choose a reason for hiding this comment

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

you can remove this var

@truthbk
Copy link
Member Author

truthbk commented Jul 11, 2017

After taking a look at the internals, I believe @theduderog was indeed correct and we will need to use a separator to guarantee we know when no more data is expected in the iteration. Will have to fix that here, and in the dd-agent side.

O_NONBLOCK disabled, n > PIPE_BUF
The write is nonatomic: the data given to write(2) may be interleaved with write(2)s by other process; the write(2) blocks until n bytes have been written.
O_NONBLOCK enabled, n > PIPE_BUF
If the pipe is full, then write(2) fails, with errno set to EAGAIN. Otherwise, from 1 to n bytes may be written (i.e., a "partial write" may occur; the caller should check the return value from write(2) to see how many bytes were actually written), and these bytes may be interleaved with writes by other processes.

We have a single writer, so it'd be less problematic, that said, better safe than sorry - adding a separator/terminator.

@truthbk truthbk modified the milestones: 0.15.0, Next Jul 11, 2017
@truthbk truthbk merged commit 645af8a into master Jul 11, 2017
@truthbk truthbk deleted the jaime/largecfg branch July 11, 2017 15:33
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.

4 participants