void add(Type type, SSTable table) { if (!addRecord(makeRecord(type, table))) throw new IllegalStateException(); }
public void addAll(Type type, Iterable<SSTableReader> toBulkAdd) { for (LogRecord record : makeRecords(type, toBulkAdd)) if (!addRecord(record)) throw new IllegalStateException(); }
void classifyFiles(LogFile txnFile) Map<LogRecord, Set<File>> oldFiles = txnFile.getFilesOfType(folder, files.navigableKeySet(), LogRecord.Type.REMOVE); Map<LogRecord, Set<File>> newFiles = txnFile.getFilesOfType(folder, files.navigableKeySet(), LogRecord.Type.ADD); if (txnFile.completed()) if (!txnFile.exists()) return; if (txnFile.completed()) ? "\t-" : String.join("\n", files.keySet().stream().map(f -> String.format("\t%s", f)).collect(Collectors.toList())), txnFile.toString(true));
Throwable removeUnfinishedLeftovers(Throwable accumulate) { try { // we sync the parent directories before content deletion to ensure // any previously deleted files (see SSTableTider) are not // incorrectly picked up by record.getExistingFiles() in // deleteRecordFiles(), see CASSANDRA-12261 Throwables.maybeFail(syncDirectory(accumulate)); deleteFilesForRecordsOfType(committed() ? Type.REMOVE : Type.ADD); // we sync the parent directories between contents and log deletion // to ensure there is a happens before edge between them Throwables.maybeFail(syncDirectory(accumulate)); accumulate = replicas.delete(accumulate); } catch (Throwable t) { accumulate = merge(accumulate, t); } return accumulate; }
public void run() { if (logger.isTraceEnabled()) logger.trace("Removing files for transaction log {}", data); if (!data.completed()) { // this happens if we forget to close a txn and the garbage collector closes it for us logger.error("Transaction log {} indicates txn was not completed, trying to abort it now", data); Throwable err = Throwables.perform((Throwable)null, data::abort); if (err != null) logger.error("Failed to abort transaction log {}", data, err); } Throwable err = data.removeUnfinishedLeftovers(null); if (err != null) { logger.info("Failed deleting files for transaction log {}, we'll retry after GC and on on server restart", data, err); failedDeletions.add(this); } else { if (logger.isTraceEnabled()) logger.trace("Closing transaction log {}", data); data.close(); } } }
LogTransaction(OperationType opType, Tracker tracker) { this.tracker = tracker; this.txnFile = new LogFile(opType, UUIDGen.getTimeUUID()); this.selfRef = new Ref<>(this, new TransactionTidier(txnFile)); if (logger.isTraceEnabled()) logger.trace("Created transaction logs with id {}", txnFile.id()); }
public String toString(boolean showContents) { StringBuilder str = new StringBuilder(); str.append('['); str.append(getFileName()); str.append(" in "); str.append(replicas.getDirectories()); str.append(']'); if (showContents) { str.append(System.lineSeparator()); str.append("Files and contents follow:"); str.append(System.lineSeparator()); replicas.printContentsWithAnyErrors(str); } return str.toString(); }
static LogFile make(String fileName, List<File> logReplicas) { Matcher matcher = LogFile.FILE_REGEX.matcher(fileName); boolean matched = matcher.matches(); assert matched && matcher.groupCount() == 3; // For now we don't need this but it is there in case we need to change // file format later on, the version is the sstable version as defined in BigFormat //String version = matcher.group(1); OperationType operationType = OperationType.fromFileName(matcher.group(2)); UUID id = UUID.fromString(matcher.group(3)); return new LogFile(operationType, id, logReplicas); }
private void setTemporary(LogFile txnFile, Collection<Set<File>> oldFiles, Collection<Set<File>> newFiles) { Collection<Set<File>> temporary = txnFile.committed() ? oldFiles : newFiles; temporary.stream() .flatMap(Set::stream) .forEach((f) -> this.files.put(f, FileType.TEMPORARY)); } }
void add(LogRecord record) { if (!addRecord(record)) throw new IllegalStateException(); }
void classifyFiles(LogFile txnFile) Map<LogRecord, Set<File>> oldFiles = txnFile.getFilesOfType(folder, files.navigableKeySet(), LogRecord.Type.REMOVE); Map<LogRecord, Set<File>> newFiles = txnFile.getFilesOfType(folder, files.navigableKeySet(), LogRecord.Type.ADD); if (txnFile.completed()) if (!txnFile.exists()) return; if (txnFile.completed()) ? "\t-" : String.join("\n", files.keySet().stream().map(f -> String.format("\t%s", f)).collect(Collectors.toList())), txnFile.toString(true));
Throwable removeUnfinishedLeftovers(Throwable accumulate) { try { // we sync the parent directories before content deletion to ensure // any previously deleted files (see SSTableTider) are not // incorrectly picked up by record.getExistingFiles() in // deleteRecordFiles(), see CASSANDRA-12261 Throwables.maybeFail(syncDirectory(accumulate)); deleteFilesForRecordsOfType(committed() ? Type.REMOVE : Type.ADD); // we sync the parent directories between contents and log deletion // to ensure there is a happens before edge between them Throwables.maybeFail(syncDirectory(accumulate)); accumulate = replicas.delete(accumulate); } catch (Throwable t) { accumulate = merge(accumulate, t); } return accumulate; }
public void run() { if (logger.isTraceEnabled()) logger.trace("Removing files for transaction log {}", data); if (!data.completed()) { // this happens if we forget to close a txn and the garbage collector closes it for us logger.error("Transaction log {} indicates txn was not completed, trying to abort it now", data); Throwable err = Throwables.perform((Throwable)null, data::abort); if (err != null) logger.error("Failed to abort transaction log {}", data, err); } Throwable err = data.removeUnfinishedLeftovers(null); if (err != null) { logger.info("Failed deleting files for transaction log {}, we'll retry after GC and on on server restart", data, err); failedDeletions.add(this); } else { if (logger.isTraceEnabled()) logger.trace("Closing transaction log {}", data); data.close(); } } }
LogTransaction(OperationType opType, Tracker tracker) { this.tracker = tracker; this.txnFile = new LogFile(opType, UUIDGen.getTimeUUID()); this.selfRef = new Ref<>(this, new TransactionTidier(txnFile)); if (logger.isTraceEnabled()) logger.trace("Created transaction logs with id {}", txnFile.id()); }
public String toString(boolean showContents) { StringBuilder str = new StringBuilder(); str.append('['); str.append(getFileName()); str.append(" in "); str.append(replicas.getDirectories()); str.append(']'); if (showContents) { str.append(System.lineSeparator()); str.append("Files and contents follow:"); str.append(System.lineSeparator()); replicas.printContentsWithAnyErrors(str); } return str.toString(); }
public void addAll(Type type, Iterable<SSTableReader> toBulkAdd) { for (LogRecord record : makeRecords(type, toBulkAdd).values()) if (!addRecord(record)) throw new IllegalStateException(); }
static LogFile make(String fileName, List<File> logReplicas) { Matcher matcher = LogFile.FILE_REGEX.matcher(fileName); boolean matched = matcher.matches(); assert matched && matcher.groupCount() == 3; // For now we don't need this but it is there in case we need to change // file format later on, the version is the sstable version as defined in BigFormat //String version = matcher.group(1); OperationType operationType = OperationType.fromFileName(matcher.group(2)); UUID id = UUID.fromString(matcher.group(3)); return new LogFile(operationType, id, logReplicas); }
private void setTemporary(LogFile txnFile, Collection<Set<File>> oldFiles, Collection<Set<File>> newFiles) { Collection<Set<File>> temporary = txnFile.committed() ? oldFiles : newFiles; temporary.stream() .flatMap(Set::stream) .forEach((f) -> this.files.put(f, FileType.TEMPORARY)); } }