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

log file truncation #3507

Merged
merged 1 commit into from
Sep 1, 2021
Merged

log file truncation #3507

merged 1 commit into from
Sep 1, 2021

Conversation

janl
Copy link
Member

@janl janl commented Apr 14, 2021

Helps find corrupted files on servers with lots of shards.

test script:

#!/bin/sh

COUCH=https://a:[email protected]:15984

DB=x-test-goop
CURL="curl -s"

# file does not exist
ls ~/Work/asf/couchdb/dev/lib/node1/data/shards/00000000-ffffffff/$DB*.couch

# reset db
$CURL -X DELETE $COUCH/$DB
$CURL -X PUT $COUCH/$DB?q=1

# add docs so we have something to truncate
$CURL -X PUT $COUCH/$DB/doc1 -d '{"foo":"baaaaaah1"}'
$CURL -X PUT $COUCH/$DB/doc2 -d '{"foo":"baaaaaah2"}'
$CURL -X PUT $COUCH/$DB/doc3 -d '{"foo":"baaaaaah3"}'

# show that we can read from the db
$CURL $COUCH/$DB/_changes?include_docs=true

# truncate
FILE_NAME=`ls ~/Work/asf/couchdb/dev/lib/node1/data/shards/00000000-ffffffff/$DB*.couch`
FILE_SIZE=`ls -l $FILE_NAME | awk '{print $5}'`
NEW_FILE_SIZE=`echo "$FILE_SIZE-5000" | bc`
truncate -s $NEW_FILE_SIZE $FILE_NAME
# rm $FILE_NAME
REAL_NEW_FILE_SIZE=`ls -l $FILE_NAME | awk '{print $5}'`

echo "$FILE_NAME"
echo "fs: $FILE_SIZE, nfs: $NEW_FILE_SIZE, rnfs: $REAL_NEW_FILE_SIZE"

# show error
$CURL $COUCH/$DB/_changes?include_docs=true

Response without the patch:

{"error":"error","reason":"{{{badmatch,eof},\n  [{couch_file,read_raw_iolist_int,3,[{file,\"src/couch_file.erl\"},{line,714}]},\n   {couch_file,handle_call,3,[{file,\"src/couch_file.erl\"},{line,493}]},\n   {gen_server,try_handle_call,4,[{file,\"gen_server.erl\"},{line,636}]},\n   {gen_server,handle_msg,6,[{file,\"gen_server.erl\"},{line,665}]},\n   {proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,247}]}]},\n {gen_server,call,[<0.784.0>,{pread_iolist,16830},infinity]},\n [{gen_server,call,3,[{file,\"gen_server.erl\"},{line,214}]},\n  {couch_file,pread_iolist,2,[{file,\"src/couch_file.erl\"},{line,177}]},\n  {couch_file,pread_binary,2,[{file,\"src/couch_file.erl\"},{line,172}]},\n  {couch_file,pread_term,2,[{file,\"src/couch_file.erl\"},{line,160}]},\n  {couch_btree,get_node,2,[{file,\"src/couch_btree.erl\"},{line,435}]},\n  {couch_btree,reduce_stream_node,11,\n               [{file,\"src/couch_btree.erl\"},{line,622}]},\n  {couch_btree,fold_reduce,4,[{file,\"src/couch_btree.erl\"},{line,81}]},\n  {couch_bt_engine,count_changes_since,2,\n                   [{file,\"src/couch_bt_engine.erl\"},{line,646}]}]}"}

Response with the patch:

{"error":"error","reason":"{{bad_return_value,\n     {file_truncate_error,eof,\n         \"/Users/jan/Work/asf/couchdb/dev/lib/node1/data/shards/00000000-ffffffff/x-test-goop.1618391080.couch\"}},\n {gen_server,call,[<0.6608.1>,{pread_iolist,16830},infinity]},\n [{gen_server,call,3,[{file,\"gen_server.erl\"},{line,214}]},\n  {couch_file,pread_iolist,2,[{file,\"src/couch_file.erl\"},{line,177}]},\n  {couch_file,pread_binary,2,[{file,\"src/couch_file.erl\"},{line,172}]},\n  {couch_file,pread_term,2,[{file,\"src/couch_file.erl\"},{line,160}]},\n  {couch_btree,get_node,2,[{file,\"src/couch_btree.erl\"},{line,435}]},\n  {couch_btree,reduce_stream_node,11,\n      [{file,\"src/couch_btree.erl\"},{line,622}]},\n  {couch_btree,fold_reduce,4,[{file,\"src/couch_btree.erl\"},{line,81}]},\n  {couch_bt_engine,count_changes_since,2,\n      [{file,\"src/couch_bt_engine.erl\"},{line,646}]}]}"}

@janl janl changed the base branch from main to 3.x April 14, 2021 09:41
@bessbd
Copy link
Member

bessbd commented Apr 14, 2021

The error message improvement seems awesome, but we still shouldn't get a stack trace on HTTP, right?

@bessbd
Copy link
Member

bessbd commented Apr 14, 2021

Should we open a follow-up issue / PR?

@janl janl force-pushed the feat/log-file-truncation branch from 60910d4 to 320a45c Compare July 11, 2021 07:37
@janl janl added this to the 3.2.0 milestone Jul 11, 2021
@janl janl force-pushed the feat/log-file-truncation branch from 320a45c to ba4665f Compare July 11, 2021 07:38
@janl
Copy link
Member Author

janl commented Jul 11, 2021

@rnewson is this more in line with what you were looking for here?

@janl janl force-pushed the feat/log-file-truncation branch 2 times, most recently from e96e582 to 268b94b Compare July 13, 2021 10:31
@rnewson
Copy link
Member

rnewson commented Jul 13, 2021

Yes, sorry for delay. +1.

@janl janl merged commit aabc7ae into 3.x Sep 1, 2021
@janl janl deleted the feat/log-file-truncation branch September 1, 2021 13:27
This pull request was closed.
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.

3 participants