use of org.apache.cassandra.db.Keyspace in project cassandra by apache.
the class OnInstanceRepair method invokeRepair.
private static void invokeRepair(String keyspaceName, boolean repairPaxos, boolean repairOnlyPaxos, boolean primaryRangeOnly, boolean force, Runnable listener) {
Keyspace keyspace = Keyspace.open(keyspaceName);
TokenMetadata metadata = StorageService.instance.getTokenMetadata().cloneOnlyTokenMap();
invokeRepair(keyspaceName, repairPaxos, repairOnlyPaxos, () -> primaryRangeOnly ? Collections.singletonList(metadata.getPrimaryRangeFor(currentToken())) : keyspace.getReplicationStrategy().getAddressReplicas(metadata).get(getBroadcastAddressAndPort()).asList(Replica::range), primaryRangeOnly, force, listener);
}
use of org.apache.cassandra.db.Keyspace in project cassandra by apache.
the class ViewFiltering1Test method testViewFiltering.
public void testViewFiltering(boolean flush) throws Throwable {
// CASSANDRA-13547: able to shadow entire view row if base column used in filter condition is modified
createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a))");
String mv1 = createView("CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s " + "WHERE a IS NOT NULL AND b IS NOT NULL and c = 1 PRIMARY KEY (a, b)");
String mv2 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c, d FROM %s " + "WHERE a IS NOT NULL AND b IS NOT NULL and c = 1 and d = 1 PRIMARY KEY (a, b)");
String mv3 = createView("CREATE MATERIALIZED VIEW %s AS SELECT a, b, c, d FROM %%s " + "WHERE a IS NOT NULL AND b IS NOT NULL PRIMARY KEY (a, b)");
String mv4 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c FROM %s " + "WHERE a IS NOT NULL AND b IS NOT NULL and c = 1 PRIMARY KEY (a, b)");
String mv5 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c FROM %s " + "WHERE a IS NOT NULL and d = 1 PRIMARY KEY (a, d)");
String mv6 = createView("CREATE MATERIALIZED VIEW %s AS SELECT c FROM %s " + "WHERE a = 1 and d IS NOT NULL PRIMARY KEY (a, d)");
Keyspace ks = Keyspace.open(keyspace());
ks.getColumnFamilyStore(mv1).disableAutoCompaction();
ks.getColumnFamilyStore(mv2).disableAutoCompaction();
ks.getColumnFamilyStore(mv3).disableAutoCompaction();
ks.getColumnFamilyStore(mv4).disableAutoCompaction();
ks.getColumnFamilyStore(mv5).disableAutoCompaction();
ks.getColumnFamilyStore(mv6).disableAutoCompaction();
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?) using timestamp 0", 1, 1, 1, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
// views should be updated.
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
updateView("UPDATE %s using timestamp 1 set c = ? WHERE a=?", 0, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowCount(execute("SELECT * FROM " + mv1), 0);
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 0, 1));
assertRowCount(execute("SELECT * FROM " + mv4), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 0));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 0));
updateView("UPDATE %s using timestamp 2 set c = ? WHERE a=?", 1, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
// row should be back in views.
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
updateView("UPDATE %s using timestamp 3 set d = ? WHERE a=?", 0, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 0));
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 0));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
assertRowCount(execute("SELECT * FROM " + mv5), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 0, 1));
updateView("UPDATE %s using timestamp 4 set c = ? WHERE a=?", 0, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowCount(execute("SELECT * FROM " + mv1), 0);
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 0, 0));
assertRowCount(execute("SELECT * FROM " + mv4), 0);
assertRowCount(execute("SELECT * FROM " + mv5), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 0, 0));
updateView("UPDATE %s using timestamp 5 set d = ? WHERE a=?", 1, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
// should not update as c=0
assertRowCount(execute("SELECT * FROM " + mv1), 0);
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 0, 1));
assertRowCount(execute("SELECT * FROM " + mv4), 0);
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 0));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 0));
updateView("UPDATE %s using timestamp 6 set c = ? WHERE a=?", 1, 1);
// row should be back in views.
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
updateView("UPDATE %s using timestamp 7 set b = ? WHERE a=?", 2, 1);
if (flush) {
FBUtilities.waitOnFutures(ks.flush());
for (String view : getViews()) ks.getColumnFamilyStore(view).forceMajorCompaction();
}
// row should be back in views.
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 2, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 2, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 2, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 2, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
updateView("DELETE b, c FROM %s using timestamp 6 WHERE a=?", 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT * FROM %s"), row(1, 2, null, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 2, null, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, null));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, null));
updateView("DELETE FROM %s using timestamp 8 where a=?", 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowCount(execute("SELECT * FROM " + mv1), 0);
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowCount(execute("SELECT * FROM " + mv3), 0);
assertRowCount(execute("SELECT * FROM " + mv4), 0);
assertRowCount(execute("SELECT * FROM " + mv5), 0);
assertRowCount(execute("SELECT * FROM " + mv6), 0);
// upsert
updateView("UPDATE %s using timestamp 9 set b = ?,c = ? where a=?", 1, 1, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, null));
assertRows(execute("SELECT * FROM " + mv2));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, null));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
assertRows(execute("SELECT * FROM " + mv5));
assertRows(execute("SELECT * FROM " + mv6));
updateView("DELETE FROM %s using timestamp 10 where a=?", 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowCount(execute("SELECT * FROM " + mv1), 0);
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowCount(execute("SELECT * FROM " + mv3), 0);
assertRowCount(execute("SELECT * FROM " + mv4), 0);
assertRowCount(execute("SELECT * FROM " + mv5), 0);
assertRowCount(execute("SELECT * FROM " + mv6), 0);
execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?) using timestamp 11", 1, 1, 1, 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
// row should be back in views.
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv5), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv6), row(1, 1, 1));
updateView("DELETE FROM %s using timestamp 12 where a=?", 1);
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRowCount(execute("SELECT * FROM " + mv1), 0);
assertRowCount(execute("SELECT * FROM " + mv2), 0);
assertRowCount(execute("SELECT * FROM " + mv3), 0);
assertRowCount(execute("SELECT * FROM " + mv4), 0);
assertRowCount(execute("SELECT * FROM " + mv5), 0);
assertRowCount(execute("SELECT * FROM " + mv6), 0);
dropView(mv1);
dropView(mv2);
dropView(mv3);
dropView(mv4);
dropView(mv5);
dropView(mv6);
dropTable("DROP TABLE %s");
}
use of org.apache.cassandra.db.Keyspace in project cassandra by apache.
the class ViewFiltering1Test method testMVFilteringWithComplexColumn.
// TODO will revise the non-pk filter condition in MV, see CASSANDRA-11500
@Ignore
@Test
public void testMVFilteringWithComplexColumn() throws Throwable {
createTable("CREATE TABLE %s (a int, b int, c int, l list<int>, s set<int>, m map<int,int>, PRIMARY KEY (a, b))");
String mv1 = createView("CREATE MATERIALIZED VIEW %s AS SELECT a,b,c FROM %%s " + "WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL AND l contains (1) " + "AND s contains (1) AND m contains key (1) " + "PRIMARY KEY (a, b, c)");
String mv2 = createView("CREATE MATERIALIZED VIEW %s AS SELECT a,b FROM %%s " + "WHERE a IS NOT NULL and b IS NOT NULL AND l contains (1) " + "PRIMARY KEY (a, b)");
String mv3 = createView("CREATE MATERIALIZED VIEW %s AS SELECT a,b FROM %%s " + "WHERE a IS NOT NULL AND b IS NOT NULL AND s contains (1) " + "PRIMARY KEY (a, b)");
String mv4 = createView("CREATE MATERIALIZED VIEW %s AS SELECT a,b FROM %%s " + "WHERE a IS NOT NULL AND b IS NOT NULL AND m contains key (1) " + "PRIMARY KEY (a, b)");
// not able to drop base column filtered in view
assertInvalidMessage("Cannot drop column l, depended on by materialized views", "ALTER TABLE %s DROP l");
assertInvalidMessage("Cannot drop column s, depended on by materialized views", "ALTER TABLE %S DROP s");
assertInvalidMessage("Cannot drop column m, depended on by materialized views", "ALTER TABLE %s DROP m");
Keyspace ks = Keyspace.open(keyspace());
ks.getColumnFamilyStore(mv1).disableAutoCompaction();
ks.getColumnFamilyStore(mv2).disableAutoCompaction();
ks.getColumnFamilyStore(mv3).disableAutoCompaction();
ks.getColumnFamilyStore(mv4).disableAutoCompaction();
execute("INSERT INTO %s (a, b, c, l, s, m) VALUES (?, ?, ?, ?, ?, ?) ", 1, 1, 1, list(1, 1, 2), set(1, 2), map(1, 1, 2, 2));
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2), row(1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1));
execute("UPDATE %s SET l=l-[1] WHERE a = 1 AND b = 1");
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1));
execute("UPDATE %s SET s=s-{2}, m=m-{2} WHERE a = 1 AND b = 1");
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT a,b,c FROM %s"), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4), row(1, 1));
execute("UPDATE %s SET m=m-{1} WHERE a = 1 AND b = 1");
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT a,b,c FROM %s"), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4));
// filter conditions result not changed
execute("UPDATE %s SET l=l+[2], s=s-{0}, m=m+{3:3} WHERE a = 1 AND b = 1");
FBUtilities.waitOnFutures(ks.flush());
assertRowsIgnoringOrder(execute("SELECT a,b,c FROM %s"), row(1, 1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv2));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv3), row(1, 1));
assertRowsIgnoringOrder(execute("SELECT * FROM " + mv4));
}
use of org.apache.cassandra.db.Keyspace in project cassandra by apache.
the class ViewComplexDeletionsPartialTest method testPartialDeleteUnselectedColumn.
private void testPartialDeleteUnselectedColumn(boolean flush) throws Throwable {
createTable("CREATE TABLE %s (k int, c int, a int, b int, PRIMARY KEY (k, c))");
createView("CREATE MATERIALIZED VIEW %s AS " + "SELECT k,c FROM %s WHERE k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (k,c)");
Keyspace ks = Keyspace.open(keyspace());
ks.getColumnFamilyStore(currentView()).disableAutoCompaction();
updateView("UPDATE %s USING TIMESTAMP 10 SET b=1 WHERE k=1 AND c=1");
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRows(execute("SELECT * from %s"), row(1, 1, null, 1));
assertRows(executeView("SELECT * FROM %s"), row(1, 1));
updateView("DELETE b FROM %s USING TIMESTAMP 11 WHERE k=1 AND c=1");
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertEmpty(execute("SELECT * from %s"));
assertEmpty(executeView("SELECT * FROM %s"));
updateView("UPDATE %s USING TIMESTAMP 1 SET a=1 WHERE k=1 AND c=1");
if (flush)
FBUtilities.waitOnFutures(ks.flush());
assertRows(execute("SELECT * from %s"), row(1, 1, 1, null));
assertRows(executeView("SELECT * FROM %s"), row(1, 1));
execute("truncate %s;");
// removal generated by unselected column should not shadow PK update with smaller timestamp
updateViewWithFlush("UPDATE %s USING TIMESTAMP 18 SET a=1 WHERE k=1 AND c=1", flush);
assertRows(execute("SELECT * from %s"), row(1, 1, 1, null));
assertRows(executeView("SELECT * FROM %s"), row(1, 1));
updateViewWithFlush("UPDATE %s USING TIMESTAMP 20 SET a=null WHERE k=1 AND c=1", flush);
assertRows(execute("SELECT * from %s"));
assertRows(executeView("SELECT * FROM %s"));
updateViewWithFlush("INSERT INTO %s(k,c) VALUES(1,1) USING TIMESTAMP 15", flush);
assertRows(execute("SELECT * from %s"), row(1, 1, null, null));
assertRows(executeView("SELECT * FROM %s"), row(1, 1));
}
use of org.apache.cassandra.db.Keyspace in project cassandra by apache.
the class ViewComplexLivenessLimitTest method testExpiredLivenessLimit.
private void testExpiredLivenessLimit(boolean flush) throws Throwable {
createTable("CREATE TABLE %s (k int PRIMARY KEY, a int, b int);");
Keyspace ks = Keyspace.open(keyspace());
String mv1 = createView("CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s " + "WHERE k IS NOT NULL AND a IS NOT NULL PRIMARY KEY (k, a)");
String mv2 = createView("CREATE MATERIALIZED VIEW %s AS SELECT * FROM %s " + "WHERE k IS NOT NULL AND a IS NOT NULL PRIMARY KEY (a, k)");
ks.getColumnFamilyStore(mv1).disableAutoCompaction();
ks.getColumnFamilyStore(mv2).disableAutoCompaction();
for (int i = 1; i <= 100; i++) updateView("INSERT INTO %s(k, a, b) VALUES (?, ?, ?);", i, i, i);
for (int i = 1; i <= 100; i++) {
if (i % 50 == 0)
continue;
// create expired liveness
updateView("DELETE a FROM %s WHERE k = ?;", i);
}
if (flush) {
ks.getColumnFamilyStore(mv1).forceBlockingFlush();
ks.getColumnFamilyStore(mv2).forceBlockingFlush();
}
for (String view : Arrays.asList(mv1, mv2)) {
// paging
assertEquals(1, executeNetWithPaging(String.format("SELECT k,a,b FROM %s limit 1", view), 1).all().size());
assertEquals(2, executeNetWithPaging(String.format("SELECT k,a,b FROM %s limit 2", view), 1).all().size());
assertEquals(2, executeNetWithPaging(String.format("SELECT k,a,b FROM %s", view), 1).all().size());
assertRowsNet(executeNetWithPaging(String.format("SELECT k,a,b FROM %s ", view), 1), row(50, 50, 50), row(100, 100, 100));
// limit
assertEquals(1, execute(String.format("SELECT k,a,b FROM %s limit 1", view)).size());
assertRowsIgnoringOrder(execute(String.format("SELECT k,a,b FROM %s limit 2", view)), row(50, 50, 50), row(100, 100, 100));
}
}
Aggregations