| --- |
| layout: docpage |
| |
| title: "Documentation" |
| |
| is_homepage: false |
| is_sphinx_doc: true |
| |
| doc-parent: "Operating Cassandra" |
| |
| doc-title: "Repair" |
| doc-header-links: ' |
| <link rel="top" title="Apache Cassandra Documentation v4.0-alpha5" href="../index.html"/> |
| <link rel="up" title="Operating Cassandra" href="index.html"/> |
| <link rel="next" title="Read repair" href="read_repair.html"/> |
| <link rel="prev" title="Adding, replacing, moving and removing nodes" href="topo_changes.html"/> |
| ' |
| doc-search-path: "../search.html" |
| |
| extra-footer: ' |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: "", |
| VERSION: "", |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: ".html", |
| HAS_SOURCE: false, |
| SOURCELINK_SUFFIX: ".txt" |
| }; |
| </script> |
| ' |
| |
| --- |
| <div class="container-fluid"> |
| <div class="row"> |
| <div class="col-md-3"> |
| <div class="doc-navigation"> |
| <div class="doc-menu" role="navigation"> |
| <div class="navbar-header"> |
| <button type="button" class="pull-left navbar-toggle" data-toggle="collapse" data-target=".sidebar-navbar-collapse"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| </div> |
| <div class="navbar-collapse collapse sidebar-navbar-collapse"> |
| <form id="doc-search-form" class="navbar-form" action="../search.html" method="get" role="search"> |
| <div class="form-group"> |
| <input type="text" size="30" class="form-control input-sm" name="q" placeholder="Search docs"> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </div> |
| </form> |
| |
| |
| |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="../getting_started/index.html">Getting Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../new/index.html">New Features in Apache Cassandra 4.0</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../architecture/index.html">Architecture</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../cql/index.html">The Cassandra Query Language (CQL)</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../data_modeling/index.html">Data Modeling</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../configuration/index.html">Configuring Cassandra</a></li> |
| <li class="toctree-l1 current"><a class="reference internal" href="index.html">Operating Cassandra</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="snitch.html">Snitch</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="topo_changes.html">Adding, replacing, moving and removing nodes</a></li> |
| <li class="toctree-l2 current"><a class="current reference internal" href="#">Repair</a><ul> |
| <li class="toctree-l3"><a class="reference internal" href="#incremental-and-full-repairs">Incremental and Full Repairs</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#usage-and-best-practices">Usage and Best Practices</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#other-options">Other Options</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="#full-repair-example">Full Repair Example</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="read_repair.html">Read repair</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="hints.html">Hints</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="compaction/index.html">Compaction</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="bloom_filters.html">Bloom Filters</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="compression.html">Compression</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="cdc.html">Change Data Capture</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="backups.html">Backups</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="bulk_loading.html">Bulk Loading</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="metrics.html">Monitoring</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="security.html">Security</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="hardware.html">Hardware Choices</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Cassandra Tools</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../troubleshooting/index.html">Troubleshooting</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../development/index.html">Contributing to Cassandra</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../faq/index.html">Frequently Asked Questions</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../plugins/index.html">Third-Party Plugins</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../bugs.html">Reporting Bugs</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../contactus.html">Contact us</a></li> |
| </ul> |
| |
| |
| |
| </div><!--/.nav-collapse --> |
| </div> |
| </div> |
| </div> |
| <div class="col-md-8"> |
| <div class="content doc-content"> |
| <div class="content-container"> |
| |
| <div class="section" id="repair"> |
| <span id="id1"></span><h1>Repair<a class="headerlink" href="#repair" title="Permalink to this headline">¶</a></h1> |
| <p>Cassandra is designed to remain available if one of it’s nodes is down or unreachable. However, when a node is down or |
| unreachable, it needs to eventually discover the writes it missed. Hints attempt to inform a node of missed writes, but |
| are a best effort, and aren’t guaranteed to inform a node of 100% of the writes it missed. These inconsistencies can |
| eventually result in data loss as nodes are replaced or tombstones expire.</p> |
| <p>These inconsistencies are fixed with the repair process. Repair synchronizes the data between nodes by comparing their |
| respective datasets for their common token ranges, and streaming the differences for any out of sync sections between |
| the nodes. It compares the data with merkle trees, which are a hierarchy of hashes.</p> |
| <div class="section" id="incremental-and-full-repairs"> |
| <h2>Incremental and Full Repairs<a class="headerlink" href="#incremental-and-full-repairs" title="Permalink to this headline">¶</a></h2> |
| <p>There are 2 types of repairs: full repairs, and incremental repairs. Full repairs operate over all of the data in the |
| token range being repaired. Incremental repairs only repair data that’s been written since the previous incremental repair.</p> |
| <p>Incremental repairs are the default repair type, and if run regularly, can significantly reduce the time and io cost of |
| performing a repair. However, it’s important to understand that once an incremental repair marks data as repaired, it won’t |
| try to repair it again. This is fine for syncing up missed writes, but it doesn’t protect against things like disk corruption, |
| data loss by operator error, or bugs in Cassandra. For this reason, full repairs should still be run occasionally.</p> |
| </div> |
| <div class="section" id="usage-and-best-practices"> |
| <h2>Usage and Best Practices<a class="headerlink" href="#usage-and-best-practices" title="Permalink to this headline">¶</a></h2> |
| <p>Since repair can result in a lot of disk and network io, it’s not run automatically by Cassandra. It is run by the operator |
| via nodetool.</p> |
| <p>Incremental repair is the default and is run with the following command:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>nodetool repair |
| </pre></div> |
| </div> |
| <p>A full repair can be run with the following command:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>nodetool repair --full |
| </pre></div> |
| </div> |
| <p>Additionally, repair can be run on a single keyspace:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>nodetool repair [options] <keyspace_name> |
| </pre></div> |
| </div> |
| <p>Or even on specific tables:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>nodetool repair [options] <keyspace_name> <table1> <table2> |
| </pre></div> |
| </div> |
| <p>The repair command only repairs token ranges on the node being repaired, it doesn’t repair the whole cluster. By default, repair |
| will operate on all token ranges replicated by the node you’re running repair on, which will cause duplicate work if you run it |
| on every node. The <code class="docutils literal notranslate"><span class="pre">-pr</span></code> flag will only repair the “primary” ranges on a node, so you can repair your entire cluster by running |
| <code class="docutils literal notranslate"><span class="pre">nodetool</span> <span class="pre">repair</span> <span class="pre">-pr</span></code> on each node in a single datacenter.</p> |
| <p>The specific frequency of repair that’s right for your cluster, of course, depends on several factors. However, if you’re |
| just starting out and looking for somewhere to start, running an incremental repair every 1-3 days, and a full repair every |
| 1-3 weeks is probably reasonable. If you don’t want to run incremental repairs, a full repair every 5 days is a good place |
| to start.</p> |
| <p>At a minimum, repair should be run often enough that the gc grace period never expires on unrepaired data. Otherwise, deleted |
| data could reappear. With a default gc grace period of 10 days, repairing every node in your cluster at least once every 7 days |
| will prevent this, while providing enough slack to allow for delays.</p> |
| </div> |
| <div class="section" id="other-options"> |
| <h2>Other Options<a class="headerlink" href="#other-options" title="Permalink to this headline">¶</a></h2> |
| <dl class="docutils"> |
| <dt><code class="docutils literal notranslate"><span class="pre">-pr,</span> <span class="pre">--partitioner-range</span></code></dt> |
| <dd>Restricts repair to the ‘primary’ token ranges of the node being repaired. A primary range is just a token range for |
| which a node is the first replica in the ring.</dd> |
| <dt><code class="docutils literal notranslate"><span class="pre">-prv,</span> <span class="pre">--preview</span></code></dt> |
| <dd>Estimates the amount of streaming that would occur for the given repair command. This builds the merkle trees, and prints |
| the expected streaming activity, but does not actually do any streaming. By default, incremental repairs are estimated, |
| add the <code class="docutils literal notranslate"><span class="pre">--full</span></code> flag to estimate a full repair.</dd> |
| <dt><code class="docutils literal notranslate"><span class="pre">-vd,</span> <span class="pre">--validate</span></code></dt> |
| <dd>Verifies that the repaired data is the same across all nodes. Similiar to <code class="docutils literal notranslate"><span class="pre">--preview</span></code>, this builds and compares merkle |
| trees of repaired data, but doesn’t do any streaming. This is useful for troubleshooting. If this shows that the repaired |
| data is out of sync, a full repair should be run.</dd> |
| </dl> |
| <div class="admonition seealso"> |
| <p class="first admonition-title">See also</p> |
| <p class="last"><a class="reference internal" href="../tools/nodetool/repair.html#nodetool-repair"><span class="std std-ref">nodetool repair docs</span></a></p> |
| </div> |
| </div> |
| <div class="section" id="full-repair-example"> |
| <h2>Full Repair Example<a class="headerlink" href="#full-repair-example" title="Permalink to this headline">¶</a></h2> |
| <p>Full repair is typically needed to redistribute data after increasing the replication factor of a keyspace or after adding a node to the cluster. Full repair involves streaming SSTables. To demonstrate full repair start with a three node cluster.</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[ec2-user@ip-10-0-2-238 ~]$ nodetool status |
| Datacenter: us-east-1 |
| ===================== |
| Status=Up/Down |
| |/ State=Normal/Leaving/Joining/Moving |
| -- Address Load Tokens Owns Host ID Rack |
| UN 10.0.1.115 547 KiB 256 ? b64cb32a-b32a-46b4-9eeb-e123fa8fc287 us-east-1b |
| UN 10.0.3.206 617.91 KiB 256 ? 74863177-684b-45f4-99f7-d1006625dc9e us-east-1d |
| UN 10.0.2.238 670.26 KiB 256 ? 4dcdadd2-41f9-4f34-9892-1f20868b27c7 us-east-1c |
| </pre></div> |
| </div> |
| <p>Create a keyspace with replication factor 3:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cqlsh> DROP KEYSPACE cqlkeyspace; |
| cqlsh> CREATE KEYSPACE CQLKeyspace |
| ... WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}; |
| </pre></div> |
| </div> |
| <p>Add a table to the keyspace:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cqlsh> use cqlkeyspace; |
| cqlsh:cqlkeyspace> CREATE TABLE t ( |
| ... id int, |
| ... k int, |
| ... v text, |
| ... PRIMARY KEY (id) |
| ... ); |
| </pre></div> |
| </div> |
| <p>Add table data:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cqlsh:cqlkeyspace> INSERT INTO t (id, k, v) VALUES (0, 0, 'val0'); |
| cqlsh:cqlkeyspace> INSERT INTO t (id, k, v) VALUES (1, 1, 'val1'); |
| cqlsh:cqlkeyspace> INSERT INTO t (id, k, v) VALUES (2, 2, 'val2'); |
| </pre></div> |
| </div> |
| <p>A query lists the data added:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cqlsh:cqlkeyspace> SELECT * FROM t; |
| |
| id | k | v |
| ----+---+------ |
| 1 | 1 | val1 |
| 0 | 0 | val0 |
| 2 | 2 | val2 |
| (3 rows) |
| </pre></div> |
| </div> |
| <p>Make the following changes to a three node cluster:</p> |
| <ol class="arabic simple"> |
| <li>Increase the replication factor from 3 to 4.</li> |
| <li>Add a 4th node to the cluster</li> |
| </ol> |
| <p>When the replication factor is increased the following message gets output indicating that a full repair is needed as per (<a class="reference external" href="https://issues.apache.org/jira/browse/CASSANDRA-13079">CASSANDRA-13079</a>):</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>cqlsh:cqlkeyspace> ALTER KEYSPACE CQLKeyspace |
| ... WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 4}; |
| Warnings : |
| When increasing replication factor you need to run a full (-full) repair to distribute the |
| data. |
| </pre></div> |
| </div> |
| <p>Perform a full repair on the keyspace <code class="docutils literal notranslate"><span class="pre">cqlkeyspace</span></code> table <code class="docutils literal notranslate"><span class="pre">t</span></code> with following command:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>nodetool repair -full cqlkeyspace t |
| </pre></div> |
| </div> |
| <p>Full repair completes in about a second as indicated by the output:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[ec2-user@ip-10-0-2-238 ~]$ nodetool repair -full cqlkeyspace t |
| [2019-08-17 03:06:21,445] Starting repair command #1 (fd576da0-c09b-11e9-b00c-1520e8c38f00), repairing keyspace cqlkeyspace with repair options (parallelism: parallel, primary range: false, incremental: false, job threads: 1, ColumnFamilies: [t], dataCenters: [], hosts: [], previewKind: NONE, # of ranges: 1024, pull repair: false, force repair: false, optimise streams: false) |
| [2019-08-17 03:06:23,059] Repair session fd8e5c20-c09b-11e9-b00c-1520e8c38f00 for range [(-8792657144775336505,-8786320730900698730], (-5454146041421260303,-5439402053041523135], (4288357893651763201,4324309707046452322], ... , (4350676211955643098,4351706629422088296]] finished (progress: 0%) |
| [2019-08-17 03:06:23,077] Repair completed successfully |
| [2019-08-17 03:06:23,077] Repair command #1 finished in 1 second |
| [ec2-user@ip-10-0-2-238 ~]$ |
| </pre></div> |
| </div> |
| <p>The <code class="docutils literal notranslate"><span class="pre">nodetool</span>  <span class="pre">tpstats</span></code> command should list a repair having been completed as <code class="docutils literal notranslate"><span class="pre">Repair-Task</span></code> > <code class="docutils literal notranslate"><span class="pre">Completed</span></code> column value of 1:</p> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[ec2-user@ip-10-0-2-238 ~]$ nodetool tpstats |
| Pool Name Active Pending Completed Blocked All time blocked |
| ReadStage 0 0 99 0 0 |
| … |
| Repair-Task 0 0 1 0 0 |
| RequestResponseStage 0 0 2078 0 0 |
| </pre></div> |
| </div> |
| </div> |
| </div> |
| |
| |
| |
| |
| <div class="doc-prev-next-links" role="navigation" aria-label="footer navigation"> |
| |
| <a href="read_repair.html" class="btn btn-default pull-right " role="button" title="Read repair" accesskey="n">Next <span class="glyphicon glyphicon-circle-arrow-right" aria-hidden="true"></span></a> |
| |
| |
| <a href="topo_changes.html" class="btn btn-default" role="button" title="Adding, replacing, moving and removing nodes" accesskey="p"><span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span> Previous</a> |
| |
| </div> |
| |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |