<commit_before>-module(riak_handoff_receiver).

-include("riakserver_pb.hrl").
-behaviour(gen_server2).

-export([start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-record(state, {sock, partition, vnode}).

start_link(Socket) ->
    gen_server2:start_link(?MODULE, [Socket], []).

init([Socket]) -> 
    inet:setopts(Socket, [{active, once}, {packet, 4}, {header, 1}]),
    {ok, #state{sock=Socket}}.

handle_info({tcp_closed, Socket}, State=#state{sock=Socket}) ->
    {stop, normal, State};
handle_info({tcp, _Sock, Data}, State=#state{sock=Socket}) ->
    [MsgType|MsgData] = Data,
    NewState = process_message(MsgType,MsgData,State),
    inet:setopts(Socket, [{active, once}]),
    {noreply, NewState}.

process_message(0, MsgData, State) ->
    <<Partition:160/integer>> = MsgData,
    {ok, VNode} = gen_server2:call(riak_vnode_master, {get_vnode, Partition}),  
    io:format("got partition: ~p vnode=~p~n", [Partition, VNode]),
    State#state{partition=Partition, vnode=VNode};
process_message(1, MsgData, State=#state{vnode=VNode}) ->
    % header of 1 is a riakobject_pb
    RO_PB = riakserver_pb:decode_riakobject_pb(zlib:unzip(MsgData)),
    io:format("got a 1 ~p ~p~n",
              [RO_PB#riakobject_pb.bucket,RO_PB#riakobject_pb.key]),
    BKey = {RO_PB#riakobject_pb.bucket,RO_PB#riakobject_pb.key},
    ok = gen_fsm:sync_send_all_state_event(VNode, {diffobj, {BKey, RO_PB#riakobject_pb.val}}),
    State;
process_message(2, _MsgData, State=#state{sock=Socket}) ->
    io:format("got a 2~n"),
    ok = gen_tcp:send(Socket, <<2:8,"sync">>),
    io:format("sent sync~n"),
    State.

handle_call(_Request, _From, State) -> {reply, ok, State}.

handle_cast(_Msg, State) -> {noreply, State}.

terminate(_Reason, _State) -> ok.

code_change(_OldVsn, State, _Extra) -> {ok, State}.
<commit_msg>longer timeout for diffobj_put<commit_after>-module(riak_handoff_receiver).

-include("riakserver_pb.hrl").
-behaviour(gen_server2).

-export([start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

-record(state, {sock, partition, vnode}).

start_link(Socket) ->
    gen_server2:start_link(?MODULE, [Socket], []).

init([Socket]) -> 
    inet:setopts(Socket, [{active, once}, {packet, 4}, {header, 1}]),
    {ok, #state{sock=Socket}}.

handle_info({tcp_closed, Socket}, State=#state{sock=Socket}) ->
    {stop, normal, State};
handle_info({tcp, _Sock, Data}, State=#state{sock=Socket}) ->
    [MsgType|MsgData] = Data,
    NewState = process_message(MsgType,MsgData,State),
    inet:setopts(Socket, [{active, once}]),
    {noreply, NewState}.

process_message(0, MsgData, State) ->
    <<Partition:160/integer>> = MsgData,
    {ok, VNode} = gen_server2:call(riak_vnode_master, {get_vnode, Partition}),  
    io:format("got partition: ~p vnode=~p~n", [Partition, VNode]),
    State#state{partition=Partition, vnode=VNode};
process_message(1, MsgData, State=#state{vnode=VNode}) ->
    % header of 1 is a riakobject_pb
    RO_PB = riakserver_pb:decode_riakobject_pb(zlib:unzip(MsgData)),
    io:format("got a 1 ~p ~p~n",
              [RO_PB#riakobject_pb.bucket,RO_PB#riakobject_pb.key]),
    BKey = {RO_PB#riakobject_pb.bucket,RO_PB#riakobject_pb.key},
    ok = gen_fsm:sync_send_all_state_event(VNode, {diffobj, {BKey, RO_PB#riakobject_pb.val}}, 60000),
    State;
process_message(2, _MsgData, State=#state{sock=Socket}) ->
    io:format("got a 2~n"),
    ok = gen_tcp:send(Socket, <<2:8,"sync">>),
    io:format("sent sync~n"),
    State.

handle_call(_Request, _From, State) -> {reply, ok, State}.

handle_cast(_Msg, State) -> {noreply, State}.

terminate(_Reason, _State) -> ok.

code_change(_OldVsn, State, _Extra) -> {ok, State}.

{'fraction_non_alphanumeric': 0.18044515103338632, 'fraction_numerical': 0.013513513513513514, 'mean_word_length': 5.04, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4540309', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1431, 'n_words': 242}