Search in sources :

Example 1 with TableSnapshot

use of org.apache.cassandra.service.snapshot.TableSnapshot in project cassandra by apache.

the class StorageService method getSnapshotDetails.

public Map<String, TabularData> getSnapshotDetails(Map<String, String> options) {
    Map<String, TabularData> snapshotMap = new HashMap<>();
    for (Keyspace keyspace : Keyspace.all()) {
        for (ColumnFamilyStore cfStore : keyspace.getColumnFamilyStores()) {
            for (Map.Entry<String, TableSnapshot> snapshotDetail : TableSnapshot.filter(cfStore.listSnapshots(), options).entrySet()) {
                TabularDataSupport data = (TabularDataSupport) snapshotMap.get(snapshotDetail.getKey());
                if (data == null) {
                    data = new TabularDataSupport(SnapshotDetailsTabularData.TABULAR_TYPE);
                    snapshotMap.put(snapshotDetail.getKey(), data);
                }
                SnapshotDetailsTabularData.from(snapshotDetail.getValue(), data);
            }
        }
    }
    return snapshotMap;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TraceKeyspace(org.apache.cassandra.tracing.TraceKeyspace) AuthKeyspace(org.apache.cassandra.auth.AuthKeyspace) SystemDistributedKeyspace(org.apache.cassandra.schema.SystemDistributedKeyspace) MigrationManager.evolveSystemKeyspace(org.apache.cassandra.schema.MigrationManager.evolveSystemKeyspace) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot) Collectors.toMap(java.util.stream.Collectors.toMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TabularData(javax.management.openmbean.TabularData)

Example 2 with TableSnapshot

use of org.apache.cassandra.service.snapshot.TableSnapshot in project cassandra by apache.

the class ColumnFamilyStore method snapshotWithoutFlush.

/**
 * @param ephemeral If this flag is set to true, the snapshot will be cleaned during next startup
 */
public TableSnapshot snapshotWithoutFlush(String snapshotName, Predicate<SSTableReader> predicate, boolean ephemeral, DurationSpec ttl, RateLimiter rateLimiter, Instant creationTime) {
    if (ephemeral && ttl != null) {
        throw new IllegalStateException(String.format("can not take ephemeral snapshot (%s) while ttl is specified too", snapshotName));
    }
    if (rateLimiter == null)
        rateLimiter = DatabaseDescriptor.getSnapshotRateLimiter();
    Set<SSTableReader> snapshottedSSTables = new LinkedHashSet<>();
    for (ColumnFamilyStore cfs : concatWithIndexes()) {
        try (RefViewFragment currentView = cfs.selectAndReference(View.select(SSTableSet.CANONICAL, (x) -> predicate == null || predicate.apply(x)))) {
            for (SSTableReader ssTable : currentView.sstables) {
                File snapshotDirectory = Directories.getSnapshotDirectory(ssTable.descriptor, snapshotName);
                // hard links
                ssTable.createLinks(snapshotDirectory.path(), rateLimiter);
                if (logger.isTraceEnabled())
                    logger.trace("Snapshot for {} keyspace data file {} created in {}", keyspace, ssTable.getFilename(), snapshotDirectory);
                snapshottedSSTables.add(ssTable);
            }
        }
    }
    return createSnapshot(snapshotName, ephemeral, ttl, snapshottedSSTables, creationTime);
}
Also used : CachedPartition(org.apache.cassandra.db.partitions.CachedPartition) Sampler(org.apache.cassandra.metrics.Sampler) TableRepairManager(org.apache.cassandra.repair.TableRepairManager) File(org.apache.cassandra.io.util.File) LoggerFactory(org.slf4j.LoggerFactory) CommitLog(org.apache.cassandra.db.commitlog.CommitLog) TimeoutException(java.util.concurrent.TimeoutException) CommitLogPosition(org.apache.cassandra.db.commitlog.CommitLogPosition) com.google.common.util.concurrent(com.google.common.util.concurrent) org.apache.cassandra.utils(org.apache.cassandra.utils) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) CountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch) ByteBuffer(java.nio.ByteBuffer) Throwables.merge(org.apache.cassandra.utils.Throwables.merge) SnapshotManifest(org.apache.cassandra.service.snapshot.SnapshotManifest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileOutputStreamPlus(org.apache.cassandra.io.util.FileOutputStreamPlus) CacheService(org.apache.cassandra.service.CacheService) com.google.common.collect(com.google.common.collect) org.apache.cassandra.db.lifecycle(org.apache.cassandra.db.lifecycle) FSWriteError(org.apache.cassandra.io.FSWriteError) TableViews(org.apache.cassandra.db.view.TableViews) org.apache.cassandra.io.sstable.format(org.apache.cassandra.io.sstable.format) TombstoneOption(org.apache.cassandra.schema.CompactionParams.TombstoneOption) NONE(org.apache.cassandra.db.commitlog.CommitLogPosition.NONE) Throwables.maybeFail(org.apache.cassandra.utils.Throwables.maybeFail) Instant(java.time.Instant) org.apache.cassandra.dht(org.apache.cassandra.dht) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) CommitLog.instance(org.apache.cassandra.db.commitlog.CommitLog.instance) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) AsyncPromise(org.apache.cassandra.utils.concurrent.AsyncPromise) org.apache.cassandra.cache(org.apache.cassandra.cache) Future(org.apache.cassandra.utils.concurrent.Future) FileUtils(org.apache.cassandra.io.util.FileUtils) org.apache.cassandra.concurrent(org.apache.cassandra.concurrent) DataLimits(org.apache.cassandra.db.filter.DataLimits) Pattern(java.util.regex.Pattern) org.apache.cassandra.schema(org.apache.cassandra.schema) DatabaseDescriptor.getFlushWriters(org.apache.cassandra.config.DatabaseDescriptor.getFlushWriters) org.apache.cassandra.config(org.apache.cassandra.config) java.util(java.util) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) PendingStat(org.apache.cassandra.repair.consistent.admin.PendingStat) CassandraStreamManager(org.apache.cassandra.db.streaming.CassandraStreamManager) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) Global.currentTimeMillis(org.apache.cassandra.utils.Clock.Global.currentTimeMillis) Range(org.apache.cassandra.dht.Range) Callable(java.util.concurrent.Callable) Constructor(java.lang.reflect.Constructor) AtomicReference(java.util.concurrent.atomic.AtomicReference) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Promise(org.apache.cassandra.utils.concurrent.Promise) SSTableMultiWriter(org.apache.cassandra.io.sstable.SSTableMultiWriter) TableMetrics(org.apache.cassandra.metrics.TableMetrics) CountDownLatch.newCountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch.newCountDownLatch) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Component(org.apache.cassandra.io.sstable.Component) UpdateTransaction(org.apache.cassandra.index.transactions.UpdateTransaction) Descriptor(org.apache.cassandra.io.sstable.Descriptor) MetadataCollector(org.apache.cassandra.io.sstable.metadata.MetadataCollector) Refs(org.apache.cassandra.utils.concurrent.Refs) CleanupSummary(org.apache.cassandra.repair.consistent.admin.CleanupSummary) ExecutorService(java.util.concurrent.ExecutorService) Throwables.propagate(com.google.common.base.Throwables.propagate) PrintStream(java.io.PrintStream) Logger(org.slf4j.Logger) Files(java.nio.file.Files) com.google.common.base(com.google.common.base) SecondaryIndexManager(org.apache.cassandra.index.SecondaryIndexManager) MemtableAllocator(org.apache.cassandra.utils.memory.MemtableAllocator) javax.management(javax.management) CassandraTableRepairManager(org.apache.cassandra.db.repair.CassandraTableRepairManager) Throwables(com.google.common.base.Throwables) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) javax.management.openmbean(javax.management.openmbean) SamplerType(org.apache.cassandra.metrics.Sampler.SamplerType) org.apache.cassandra.db.compaction(org.apache.cassandra.db.compaction) TableStreamManager(org.apache.cassandra.streaming.TableStreamManager) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CellPath(org.apache.cassandra.db.rows.CellPath) FSReadError(org.apache.cassandra.io.FSReadError) CassandraIndex(org.apache.cassandra.index.internal.CassandraIndex) Sample(org.apache.cassandra.metrics.Sampler.Sample) Global.executorFactory(org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ClusteringIndexFilter(org.apache.cassandra.db.filter.ClusteringIndexFilter) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot) StartupException(org.apache.cassandra.exceptions.StartupException) File(org.apache.cassandra.io.util.File)

