Skip to content

Instantly share code, notes, and snippets.

View angrycub's full-sized avatar

Charlie Voiselle angrycub

View GitHub Profile
@angrycub
angrycub / check-debugs.sh.md
Last active July 14, 2016 13:54
Forever WIP preprocessor for a cluster's worth of Riak Debugs. Catches some of the faves and biggies
@angrycub
angrycub / example_errors.md
Created June 29, 2015 16:46
Examples of Riak Error Log Messages

eacces

Note: It is not eaccess

An example created when the ring folder is not owned by the user riak is running as:

2015-06-23 14:57:43.073 [error] <0.154.0>@riak_core_ring_manager:do_write_ringfile:236 Unable to write ring to "./data/ring/riak_core_ring.default.20150623185743" - {badmatch,{error,eacces}}

emfile

@angrycub
angrycub / convert_binary_ring.sh
Created June 25, 2015 17:51
Convert Binary Ring to Text
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname convert_binary_ring -mnesia debug verbose
main([RingFile, OutFile]) ->
try
{ok, Binary} = file:read_file(RingFile),
Ring = binary_to_term(Binary),
try
file:write_file(OutFile, io_lib:format("~p.~n", [Ring])),
@angrycub
angrycub / force_remove_s3_bucket.erl
Last active October 17, 2017 10:22
Snippet to forcibly remove a CS Bucket from a Riak CS User
Force_remove_s3_bucket = fun(UserID, Bucket) ->
Update_user_buckets = fun(User, Bucket) ->
Buckets = User#rcs_user_v2.buckets,
%% At this point any siblings from the read of the
%% user record have been resolved so the user bucket
%% list should have 0 or 1 buckets that share a name
%% with `Bucket'.
case [B || B <- Buckets, B#moss_bucket_v1.name =:= Bucket#moss_bucket_v1.name] of
[] ->
{ok, User#rcs_user_v2{buckets=[Bucket | Buckets]}};
@angrycub
angrycub / Garbage.erl
Last active October 17, 2017 10:22
Helper Shell Funs for Riak CS Cleanup
%% Shell functions that can be run in `riak-cs attach`
%% Peek({S3Bucket, Key}) will fetch an object and display the sibling count and
%% the number of manifests in the object.
Peek = fun({Bucket, Key}) ->
io:format("Peeking at ~p/~p.~n", [Bucket, Key]),
{ok, RcPid} = riak_cs_riak_client:checkout(),
ManifestBucket = riak_cs_utils:to_bucket_name(objects, Bucket),
ok = riak_cs_riak_client:set_bucket_name(RcPid, Bucket),
@angrycub
angrycub / preflist.erl
Created June 18, 2015 00:27
Get a Preflist for a bucket key
Preflist = fun(Bucket,Key) ->
BKey = {Bucket,Key},
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
DocIdx = riak_core_util:chash_key(BKey),
BucketProps = riak_core_bucket:get_bucket(Bucket, Ring),
[NValue] = [Y || {X1, Y} <- BucketProps, n_val == X1],
UpNodes = riak_core_node_watcher:nodes(riak_kv),
Preflist2 = riak_core_apl:get_apl_ann(DocIdx, NValue, Ring, UpNodes),
[IndexNode || {IndexNode, _Type} <- Preflist2]
end.
@angrycub
angrycub / listcask.erl
Last active August 29, 2015 14:22
ListCask redux
%% These are shell functions that can be used to output a keylist from a bitcask file in terms of Riak {Bucket,Key} tuples
%% They should be run from `riak attach`. Paste in the contents and run ListAll("filename.txt"). Profit.
ListCask = fun(Vnode,OutFile) ->
Bk_to_tuple =
fun(<<1:7, HasType:1, Sz:16/integer,
TypeOrBucket:Sz/bytes, Rest/binary>>) ->
case HasType of
0 ->
%% no type, first field is bucket
{TypeOrBucket, Rest};
@angrycub
angrycub / MonitoringRiak.md
Last active October 17, 2017 10:22
Additional Information about Monitoring Riak

Additional Information about Monitoring Riak

Riak is a complex system that includes many moving parts to monitor, such as the health of the hardware, the well-being of the software, and the responsiveness of the network. This document will discuss metrics, thresholds, and values that indicate when your monitoring system should be sending alarms.

System metrics to monitor

@angrycub
angrycub / lager_sensitive_formatter.erl
Created March 25, 2015 20:00
Modifying lager_default_formatter to make a filtering formatter
%% Copyright (c) 2015 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
@angrycub
angrycub / advanced.config
Created March 25, 2015 17:50
Advanced config to add a redacted_console.log (Paths are from a devrel)
[
{lager,
[
{error_logger_hwm,100},
{error_logger_redirect,true},
{crash_log_date,"$D0"},
{crash_log_size,10485760},
{crash_log_msg_size,65536},
{handlers,
[