org.apache.cassandra.repair.CoordinatedRepairResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-all Show documentation
Show all versions of cassandra-all Show documentation
The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.repair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
public class CoordinatedRepairResult
{
public final Collection> successfulRanges;
public final Collection> failedRanges;
public final Collection> skippedRanges;
public final Optional> results;
public CoordinatedRepairResult(Collection> successfulRanges,
Collection> failedRanges,
Collection> skippedRanges,
List results)
{
this.successfulRanges = successfulRanges != null ? ImmutableList.copyOf(successfulRanges) : Collections.emptyList();
this.failedRanges = failedRanges != null ? ImmutableList.copyOf(failedRanges) : Collections.emptyList();
this.skippedRanges = skippedRanges != null ? ImmutableList.copyOf(skippedRanges) : Collections.emptyList();
this.results = Optional.ofNullable(results);
}
public static CoordinatedRepairResult create(List>> ranges, List results)
{
if (results == null || results.isEmpty())
// something went wrong; assume all sessions failed
return failed(ranges);
assert ranges.size() == results.size() : String.format("range size %d != results size %d;ranges: %s, results: %s", ranges.size(), results.size(), ranges, results);
Collection> successfulRanges = new ArrayList<>();
Collection> failedRanges = new ArrayList<>();
Collection> skippedRanges = new ArrayList<>();
int index = 0;
for (RepairSessionResult sessionResult : results)
{
if (sessionResult != null)
{
// don't record successful repair if we had to skip ranges
Collection> replicas = sessionResult.skippedReplicas ? skippedRanges : successfulRanges;
replicas.addAll(sessionResult.ranges);
}
else
{
// FutureCombiner.successfulOf doesn't keep track of the original, but maintains order, so
// can fetch the original session
failedRanges.addAll(Objects.requireNonNull(ranges.get(index)));
}
index++;
}
return new CoordinatedRepairResult(successfulRanges, failedRanges, skippedRanges, results);
}
private static CoordinatedRepairResult failed(@Nullable List>> ranges)
{
Collection> failedRanges = new ArrayList<>(ranges == null ? 0 : ranges.size());
if (ranges != null)
ranges.forEach(failedRanges::addAll);
return new CoordinatedRepairResult(null, failedRanges, null, null);
}
/**
* Utility method for tests to produce a success result; should only be used by tests as syntaxtic sugar as all
* results must be present else an error is thrown.
*/
@VisibleForTesting
public static CoordinatedRepairResult success(List results)
{
assert results != null && results.stream().allMatch(a -> a != null) : String.format("results was null or had a null (failed) result: %s", results);
List>> ranges = Lists.transform(results, a -> a.ranges);
return create(ranges, results);
}
public boolean hasFailed()
{
return !failedRanges.isEmpty();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy