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

common/Formatter: avoid newline if there is no output #5351

Merged
merged 1 commit into from Jan 6, 2016

Conversation

Aran85
Copy link
Contributor

@Aran85 Aran85 commented Jul 27, 2015

When executed the gateway command : radosgw-admin mdlog list ,these are some useless blank lines (default is 64 lines) in the output message.this is marked when no meta log in the gateway.

Signed-off-by: Aran85 zhangzengran@h3c.com

@theanalyst theanalyst added the rgw label Jul 27, 2015
@theanalyst
Copy link
Member

Need to add a signed-off-by line to the commit message as outlined in https://github.com/ceph/ceph/blob/master/SubmittingPatches

@yehudasa
Copy link
Member

@Aran85 I understand that there's an issue. I just think that it seems to me that the issue needs to be fixed in the formatter. I don't think that avoiding a call to flush is the way to go as we'll eventually hit this issue again.

@Aran85
Copy link
Contributor Author

Aran85 commented Jul 29, 2015

dear @yehudasa
i think you are right.i add a condition check when flush.the format is more pretty now :)

@Aran85
Copy link
Contributor Author

Aran85 commented Jul 30, 2015

dear @yehudasa
as you said,i think there is no need for flush to output "\n" .but when close section,we need to output the final "\n" when all closeed.i have checked many command's output.hope Ceph & formatter be more pretty!

@Aran85
Copy link
Contributor Author

Aran85 commented Aug 3, 2015

dear @yehudasa
need you to review.

@yehudasa
Copy link
Member

yehudasa commented Aug 5, 2015

@Aran85 you should probably also squash the commits together

@Aran85
Copy link
Contributor Author

Aran85 commented Aug 6, 2015

dear @yehudasa
just see the TEST modify which i commited,if no eol when m_stack empty,the "[]" will be connect with the next shell PS1.

Signed-off-by: Aran85 zhangzengran@h3c.com
@Aran85
Copy link
Contributor Author

Aran85 commented Aug 11, 2015

dear @yehudasa
the eol when section close is just as before,only the useless eol in sections removed .plz check.

@yehudasa
Copy link
Member

@Aran85 I see why it fixes the original issue, but it seems to me that we break other things in the process. From what I understand is that we now switched to appending eol just in the case where the stack is empty, which means that it will only happen to the top level (or am I misreading?). Also, having to update a test to get this change passing doesn't seem quite right.

@Aran85
Copy link
Contributor Author

Aran85 commented Aug 21, 2015

dear @yehudasa
I think we have three problems here right now.
1.about the eol dumping in json flush method
like the c++ std::flush,the eol in flush is not not necessary.
eol is controlled by print_comma and close section,and it works well.
if somewhere readlly need to split two lines by eol,we could add a endl method also like std::endl.
removing the eol in flush will compact the json format,and i had test it.
2.about the eol appending when stack empty.
i think you are misreaded.the appending eol where the stack is empty means that it will only happen when a sigle whole json had dumped,the next is a new command input line.
3.about the test modify
I had check crush dump_rules usage in OSDMonitor.cc (line.3335) and in crush/CrushWrapper.cc (line.1404),dump_rules is always between open_section and close_section,so the test should use it like which in the process.

@Aran85
Copy link
Contributor Author

Aran85 commented Aug 21, 2015

dear @yehudasa
example:

1.  {
2.      "data": {                  
3.          "user_id": "aaa",
4.          "display_name": "aaa"
5.      }
6.  } 
7.                              

we could see that the eols at line1 to line5 are common condition.they are dumped by the next line.There are only tow methods which are print_name() and close_section() in the common condithon.
the eol at line 1 is dumped by print_comma which is called by print_name("data",...)
the eol at line 2 is dumped by print_comma which is called by print_name("user_id") .
the eol at line 3 is dumped by print_comma which is called by print_name("display_name")
the eol at line 4 is dumped by close_section (section opened at line 2)
the eol at line 5 is dumped by close_section (section opened at line 1)

the eol at line 6 is dumped by final flush

So most of the time the eols in json are not dumped by flush.only the eol at last line is dumped by flush.

The reason why i append eol in the case where the stack is empty is to replace the eol which is dumped by final flush.

@guce
Copy link

guce commented Aug 21, 2015

I think there are two options:
1.As @Aran85 's change, flush()'s function is relatively pure, i.e. flush() doesn't have to deal with eol.
2.Keep formatter unchanged. To avoid outputing extra blank lines, we should never use flush() when the buffer is empty.

@Aran85
Copy link
Contributor Author

Aran85 commented Oct 29, 2015

@yehudasa

@yehudasa yehudasa assigned liewegas and unassigned yehudasa Oct 29, 2015
@yehudasa
Copy link
Member

@Aran85 sorry for not getting into it earlier. The problem I'm having here is that I'm afraid this will break tests unintentionally, ones that go beyond the rgw use case. Maybe @liewegas can add this one to his set of tests?

@Aran85
Copy link
Contributor Author

Aran85 commented Nov 9, 2015

hello @liewegas
how about the test?

@ghost ghost added the needs-qa label Nov 25, 2015
liewegas added a commit that referenced this pull request Jan 6, 2016
common/Formatter: avoid newline if there is no output

Reviewed-by: Yehuda Sadeh <yehuda@redhat.com>
@liewegas liewegas merged commit 469d78d into ceph:master Jan 6, 2016
@ghost ghost changed the title fix radosgw-admin mdlog list blank lines common/Formatter: avoid newline if there is no output Feb 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants