/** * Discovers existing components for the descriptor. Slow: only intended for use outside the critical path. */ public static Set<Component> componentsFor(final Descriptor desc) { try { try { return readTOC(desc); } catch (FileNotFoundException e) { Set<Component> components = discoverComponentsFor(desc); if (components.isEmpty()) return components; // sstable doesn't exist yet if (!components.contains(Component.TOC)) components.add(Component.TOC); appendTOC(desc, components); return components; } } catch (IOException e) { throw new IOError(e); } }
@Override public String toString() { return getClass().getSimpleName() + "(" + "path='" + getFilename() + '\'' + ')'; }
public DecoratedKey decorateKey(ByteBuffer key) { return getPartitioner().decorateKey(key); }
public void run() { if (tracker != null && !tracker.isDummy()) SystemKeyspace.clearSSTableReadMeter(desc.ksname, desc.cfname, desc.generation); try { // If we can't successfully delete the DATA component, set the task to be retried later: see TransactionTidier File datafile = new File(desc.filenameFor(Component.DATA)); if (datafile.exists()) delete(datafile); else if (!wasNew) logger.error("SSTableTidier ran with no existing data file for an sstable that was not new"); // let the remainder be cleaned up by delete SSTable.delete(desc, SSTable.discoverComponentsFor(desc)); } catch (Throwable t) { logger.error("Failed deletion for {}, we'll retry after GC and on server restart", desc); failedDeletions.add(this); return; } if (tracker != null && tracker.cfstore != null && !wasNew) tracker.cfstore.metric.totalDiskSpaceUsed.dec(sizeOnDisk); // release the referent to the parent so that the all transaction files can be released parentRef.release(); }
public boolean accept(File dir, String name) { Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name); Descriptor desc = p == null ? null : p.left; if (desc == null) return false; if (desc.cfname.equals(columnFamily)) existing.add(desc); return false; } });
/** * Registers new custom components. Used by custom compaction strategies. * Adding a component for the second time is a no-op. * Don't remove this - this method is a part of the public API, intended for use by custom compaction strategies. * @param newComponents collection of components to be added */ public synchronized void addComponents(Collection<Component> newComponents) { Collection<Component> componentsToAdd = Collections2.filter(newComponents, Predicates.not(Predicates.in(components))); appendTOC(descriptor, componentsToAdd); components.addAll(componentsToAdd); } }
public static Map<SSTable, LogRecord> make(Type type, Iterable<SSTableReader> tables) { // contains a mapping from sstable absolute path (everything up until the 'Data'/'Index'/etc part of the filename) to the sstable Map<String, SSTable> absolutePaths = new HashMap<>(); for (SSTableReader table : tables) absolutePaths.put(absolutePath(table.descriptor.baseFilename()), table); // maps sstable base file name to the actual files on disk Map<String, List<File>> existingFiles = getExistingFiles(absolutePaths.keySet()); Map<SSTable, LogRecord> records = new HashMap<>(existingFiles.size()); for (Map.Entry<String, List<File>> entry : existingFiles.entrySet()) { List<File> filesOnDisk = entry.getValue(); String baseFileName = entry.getKey(); SSTable sstable = absolutePaths.get(baseFileName); records.put(sstable, make(type, filesOnDisk, sstable.getAllFilePaths().size(), baseFileName)); } return records; }
public void run() { // If we can't successfully delete the DATA component, set the task to be retried later: see above File datafile = new File(desc.filenameFor(Component.DATA)); if (!datafile.delete()) { logger.error("Unable to delete {} (it will be removed on server restart; we'll also retry after GC)", datafile); failedTasks.add(this); return; } // let the remainder be cleaned up by delete SSTable.delete(desc, Sets.difference(components, Collections.singleton(Component.DATA))); if (totalDiskSpaceUsed != null) totalDiskSpaceUsed.dec(bytesOnDisk); }
/** * After failure, attempt to close the index writer and data file before deleting all temp components for the sstable */ public void abort() { assert descriptor.type.isTemporary; if (iwriter == null && dataFile == null) return; if (iwriter != null) iwriter.abort(); if (dataFile!= null) dataFile.abort(); Set<Component> components = SSTable.componentsFor(descriptor); try { if (!components.isEmpty()) SSTable.delete(descriptor, components); } catch (FSWriteError e) { logger.error(String.format("Failed deleting temp components for %s", descriptor), e); throw e; } }
private long getPrimaryIndexLength(SSTable sstable) { File primaryIndex = new File(sstable.getIndexFilename()); return primaryIndex.exists() ? primaryIndex.length() : 0; }
public void run() { if (tracker != null && !tracker.isDummy()) SystemKeyspace.clearSSTableReadMeter(desc.ksname, desc.cfname, desc.generation); try { // If we can't successfully delete the DATA component, set the task to be retried later: see TransactionTidier File datafile = new File(desc.filenameFor(Component.DATA)); if (datafile.exists()) delete(datafile); else if (!wasNew) logger.error("SSTableTidier ran with no existing data file for an sstable that was not new"); // let the remainder be cleaned up by delete SSTable.delete(desc, SSTable.discoverComponentsFor(desc)); } catch (Throwable t) { logger.error("Failed deletion for {}, we'll retry after GC and on server restart", desc); failedDeletions.add(this); return; } if (tracker != null && tracker.cfstore != null && !wasNew) tracker.cfstore.metric.totalDiskSpaceUsed.dec(sizeOnDisk); // release the referent to the parent so that the all transaction files can be released parentRef.release(); }
public boolean accept(File dir, String name) { Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name); Descriptor desc = p == null ? null : p.left; if (desc == null) return false; if (desc.cfname.equals(columnFamily)) existing.add(desc); return false; } });
/** * Registers new custom components. Used by custom compaction strategies. * Adding a component for the second time is a no-op. * Don't remove this - this method is a part of the public API, intended for use by custom compaction strategies. * @param newComponents collection of components to be added */ public synchronized void addComponents(Collection<Component> newComponents) { Collection<Component> componentsToAdd = Collections2.filter(newComponents, Predicates.not(Predicates.in(components))); appendTOC(descriptor, componentsToAdd); components.addAll(componentsToAdd); } }
public static Map<SSTable, LogRecord> make(Type type, Iterable<SSTableReader> tables) { // contains a mapping from sstable absolute path (everything up until the 'Data'/'Index'/etc part of the filename) to the sstable Map<String, SSTable> absolutePaths = new HashMap<>(); for (SSTableReader table : tables) absolutePaths.put(absolutePath(table.descriptor.baseFilename()), table); // maps sstable base file name to the actual files on disk Map<String, List<File>> existingFiles = getExistingFiles(absolutePaths.keySet()); Map<SSTable, LogRecord> records = new HashMap<>(existingFiles.size()); for (Map.Entry<String, List<File>> entry : existingFiles.entrySet()) { List<File> filesOnDisk = entry.getValue(); String baseFileName = entry.getKey(); SSTable sstable = absolutePaths.get(baseFileName); records.put(sstable, make(type, filesOnDisk, sstable.getAllFilePaths().size(), baseFileName)); } return records; }
assert compactionTaskID != null; logger.debug("Going to delete unfinished compaction product {}", desc); SSTable.delete(desc, sstableFiles.getValue()); SystemKeyspace.finishCompaction(compactionTaskID); SSTable.delete(desc, sstableFiles.getValue()); UUID compactionTaskID = unfinishedCompactions.get(desc.generation); if (compactionTaskID != null)
public void cleanup() { List<String> files = readLockfile(lockfile); for (String file : files) { try { Descriptor desc = Descriptor.fromFilename(file, true); SSTable.delete(desc, SSTable.componentsFor(desc)); } catch (Exception e) { JVMStabilityInspector.inspectThrowable(e); logger.warn("failed to delete a potentially stale sstable {}", file); } } }
private long getPrimaryIndexLength(SSTable sstable) { File primaryIndex = new File(sstable.getIndexFilename()); return primaryIndex.exists() ? primaryIndex.length() : 0; }
/** * Discovers existing components for the descriptor. Slow: only intended for use outside the critical path. */ public static Set<Component> componentsFor(final Descriptor desc) { try { try { return readTOC(desc); } catch (FileNotFoundException e) { Set<Component> components = discoverComponentsFor(desc); if (components.isEmpty()) return components; // sstable doesn't exist yet if (!components.contains(Component.TOC)) components.add(Component.TOC); appendTOC(desc, components); return components; } } catch (IOException e) { throw new IOError(e); } }
public void run() { if (tracker != null && !tracker.isDummy()) SystemKeyspace.clearSSTableReadMeter(desc.ksname, desc.cfname, desc.generation); try { // If we can't successfully delete the DATA component, set the task to be retried later: see TransactionTidier File datafile = new File(desc.filenameFor(Component.DATA)); if (datafile.exists()) delete(datafile); else if (!wasNew) logger.error("SSTableTidier ran with no existing data file for an sstable that was not new"); // let the remainder be cleaned up by delete SSTable.delete(desc, SSTable.discoverComponentsFor(desc)); } catch (Throwable t) { logger.error("Failed deletion for {}, we'll retry after GC and on server restart", desc); failedDeletions.add(this); return; } if (tracker != null && tracker.cfstore != null && !wasNew) tracker.cfstore.metric.totalDiskSpaceUsed.dec(sizeOnDisk); // release the referent to the parent so that the all transaction files can be released parentRef.release(); }
public boolean accept(File dir, String name) { Pair<Descriptor, Component> p = SSTable.tryComponentFromFilename(dir, name); Descriptor desc = p == null ? null : p.left; if (desc == null) return false; if (desc.cfname.equals(columnFamily)) existing.add(desc); return false; } });