RepairSession (apache-cassandra API)
Date: 2014-10-21

org.apache.cassandra.repair

## Class RepairSession

- java.lang.Object
- - org.apache.cassandra.utils.WrappedRunnable
  - - org.apache.cassandra.repair.RepairSession

- All Implemented Interfaces:
    java.lang.Runnable, IEndpointStateChangeSubscriber, IFailureDetectionEventListener, IRepairJobEventListener

      public class RepairSession
      extends WrappedRunnable
      implements IEndpointStateChangeSubscriber, IFailureDetectionEventListener, IRepairJobEventListener

  Coordinates the (active) repair of a token range. A given RepairSession repairs a set of replicas for a given range on a list of column families. For each of the column family to repair, RepairSession creates a RepairJob that handles the repair of that CF. A given RepairJob has the 2 main phases: 1. Validation phase: the job requests merkle trees from each of the replica involves (RepairJob.sendTreeRequests()) and waits until all trees are received (in validationComplete()). 2. Synchonization phase: once all trees are received, the job compares each tree with all the other using a so-called Differencer (started by submitDifferencers()). If differences there is between 2 trees, the concerned Differencer will start a streaming of the difference between the 2 endpoint concerned (Differencer.performStreamingRepair). The job is done once all its Differencer are done (i.e. have either computed no differences or the streaming they started is done (syncComplete())). A given session will execute the first phase (validation phase) of each of it's job sequentially. In other words, it will start the first job and only start the next one once that first job validation phase is complete. This is done so that the replica only create one merkle tree at a time, which is our way to ensure that such creation starts roughly at the same time on every node (see CASSANDRA-2816). However the synchronization phases are allowed to run concurrently (with each other and with validation phases). A given RepairJob has 2 modes: either sequential or not (isSequential flag). If sequential, it will requests merkle tree creation from each replica in sequence (though in that case we still first send a message to each node to flush and snapshot data so each merkle tree creation is still done on similar data, even if the actual creation is not done simulatneously). If not sequential, all merkle tree are requested in parallel. Similarly, if a job is sequential, it will handle one Differencer at a time, but will handle all of them in parallel otherwise.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `java.util.concurrent.locks.Condition` | `differencingDone`
    `java.util.Set<java.net.InetAddress>` | `endpoints`
    `boolean` | `isSequential`
    `java.lang.String` | `keyspace`
    `java.util.UUID` | `parentRepairSession`
    `Range<Token>` | `range` Range to repair

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RepairSession(java.util.UUID parentRepairSession, Range<Token> range, java.lang.String keyspace, boolean isSequential, java.util.Set<java.net.InetAddress> endpoints, java.lang.String... cfnames)` Create new repair session.
    `RepairSession(java.util.UUID parentRepairSession, java.util.UUID id, Range<Token> range, java.lang.String keyspace, boolean isSequential, java.util.Set<java.net.InetAddress> endpoints, java.lang.String[] cfnames)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `beforeChange(java.net.InetAddress endpoint, EndpointState currentState, ApplicationState newStateKey, VersionedValue newValue)`
    `void` | `convict(java.net.InetAddress endpoint, double phi)` Convict the specified endpoint.
    `void` | `failedSnapshot()` Signal that there was a failure during the snapshot creation process.
    `void` | `forceShutdown()` clear all RepairJobs and terminate this session.
    `java.util.UUID` | `getId()`
    `Range<Token>` | `getRange()`
    `void` | `onAlive(java.net.InetAddress endpoint, EndpointState state)`
    `void` | `onChange(java.net.InetAddress endpoint, ApplicationState state, VersionedValue value)`
    `void` | `onDead(java.net.InetAddress endpoint, EndpointState state)`
    `void` | `onJoin(java.net.InetAddress endpoint, EndpointState epState)` Use to inform interested parties about the change in the state for specified endpoint
    `void` | `onRemove(java.net.InetAddress endpoint)`
    `void` | `onRestart(java.net.InetAddress endpoint, EndpointState epState)` Called whenever a node is restarted.
    `void` | `runMayThrow()`
    `void` | `syncComplete(RepairJobDesc desc, NodePair nodes, boolean success)` Notify this session that sync completed/failed with given `NodePair`.
    `void` | `terminate()`
    `void` | `validationComplete(RepairJobDesc desc, java.net.InetAddress endpoint, MerkleTree tree)` Receive merkle tree response or failed response from `endpoint` for current repair job.

    - ### Methods inherited from class org.apache.cassandra.utils.WrappedRunnable

      `run`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### keyspace

          public final java.lang.String keyspace

    - #### isSequential

          public final boolean isSequential

    - #### range

          public final Range<Token> range

      Range to repair

    - #### endpoints

          public final java.util.Set<java.net.InetAddress> endpoints

    - #### differencingDone

          public final java.util.concurrent.locks.Condition differencingDone

    - #### parentRepairSession

          public final java.util.UUID parentRepairSession

  - ### Constructor Detail

    - #### RepairSession

          public RepairSession(java.util.UUID parentRepairSession,
                       Range<Token> range,
                       java.lang.String keyspace,
                       boolean isSequential,
                       java.util.Set<java.net.InetAddress> endpoints,
                       java.lang.String... cfnames)

      Create new repair session.
      Parameters:
        `range` - range to repair
        `keyspace` - name of keyspace
        `isSequential` - true if performing repair on snapshots sequentially
        `endpoints` - the data centers that should be part of the repair; null for all DCs
        `cfnames` - names of columnfamilies

    - #### RepairSession

          public RepairSession(java.util.UUID parentRepairSession,
                       java.util.UUID id,
                       Range<Token> range,
                       java.lang.String keyspace,
                       boolean isSequential,
                       java.util.Set<java.net.InetAddress> endpoints,
                       java.lang.String[] cfnames)

  - ### Method Detail

    - #### getId

          public java.util.UUID getId()

    - #### getRange

          public Range<Token> getRange()

    - #### validationComplete

          public void validationComplete(RepairJobDesc desc,
                                java.net.InetAddress endpoint,
                                MerkleTree tree)

      Receive merkle tree response or failed response from `endpoint` for current repair job.
      Parameters:
        `desc` - repair job description
        `endpoint` - endpoint that sent merkle tree
        `tree` - calculated merkle tree, or null if validation failed

    - #### syncComplete

          public void syncComplete(RepairJobDesc desc,
                          NodePair nodes,
                          boolean success)

      Notify this session that sync completed/failed with given `NodePair`.
      Parameters:
        `desc` - synced repair job
        `nodes` - nodes that completed sync
        `success` - true if sync succeeded

    - #### runMayThrow

          public void runMayThrow()
                           throws java.lang.Exception

      Specified by:
        `runMayThrow` in class `WrappedRunnable`
      Throws:
        `java.lang.Exception`

    - #### terminate

          public void terminate()

    - #### forceShutdown

          public void forceShutdown()

      clear all RepairJobs and terminate this session.

    - #### failedSnapshot

          public void failedSnapshot()

      Description copied from interface: `IRepairJobEventListener`
      Signal that there was a failure during the snapshot creation process.
      Specified by:
        `failedSnapshot` in interface `IRepairJobEventListener`

    - #### onJoin

          public void onJoin(java.net.InetAddress endpoint,
                    EndpointState epState)

      Description copied from interface: `IEndpointStateChangeSubscriber`
      Use to inform interested parties about the change in the state for specified endpoint
      Specified by:
        `onJoin` in interface `IEndpointStateChangeSubscriber`
      Parameters:
        `endpoint` - endpoint for which the state change occurred.
        `epState` - state that actually changed for the above endpoint.

    - #### beforeChange

          public void beforeChange(java.net.InetAddress endpoint,
                          EndpointState currentState,
                          ApplicationState newStateKey,
                          VersionedValue newValue)

      Specified by:
        `beforeChange` in interface `IEndpointStateChangeSubscriber`

    - #### onChange

          public void onChange(java.net.InetAddress endpoint,
                      ApplicationState state,
                      VersionedValue value)

      Specified by:
        `onChange` in interface `IEndpointStateChangeSubscriber`

    - #### onAlive

          public void onAlive(java.net.InetAddress endpoint,
                     EndpointState state)

      Specified by:
        `onAlive` in interface `IEndpointStateChangeSubscriber`

    - #### onDead

          public void onDead(java.net.InetAddress endpoint,
                    EndpointState state)

      Specified by:
        `onDead` in interface `IEndpointStateChangeSubscriber`

    - #### onRemove

          public void onRemove(java.net.InetAddress endpoint)

      Specified by:
        `onRemove` in interface `IEndpointStateChangeSubscriber`

    - #### onRestart

          public void onRestart(java.net.InetAddress endpoint,
                       EndpointState epState)

      Description copied from interface: `IEndpointStateChangeSubscriber`
      Called whenever a node is restarted. Note that there is no guarantee when that happens that the node was previously marked down. It will have only if `state.isAlive() == false` as `state` is from before the restarted node is marked up.
      Specified by:
        `onRestart` in interface `IEndpointStateChangeSubscriber`

    - #### convict

          public void convict(java.net.InetAddress endpoint,
                     double phi)

      Description copied from interface: `IFailureDetectionEventListener`
      Convict the specified endpoint.
      Specified by:
        `convict` in interface `IFailureDetectionEventListener`
      Parameters:
        `endpoint` - endpoint to be convicted
        `phi` - the value of phi with with ep was convicted

Copyright © 2014 The Apache Software Foundation