Example 3 with TableSnapshot

use of org.apache.cassandra.service.snapshot.TableSnapshot in project cassandra by apache.

the class Directories method listSnapshots.

public Map<String, TableSnapshot> listSnapshots() {
    Map<String, Set<File>> snapshotDirsByTag = listSnapshotDirsByTag();
    Map<String, TableSnapshot> snapshots = Maps.newHashMapWithExpectedSize(snapshotDirsByTag.size());
    for (Map.Entry<String, Set<File>> entry : snapshotDirsByTag.entrySet()) {
        String tag = entry.getKey();
        Set<File> snapshotDirs = entry.getValue();
        SnapshotManifest manifest = maybeLoadManifest(metadata.keyspace, metadata.name, tag, snapshotDirs);
        snapshots.put(tag, buildSnapshot(tag, manifest, snapshotDirs));
    }
    return snapshots;
}
Also used : SnapshotManifest(org.apache.cassandra.service.snapshot.SnapshotManifest) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot) ImmutableMap(com.google.common.collect.ImmutableMap) File(org.apache.cassandra.io.util.File)

Example 4 with TableSnapshot

use of org.apache.cassandra.service.snapshot.TableSnapshot in project cassandra by apache.

the class Directories method buildSnapshot.

protected TableSnapshot buildSnapshot(String tag, SnapshotManifest manifest, Set<File> snapshotDirs) {
    Instant createdAt = manifest == null ? null : manifest.createdAt;
    Instant expiresAt = manifest == null ? null : manifest.expiresAt;
    return new TableSnapshot(metadata.keyspace, metadata.name, tag, createdAt, expiresAt, snapshotDirs, this::getTrueAllocatedSizeIn);
}
Also used : Instant(java.time.Instant) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot)

