-
-
Save binarytemple/0fb0fca5acf51a948c4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/lib/riak/erts-5.7.5/bin/escript | |
| %% -*- erlang -*- | |
| %%! -pa /usr/lib/riak/lib/bitcask-1.1.6/ebin | |
| %% Note: this script is designed for Riak 0.14.2 on Debian/Ubuntu | |
| main([Root]) -> | |
| case file:list_dir(filename:absname(Root)) of | |
| {ok, VnodeDirs} -> | |
| [ check_bitcask(filename:absname(Dir, Root)) || Dir <- VnodeDirs]; | |
| {error, Reason} -> | |
| io:format("Couldn't list dir ~s: ~w~n", [Root, Reason]), | |
| halt(1) | |
| end; | |
| main(_) -> | |
| usage(). | |
| check_bitcask(Dir) -> | |
| io:format("== Checking Bitcask Directory ~s ==~n", [Dir]), | |
| case file:list_dir(Dir) of | |
| {ok, Files} -> | |
| [ test_hint(filename:absname(F, Dir)) || F <- Files, | |
| filename:extension(F) =:= ".data"]; | |
| {error, Reason} -> | |
| io:format("\tCouldn't list dir ~s: ~w~n", [Dir, Reason]) | |
| end. | |
| test_hint(Datafile) -> | |
| case bitcask_fileops:open_file(Datafile) of | |
| {ok, Handle} -> | |
| fold_hints(Handle), | |
| bitcask_fileops:close(Handle); | |
| {error, Reason} -> | |
| io:format("\tCouldn't open bitcask data file ~s with reason ~p~n", [Datafile, Reason]) | |
| end. | |
| fold_hints(Handle) -> | |
| FoldFun = fun(_Key, _Ts, _PosInfo, Acc) -> Acc end, | |
| case catch bitcask_fileops:fold_keys(Handle, FoldFun, ok, hintfile) of | |
| ok -> ok; | |
| _Error -> | |
| io:format("\tCorrupted hintfile: ~s~n", [bitcask_fileops:hintfile_name(Handle)]) | |
| end. | |
| usage() -> | |
| io:format("usage: bitcaskhintcheck <bitcask-data-root>\n"), | |
| halt(1). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment