anchor.diff:            num_to_ack :: integer(),
             prepare_time :: integer(),
             commit_time :: integer(),
  +          commit_protocol :: term(),
             state:: atom()}).
   
   %%%===================================================================
  
positive.code:              SD0#state{num_to_ack=NumToAck, from=Sender, state=committing}}
      end.
  
  
  %% @doc the fsm waits for acks indicating that each partition has successfully
  %%	committed the tx and finishes operation.
  
negative.code:     end.
  
  
  %% @doc this state sends a prepare message to all updated partitions and goes
  %%      to the "receive_prepared"state.
  prepare(timeout, SD0=#state{
                          transaction = Transaction,
                          updated_partitions=Updated_partitions, from=_From}) ->
      case length(Updated_partitions) of
          0->
              Snapshot_time=Transaction#transaction.snapshot_time,
              {next_state, committing,
              SD0#state{state=committing, commit_time=Snapshot_time}, 0};
          1-> 
              clocksi_vnode:single_commit(Updated_partitions, Transaction),
              {next_state, single_committing,
              SD0#state{state=committing, num_to_ack=1}};
          _->
              clocksi_vnode:prepare(Updated_partitions, Transaction),
              Num_to_ack=length(Updated_partitions),
              {next_state, receive_prepared,
              SD0#state{num_to_ack=Num_to_ack, state=prepared}}
      end.
  %% @doc state called when 2pc is forced independently of the number of partitions
  %%      involved in the txs.
  prepare_2pc(timeout, SD0=#state{
                          transaction = Transaction,
                          updated_partitions=Updated_partitions, from=From}) ->
      case length(Updated_partitions) of
          0->
              Snapshot_time=Transaction#transaction.snapshot_time,
              gen_fsm:reply(From, {ok, Snapshot_time}),
              {next_state, committing_2pc,
              SD0#state{state=committing, commit_time=Snapshot_time}};
          1-> 
              clocksi_vnode:prepare(Updated_partitions, Transaction),
              Num_to_ack=length(Updated_partitions),
              {next_state, receive_prepared,
              SD0#state{num_to_ack=Num_to_ack, state=prepared}};
          _->
              clocksi_vnode:prepare(Updated_partitions, Transaction),
              Num_to_ack=length(Updated_partitions),
              {next_state, receive_prepared,
              SD0#state{num_to_ack=Num_to_ack, state=prepared}}
      end.
  
  %% @doc in this state, the fsm waits for prepare_time from each updated
  %%      partitions in order to compute the final tx timestamp (the maximum
  %%      of the received prepare_time).
  receive_prepared({prepared, ReceivedPrepareTime},
                   S0=#state{num_to_ack=NumToAck,
                             commit_protocol=CommitProtocol,
                             from=From, prepare_time=PrepareTime}) ->
      MaxPrepareTime = max(PrepareTime, ReceivedPrepareTime),
      case NumToAck of 1 ->
              case CommitProtocol of
              two_phase ->
                  gen_fsm:reply(From, {ok, MaxPrepareTime}),
                  {next_state, committing_2pc,
                  S0#state{prepare_time=MaxPrepareTime, commit_time=MaxPrepareTime, state=committing}};
              _ ->
                  {next_state, committing,
                  S0#state{prepare_time=MaxPrepareTime, commit_time=MaxPrepareTime, state=committing}, 0}
              end;
          _ ->
              {next_state, receive_prepared,
               S0#state{num_to_ack= NumToAck-1, prepare_time=MaxPrepareTime}}
  