janl opened a new pull request #3507: URL: https://github.com/apache/couchdb/pull/3507
Helps find corrupted files on servers with lots of shards. test script: ```sh #!/bin/sh COUCH=http://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: ```erlang {"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_bt ree.erl\"},{line,81}]},\n {couch_bt_engine,count_changes_since,2,\n [{file,\"src/couch_bt_engine.erl\"},{line,646}]}]}"} ``` Response with the patch: ```erlang {"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}]}]}"} ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
