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

ysql: preserve header upon history file truncation #9861

Open
jaki opened this issue Aug 28, 2021 · 5 comments
Open

ysql: preserve header upon history file truncation #9861

jaki opened this issue Aug 28, 2021 · 5 comments
Labels
area/ysql Yugabyte SQL (YSQL) good first issue This is a good issue to start contributing! help wanted We welcome your contributions for this issue! kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@jaki
Copy link
Contributor

jaki commented Aug 28, 2021

Jira Link: DB-2106
ysqlsh history file can be specified by --variable=HISTFILE=/path/to/file. It seems that the default amount of entries (or lines) it keeps is 500. Once it goes past that, upon history file write, it truncates the file. However, it also truncates the header line _HiStOrY_V2_. This makes the file invalid next time it's read. This is possibly related to YB using libedit rather than libreadline (commit d372e88). I have not tested upstream postgres, but it should be tested with and without --with-libedit-preferred.

Repro:

First, copy 500 dull commands to the clipboard.

for _ in {1..500}; do echo ";"; done | myclipboardcommand

Then, start ysqlsh and paste the contents. End the session with control D.

./bin/ysqlsh --variable=HISTFILE=test_history.sql

I specifically make the commands very short because it makes it more reliable. In my testing, long commands may somehow mush up with adjacent ones.

Check the history file for 500 entries and the header:

wc test_history.sql
 501  501 1013 test_history.sql
head -2 test_history.sql
_HiStOrY_V2_
;

Now, add one more entry to the history by running any one command in ysqlsh (with the same HISTFILE variable). Upon closing the session, the history file is truncated. This can be noticed by tail -F test_history.sql while closing the ysqlsh session.

tail: test_history.sql: file truncated

Notice that the header is gone

head -2 test_history.sql
;
;

Try ysqlsh again, and the up arrow or ctrl R will not bring up the history. Interestingly, the current session's history will still be written.

select 1;
tail -2 test_history.sql
;
select\0401;
@jaki jaki added kind/bug This issue is a bug help wanted We welcome your contributions for this issue! good first issue This is a good issue to start contributing! area/ysql Yugabyte SQL (YSQL) labels Aug 28, 2021
@Akshat1331
Copy link

Hi @jaki can contribute to this issue it is my first contribution so can you help me a little bit?

@jaki
Copy link
Contributor Author

jaki commented Sep 2, 2021

My suggestion is to first try to reproduce this on upstream PostgreSQL. As I mention, it should be tested with and without --with-libedit-preferred. We use PostgreSQL 11.2 with some imported patches, so you can test PostgreSQL 11.2.

If upstream PostgreSQL does not have the same issue, we can move forward with trying to fix it here.

@Akshat1331
Copy link

Akshat1331 commented Sep 3, 2021 via email

@PriyanshX1902
Copy link

@jaki is this still open? Care if i take it?

@jaki
Copy link
Contributor Author

jaki commented Sep 8, 2021

@PriyanshX1902, yes, it is still open. Anyone is free to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) good first issue This is a good issue to start contributing! help wanted We welcome your contributions for this issue! kind/bug This issue is a bug priority/medium Medium priority issue
Projects
Status: No status
Development

No branches or pull requests

4 participants