use of org.apache.cassandra.schema.TableId in project cassandra by apache.
the class CommitLogReplayer method construct.
public static CommitLogReplayer construct(CommitLog commitLog) {
// compute per-CF and global replay intervals
Map<TableId, IntervalSet<CommitLogPosition>> cfPersisted = new HashMap<>();
ReplayFilter replayFilter = ReplayFilter.create();
for (ColumnFamilyStore cfs : ColumnFamilyStore.all()) {
// but, if we've truncated the cf in question, then we need to need to start replay after the truncation
CommitLogPosition truncatedAt = SystemKeyspace.getTruncatedPosition(cfs.metadata.id);
if (truncatedAt != null) {
// Point in time restore is taken to mean that the tables need to be replayed even if they were
// deleted at a later point in time. Any truncation record after that point must thus be cleared prior
// to replay (CASSANDRA-9195).
long restoreTime = commitLog.archiver.restorePointInTime;
long truncatedTime = SystemKeyspace.getTruncatedAt(cfs.metadata.id);
if (truncatedTime > restoreTime) {
if (replayFilter.includes(cfs.metadata)) {
logger.info("Restore point in time is before latest truncation of table {}.{}. Clearing truncation record.", cfs.metadata.keyspace, cfs.metadata.name);
SystemKeyspace.removeTruncationRecord(cfs.metadata.id);
truncatedAt = null;
}
}
}
IntervalSet<CommitLogPosition> filter = persistedIntervals(cfs.getLiveSSTables(), truncatedAt);
cfPersisted.put(cfs.metadata.id, filter);
}
CommitLogPosition globalPosition = firstNotCovered(cfPersisted.values());
logger.debug("Global replay position is {} from columnfamilies {}", globalPosition, FBUtilities.toString(cfPersisted));
return new CommitLogReplayer(commitLog, globalPosition, cfPersisted, replayFilter);
}
use of org.apache.cassandra.schema.TableId in project cassandra by apache.
the class RepairMessageVerbHandler method doVerb.
public void doVerb(final Message<RepairMessage> message) {
// TODO add cancel/interrupt message
RepairJobDesc desc = message.payload.desc;
try {
switch(message.verb()) {
case PREPARE_MSG:
PrepareMessage prepareMessage = (PrepareMessage) message.payload;
logger.debug("Preparing, {}", prepareMessage);
if (!ActiveRepairService.verifyCompactionsPendingThreshold(prepareMessage.parentRepairSession, prepareMessage.previewKind)) {
// error is logged in verifyCompactionsPendingThreshold
sendFailureResponse(message);
return;
}
List<ColumnFamilyStore> columnFamilyStores = new ArrayList<>(prepareMessage.tableIds.size());
for (TableId tableId : prepareMessage.tableIds) {
ColumnFamilyStore columnFamilyStore = ColumnFamilyStore.getIfExists(tableId);
if (columnFamilyStore == null) {
logErrorAndSendFailureResponse(String.format("Table with id %s was dropped during prepare phase of repair", tableId), message);
return;
}
columnFamilyStores.add(columnFamilyStore);
}
ActiveRepairService.instance.registerParentRepairSession(prepareMessage.parentRepairSession, message.from(), columnFamilyStores, prepareMessage.ranges, prepareMessage.isIncremental, prepareMessage.timestamp, prepareMessage.isGlobal, prepareMessage.previewKind);
MessagingService.instance().send(message.emptyResponse(), message.from());
break;
case SNAPSHOT_MSG:
logger.debug("Snapshotting {}", desc);
final ColumnFamilyStore cfs = ColumnFamilyStore.getIfExists(desc.keyspace, desc.columnFamily);
if (cfs == null) {
logErrorAndSendFailureResponse(String.format("Table %s.%s was dropped during snapshot phase of repair %s", desc.keyspace, desc.columnFamily, desc.parentSessionId), message);
return;
}
ActiveRepairService.ParentRepairSession prs = ActiveRepairService.instance.getParentRepairSession(desc.parentSessionId);
prs.setHasSnapshots();
TableRepairManager repairManager = cfs.getRepairManager();
if (prs.isGlobal) {
repairManager.snapshot(desc.parentSessionId.toString(), prs.getRanges(), false);
} else {
repairManager.snapshot(desc.parentSessionId.toString(), desc.ranges, true);
}
logger.debug("Enqueuing response to snapshot request {} to {}", desc.sessionId, message.from());
MessagingService.instance().send(message.emptyResponse(), message.from());
break;
case VALIDATION_REQ:
ValidationRequest validationRequest = (ValidationRequest) message.payload;
logger.debug("Validating {}", validationRequest);
// trigger read-only compaction
ColumnFamilyStore store = ColumnFamilyStore.getIfExists(desc.keyspace, desc.columnFamily);
if (store == null) {
logger.error("Table {}.{} was dropped during snapshot phase of repair {}", desc.keyspace, desc.columnFamily, desc.parentSessionId);
MessagingService.instance().send(Message.out(VALIDATION_RSP, new ValidationResponse(desc)), message.from());
return;
}
ActiveRepairService.instance.consistent.local.maybeSetRepairing(desc.parentSessionId);
PreviewKind previewKind;
try {
previewKind = previewKind(desc.parentSessionId);
} catch (NoSuchRepairSessionException e) {
logger.warn("Parent repair session {} has been removed, failing repair", desc.parentSessionId);
MessagingService.instance().send(Message.out(VALIDATION_RSP, new ValidationResponse(desc)), message.from());
return;
}
Validator validator = new Validator(desc, message.from(), validationRequest.nowInSec, isIncremental(desc.parentSessionId), previewKind);
ValidationManager.instance.submitValidation(store, validator);
break;
case SYNC_REQ:
// forwarded sync request
SyncRequest request = (SyncRequest) message.payload;
logger.debug("Syncing {}", request);
StreamingRepairTask task = new StreamingRepairTask(desc, request.initiator, request.src, request.dst, request.ranges, isIncremental(desc.parentSessionId) ? desc.parentSessionId : null, request.previewKind, request.asymmetric);
task.run();
break;
case CLEANUP_MSG:
logger.debug("cleaning up repair");
CleanupMessage cleanup = (CleanupMessage) message.payload;
ActiveRepairService.instance.removeParentRepairSession(cleanup.parentRepairSession);
MessagingService.instance().send(message.emptyResponse(), message.from());
break;
case PREPARE_CONSISTENT_REQ:
ActiveRepairService.instance.consistent.local.handlePrepareMessage(message.from(), (PrepareConsistentRequest) message.payload);
break;
case PREPARE_CONSISTENT_RSP:
ActiveRepairService.instance.consistent.coordinated.handlePrepareResponse((PrepareConsistentResponse) message.payload);
break;
case FINALIZE_PROPOSE_MSG:
ActiveRepairService.instance.consistent.local.handleFinalizeProposeMessage(message.from(), (FinalizePropose) message.payload);
break;
case FINALIZE_PROMISE_MSG:
ActiveRepairService.instance.consistent.coordinated.handleFinalizePromiseMessage((FinalizePromise) message.payload);
break;
case FINALIZE_COMMIT_MSG:
ActiveRepairService.instance.consistent.local.handleFinalizeCommitMessage(message.from(), (FinalizeCommit) message.payload);
break;
case FAILED_SESSION_MSG:
FailSession failure = (FailSession) message.payload;
ActiveRepairService.instance.consistent.coordinated.handleFailSessionMessage(failure);
ActiveRepairService.instance.consistent.local.handleFailSessionMessage(message.from(), failure);
break;
case STATUS_REQ:
ActiveRepairService.instance.consistent.local.handleStatusRequest(message.from(), (StatusRequest) message.payload);
break;
case STATUS_RSP:
ActiveRepairService.instance.consistent.local.handleStatusResponse(message.from(), (StatusResponse) message.payload);
break;
default:
ActiveRepairService.instance.handleMessage(message);
break;
}
} catch (Exception e) {
logger.error("Got error, removing parent repair session");
if (desc != null && desc.parentSessionId != null)
ActiveRepairService.instance.removeParentRepairSession(desc.parentSessionId);
throw new RuntimeException(e);
}
}
use of org.apache.cassandra.schema.TableId in project cassandra by apache.
the class LocalSessions method getPendingStats.
public PendingStats getPendingStats(TableId tid, Collection<Range<Token>> ranges) {
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(tid);
Preconditions.checkArgument(cfs != null);
PendingStat.Builder pending = new PendingStat.Builder();
PendingStat.Builder finalized = new PendingStat.Builder();
PendingStat.Builder failed = new PendingStat.Builder();
Map<UUID, PendingStat> stats = cfs.getPendingRepairStats();
for (Map.Entry<UUID, PendingStat> entry : stats.entrySet()) {
UUID sessionID = entry.getKey();
PendingStat stat = entry.getValue();
Verify.verify(sessionID.equals(Iterables.getOnlyElement(stat.sessions)));
LocalSession session = sessions.get(sessionID);
Verify.verifyNotNull(session);
if (!Iterables.any(ranges, r -> r.intersects(session.ranges)))
continue;
switch(session.getState()) {
case FINALIZED:
finalized.addStat(stat);
break;
case FAILED:
failed.addStat(stat);
break;
default:
pending.addStat(stat);
}
}
return new PendingStats(cfs.keyspace.getName(), cfs.name, pending.build(), finalized.build(), failed.build());
}
use of org.apache.cassandra.schema.TableId in project cassandra by apache.
the class StorageProxy method mutateWithTriggers.
@SuppressWarnings("unchecked")
public static void mutateWithTriggers(List<? extends IMutation> mutations, ConsistencyLevel consistencyLevel, boolean mutateAtomically, long queryStartNanoTime) throws WriteTimeoutException, WriteFailureException, UnavailableException, OverloadedException, InvalidRequestException {
if (DatabaseDescriptor.getPartitionDenylistEnabled() && DatabaseDescriptor.getDenylistWritesEnabled()) {
for (final IMutation mutation : mutations) {
for (final TableId tid : mutation.getTableIds()) {
if (!partitionDenylist.isKeyPermitted(tid, mutation.key().getKey())) {
denylistMetrics.incrementWritesRejected();
// While Schema.instance.getTableMetadata() can return a null value, in this case the isKeyPermitted
// call above ensures that we cannot have a null associated tid at this point.
final TableMetadata tmd = Schema.instance.getTableMetadata(tid);
throw new InvalidRequestException(String.format("Unable to write to denylisted partition [0x%s] in %s/%s", mutation.key().toString(), tmd.keyspace, tmd.name));
}
}
}
}
Collection<Mutation> augmented = TriggerExecutor.instance.execute(mutations);
boolean updatesView = Keyspace.open(mutations.iterator().next().getKeyspaceName()).viewManager.updatesAffectView(mutations, true);
long size = IMutation.dataSize(mutations);
writeMetrics.mutationSize.update(size);
writeMetricsForLevel(consistencyLevel).mutationSize.update(size);
if (augmented != null)
mutateAtomically(augmented, consistencyLevel, updatesView, queryStartNanoTime);
else {
if (mutateAtomically || updatesView)
mutateAtomically((Collection<Mutation>) mutations, consistencyLevel, updatesView, queryStartNanoTime);
else
mutate(mutations, consistencyLevel, queryStartNanoTime);
}
}
use of org.apache.cassandra.schema.TableId in project cassandra by apache.
the class ActiveRepairService method prepareForRepair.
public UUID prepareForRepair(UUID parentRepairSession, InetAddressAndPort coordinator, Set<InetAddressAndPort> endpoints, RepairOption options, boolean isForcedRepair, List<ColumnFamilyStore> columnFamilyStores) {
if (!verifyCompactionsPendingThreshold(parentRepairSession, options.getPreviewKind()))
// failRepair throws exception
failRepair(parentRepairSession, "Rejecting incoming repair, pending compactions above threshold");
long repairedAt = getRepairedAt(options, isForcedRepair);
registerParentRepairSession(parentRepairSession, coordinator, columnFamilyStores, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal(), options.getPreviewKind());
final CountDownLatch prepareLatch = newCountDownLatch(endpoints.size());
final AtomicBoolean status = new AtomicBoolean(true);
final Set<String> failedNodes = synchronizedSet(new HashSet<String>());
final AtomicInteger timeouts = new AtomicInteger(0);
RequestCallback callback = new RequestCallback() {
@Override
public void onResponse(Message msg) {
prepareLatch.decrement();
}
@Override
public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
status.set(false);
failedNodes.add(from.toString());
if (failureReason == RequestFailureReason.TIMEOUT)
timeouts.incrementAndGet();
prepareLatch.decrement();
}
@Override
public boolean invokeOnFailure() {
return true;
}
};
List<TableId> tableIds = new ArrayList<>(columnFamilyStores.size());
for (ColumnFamilyStore cfs : columnFamilyStores) tableIds.add(cfs.metadata.id);
for (InetAddressAndPort neighbour : endpoints) {
if (FailureDetector.instance.isAlive(neighbour)) {
PrepareMessage message = new PrepareMessage(parentRepairSession, tableIds, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal(), options.getPreviewKind());
Message<RepairMessage> msg = out(PREPARE_MSG, message);
MessagingService.instance().sendWithCallback(msg, neighbour, callback);
} else {
// remaining ones go down, we still want to fail so we don't create repair sessions that can't complete
if (isForcedRepair && !options.isIncremental()) {
prepareLatch.decrement();
} else {
// bailout early to avoid potentially waiting for a long time.
failRepair(parentRepairSession, "Endpoint not alive: " + neighbour);
}
}
}
try {
if (!prepareLatch.await(getRpcTimeout(MILLISECONDS), MILLISECONDS) || timeouts.get() > 0)
failRepair(parentRepairSession, "Did not get replies from all endpoints.");
} catch (InterruptedException e) {
failRepair(parentRepairSession, "Interrupted while waiting for prepare repair response.");
}
if (!status.get()) {
failRepair(parentRepairSession, "Got negative replies from endpoints " + failedNodes);
}
return parentRepairSession;
}
Aggregations