Example 5 with TableSnapshot

use of org.apache.cassandra.service.snapshot.TableSnapshot in project cassandra by apache.

the class DirectoriesTest method testSecondaryIndexDirectories.

@Test
public void testSecondaryIndexDirectories() {
    TableMetadata.Builder builder = TableMetadata.builder(KS, "cf").addPartitionKeyColumn("thekey", UTF8Type.instance).addClusteringColumn("col", UTF8Type.instance);
    ColumnIdentifier col = ColumnIdentifier.getInterned("col", true);
    IndexMetadata indexDef = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(col, IndexTarget.Type.VALUES)), "idx", IndexMetadata.Kind.KEYS, Collections.emptyMap());
    builder.indexes(Indexes.of(indexDef));
    TableMetadata PARENT_CFM = builder.build();
    TableMetadata INDEX_CFM = CassandraIndex.indexCfsMetadata(PARENT_CFM, indexDef);
    Directories parentDirectories = new Directories(PARENT_CFM, toDataDirectories(tempDataDir));
    Directories indexDirectories = new Directories(INDEX_CFM, toDataDirectories(tempDataDir));
    // secondary index has its own directory
    for (File dir : indexDirectories.getCFDirectories()) {
        assertEquals(cfDir(INDEX_CFM), dir);
    }
    Descriptor parentDesc = new Descriptor(parentDirectories.getDirectoryForNewSSTables(), KS, PARENT_CFM.name, 0, SSTableFormat.Type.BIG);
    Descriptor indexDesc = new Descriptor(indexDirectories.getDirectoryForNewSSTables(), KS, INDEX_CFM.name, 0, SSTableFormat.Type.BIG);
    // snapshot dir should be created under its parent's
    File parentSnapshotDirectory = Directories.getSnapshotDirectory(parentDesc, "test");
    File indexSnapshotDirectory = Directories.getSnapshotDirectory(indexDesc, "test");
    assertEquals(parentSnapshotDirectory, indexSnapshotDirectory.parent());
    // check if snapshot directory exists
    parentSnapshotDirectory.tryCreateDirectories();
    assertTrue(parentDirectories.snapshotExists("test"));
    assertTrue(indexDirectories.snapshotExists("test"));
    // check true snapshot size
    Descriptor parentSnapshot = new Descriptor(parentSnapshotDirectory, KS, PARENT_CFM.name, 0, SSTableFormat.Type.BIG);
    createFile(parentSnapshot.filenameFor(Component.DATA), 30);
    Descriptor indexSnapshot = new Descriptor(indexSnapshotDirectory, KS, INDEX_CFM.name, 0, SSTableFormat.Type.BIG);
    createFile(indexSnapshot.filenameFor(Component.DATA), 40);
    assertEquals(30, parentDirectories.trueSnapshotsSize());
    assertEquals(40, indexDirectories.trueSnapshotsSize());
    // check snapshot details
    Map<String, TableSnapshot> parentSnapshotDetail = parentDirectories.listSnapshots();
    assertTrue(parentSnapshotDetail.containsKey("test"));
    assertEquals(30L, parentSnapshotDetail.get("test").computeTrueSizeBytes());
    Map<String, TableSnapshot> indexSnapshotDetail = indexDirectories.listSnapshots();
    assertTrue(indexSnapshotDetail.containsKey("test"));
    assertEquals(40L, indexSnapshotDetail.get("test").computeTrueSizeBytes());
    // check backup directory
    File parentBackupDirectory = Directories.getBackupsDirectory(parentDesc);
    File indexBackupDirectory = Directories.getBackupsDirectory(indexDesc);
    assertEquals(parentBackupDirectory, indexBackupDirectory.parent());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) DataDirectories(org.apache.cassandra.db.Directories.DataDirectories) IndexTarget(org.apache.cassandra.cql3.statements.schema.IndexTarget) TableSnapshot(org.apache.cassandra.service.snapshot.TableSnapshot) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) File(org.apache.cassandra.io.util.File) Test(org.junit.Test)

Aggregations

TableSnapshot (org.apache.cassandra.service.snapshot.TableSnapshot)9 File (org.apache.cassandra.io.util.File)4 Instant (java.time.Instant)3 Descriptor (org.apache.cassandra.io.sstable.Descriptor)3 SnapshotManifest (org.apache.cassandra.service.snapshot.SnapshotManifest)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 com.google.common.base (com.google.common.base)2 Throwables (com.google.common.base.Throwables)2 Throwables.propagate (com.google.common.base.Throwables.propagate)2 com.google.common.collect (com.google.common.collect)2 com.google.common.util.concurrent (com.google.common.util.concurrent)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ByteBuffer (java.nio.ByteBuffer)2 Files (java.nio.file.Files)2 java.util (java.util)2 Objects (java.util.Objects)2 Callable (java.util.concurrent.Callable)2