use of org.apache.cassandra.schema.TableMetadataRef in project cassandra by apache.
the class MockSchema method newCFS.
public static ColumnFamilyStore newCFS(String ksname) {
String cfname = "mockcf" + (id.incrementAndGet());
TableMetadata metadata = newTableMetadata(ksname, cfname);
return new ColumnFamilyStore(ks, cfname, 0, new TableMetadataRef(metadata), new Directories(metadata), false, false, false);
}
use of org.apache.cassandra.schema.TableMetadataRef in project cassandra by apache.
the class CassandraIndex method setMetadata.
private void setMetadata(IndexMetadata indexDef) {
metadata = indexDef;
Pair<ColumnMetadata, IndexTarget.Type> target = TargetParser.parse(baseCfs.metadata(), indexDef);
functions = getFunctions(indexDef, target);
TableMetadataRef tableRef = TableMetadataRef.forOfflineTools(indexCfsMetadata(baseCfs.metadata(), indexDef));
indexCfs = ColumnFamilyStore.createColumnFamilyStore(baseCfs.keyspace, tableRef.name, tableRef, baseCfs.getTracker().loadsstables);
indexedColumn = target.left;
}
use of org.apache.cassandra.schema.TableMetadataRef in project cassandra by apache.
the class KeyCacheCqlTest method test2iKeyCachePathsSaveKeysForDroppedTable.
private void test2iKeyCachePathsSaveKeysForDroppedTable() throws Throwable {
String table = createTable("CREATE TABLE %s (" + commonColumnsDef + "PRIMARY KEY ((part_key_a, part_key_b),clust_key_a,clust_key_b,clust_key_c))");
String indexName = createIndex("CREATE INDEX ON %s (col_int)");
insertData(table, indexName, true);
clearCache();
CacheMetrics metrics = CacheService.instance.keyCache.getMetrics();
long expectedNumberOfRequests = 0;
for (int i = 0; i < 10; i++) {
UntypedResultSet result = execute("SELECT part_key_a FROM %s WHERE col_int = ?", i);
assertEquals(500, result.size());
// Index requests and table requests are both added to the same metric
// We expect 10 requests on the index SSTables and 10 IN requests on the table SSTables + BF false positives
expectedNumberOfRequests += recentBloomFilterFalsePositives() + 20;
}
long hits = metrics.hits.getCount();
long requests = metrics.requests.getCount();
assertEquals(0, hits);
assertEquals(expectedNumberOfRequests, requests);
for (int i = 0; i < 10; i++) {
UntypedResultSet result = execute("SELECT part_key_a FROM %s WHERE col_int = ?", i);
// 100 part-keys * 50 clust-keys
// indexed on part-key % 10 = 10 index partitions
// (50 clust-keys * 100-part-keys / 10 possible index-values) = 500
assertEquals(500, result.size());
// Index requests and table requests are both added to the same metric
// We expect 10 requests on the index SSTables and 10 IN requests on the table SSTables + BF false positives
expectedNumberOfRequests += recentBloomFilterFalsePositives() + 20;
}
metrics = CacheService.instance.keyCache.getMetrics();
hits = metrics.hits.getCount();
requests = metrics.requests.getCount();
assertEquals(200, hits);
assertEquals(expectedNumberOfRequests, requests);
dropTable("DROP TABLE %s");
CacheService.instance.keyCache.submitWrite(Integer.MAX_VALUE).get();
CacheService.instance.keyCache.clear();
Assert.assertEquals(0, CacheService.instance.keyCache.size());
// then load saved
CacheService.instance.keyCache.loadSaved();
Iterator<KeyCacheKey> iter = CacheService.instance.keyCache.keyIterator();
while (iter.hasNext()) {
KeyCacheKey key = iter.next();
TableMetadataRef tableMetadataRef = Schema.instance.getTableMetadataRef(key.tableId);
Assert.assertFalse(tableMetadataRef.keyspace.equals("KEYSPACE_PER_TEST"));
Assert.assertFalse(tableMetadataRef.name.startsWith(table));
}
}
use of org.apache.cassandra.schema.TableMetadataRef in project cassandra by apache.
the class RealTransactionsTest method replaceSSTable.
private SSTableReader replaceSSTable(ColumnFamilyStore cfs, LifecycleTransaction txn, boolean fail) {
List<SSTableReader> newsstables = null;
int nowInSec = FBUtilities.nowInSeconds();
try (CompactionController controller = new CompactionController(cfs, txn.originals(), cfs.gcBefore(FBUtilities.nowInSeconds()))) {
try (SSTableRewriter rewriter = SSTableRewriter.constructKeepingOriginals(txn, false, 1000);
AbstractCompactionStrategy.ScannerList scanners = cfs.getCompactionStrategyManager().getScanners(txn.originals());
CompactionIterator ci = new CompactionIterator(txn.opType(), scanners.scanners, controller, nowInSec, txn.opId())) {
long lastCheckObsoletion = nanoTime();
File directory = txn.originals().iterator().next().descriptor.directory;
Descriptor desc = cfs.newSSTableDescriptor(directory);
TableMetadataRef metadata = Schema.instance.getTableMetadataRef(desc);
rewriter.switchWriter(SSTableWriter.create(metadata, desc, 0, 0, null, false, 0, SerializationHeader.make(cfs.metadata(), txn.originals()), cfs.indexManager.listIndexes(), txn));
while (ci.hasNext()) {
rewriter.append(ci.next());
if (nanoTime() - lastCheckObsoletion > TimeUnit.MINUTES.toNanos(1L)) {
controller.maybeRefreshOverlaps();
lastCheckObsoletion = nanoTime();
}
}
if (!fail)
newsstables = rewriter.finish();
else
rewriter.abort();
}
}
assertTrue(fail || newsstables != null);
if (newsstables != null) {
Assert.assertEquals(1, newsstables.size());
return newsstables.iterator().next();
}
return null;
}
use of org.apache.cassandra.schema.TableMetadataRef in project cassandra by apache.
the class BigTableZeroCopyWriterTest method writeDataTestCycle.
private void writeDataTestCycle(Function<ByteBuffer, DataInputPlus> bufferMapper) {
File dir = store.getDirectories().getDirectoryForNewSSTables();
Descriptor desc = store.newSSTableDescriptor(dir);
TableMetadataRef metadata = Schema.instance.getTableMetadataRef(desc);
LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.STREAM);
Set<Component> componentsToWrite = ImmutableSet.of(Component.DATA, Component.PRIMARY_INDEX, Component.STATS);
BigTableZeroCopyWriter btzcw = new BigTableZeroCopyWriter(desc, metadata, txn, componentsToWrite);
for (Component component : componentsToWrite) {
if (Files.exists(Paths.get(desc.filenameFor(component)))) {
Pair<DataInputPlus, Long> pair = getSSTableComponentData(sstable, component, bufferMapper);
try {
btzcw.writeComponent(component.type, pair.left, pair.right);
} catch (ClosedChannelException e) {
throw new UncheckedIOException(e);
}
}
}
Collection<SSTableReader> readers = btzcw.finish(true);
SSTableReader reader = readers.toArray(new SSTableReader[0])[0];
assertNotEquals(sstable.getFilename(), reader.getFilename());
assertEquals(sstable.estimatedKeys(), reader.estimatedKeys());
assertEquals(sstable.isPendingRepair(), reader.isPendingRepair());
assertRowCount(expectedRowCount);
}
Aggregations