private void writeToRegister( String key, int index, String clId, long l, long latencyDep, long curr_deadline2, String string, Session session) { // TODO Auto-generated method stub String cqlStr = "INSERT INTO consistify.registry (KEY, CLID, DEADLINE, INDIC, LATENCYDEP,WAITINGTIME,STATUS, CREATETIME) VALUES ('" + key + "','" + clId + "','" + +curr_deadline2 + "','" + index + " ','" + latencyDep + " ','" + l + " ','" + string + " ','" + (long) System.currentTimeMillis() + "') if not exists"; Statement statement = new SimpleStatement(cqlStr); // System.out.println("****11consistify cqlStr:="+cqlStr); statement.setConsistencyLevel(ConsistencyLevel.ALL); session.execute(statement); // .executeAsync(arg0) }
private void createRegistry(Session session) { String cqlStr = "CREATE TABLE IF NOT EXISTS consistify.registry ( key text, CLID text, DEADLINE text, INDIC text, LATENCYDEP text, WAITINGTIME text, STATUS text, CREATETIME text, PRIMARY KEY(key,CLID,INDIC));"; Statement statement = new SimpleStatement(cqlStr); // System.out.println("****consistify cqlStr:="+cqlStr); statement.setConsistencyLevel(ConsistencyLevel.ALL); session.execute(statement); }
public Statement setConsistencyLevel(Statement statement, String cLevel) { // TODO Auto-generated method stub if (cLevel.equalsIgnoreCase("ALL")) statement.setConsistencyLevel(ConsistencyLevel.ALL); else if (cLevel.equalsIgnoreCase("QUORUM")) statement.setConsistencyLevel(ConsistencyLevel.QUORUM); else if (cLevel.equalsIgnoreCase("ONE")) statement.setConsistencyLevel(ConsistencyLevel.ONE); else if (cLevel.equalsIgnoreCase("TWO")) statement.setConsistencyLevel(ConsistencyLevel.TWO); else if (cLevel.equalsIgnoreCase("ANY")) statement.setConsistencyLevel(ConsistencyLevel.ANY); return statement; }
public void removeregistry(Session session, String key, String cLID, int index) { // TODO Auto-generated method stub String cqlStr = "delete from consistify.registry WHERE KEY =' " + key + "' and CLID = '" + cLID + "' and INDIC = '" + index + "'"; Statement statement = new SimpleStatement(cqlStr); statement.setConsistencyLevel(ConsistencyLevel.QUORUM); ResultSet result = session.execute(statement); }
private void setRegister(String key, int index, String clId, Session session) { // TODO Auto-generated method stub String cqlStr = "update consistify.registry set STATUS = 'ON' WHERE KEY = '" + key + "' and CLID = '" + clId + "' and indic = '" + index + "'"; // System.out.println("****cqlStr:="+cqlStr); Statement statement = new SimpleStatement(cqlStr); statement.setConsistencyLevel(ConsistencyLevel.QUORUM); ResultSet result = session.execute(statement); }
/** * Adds a new statement to this batch. * * @param statement the new statement to add. * @return this batch. * @throws IllegalArgumentException if counter and non-counter operations are mixed. */ public Batch add(Statement statement) { boolean isCounterOp = statement instanceof BuiltStatement && ((BuiltStatement) statement).isCounterOp(); if (this.isCounterOp == null) setCounterOp(isCounterOp); else if (isCounterOp() != isCounterOp) throw new IllegalArgumentException( "Cannot mix counter operations and non-counter operations in a batch statement"); this.statements.add(statement); setDirty(); if (routingKey == null && statement.getRoutingKey() != null) routingKey = statement.getRoutingKey(); return this; }
public static void main(String[] args) { for (int i = 0; i < args.length; ++i) { if ("-endpoint".equals(args[i])) { endpoint = args[++i]; } else if ("-keyspace".equals(args[i])) { keyspace = args[++i]; } else if ("-table".equals(args[i])) { table = args[++i]; } else { System.err.println("ConsistencyTest -endpoint hostname -keyspace keyspace -table table"); } } if (endpoint == null || keyspace == null || table == null) { System.err.println("ConsistencyTest -endpoint hostname -keyspace keyspace -table table"); System.exit(1); } String[] endpoints = endpoint.split(":"); try { cluster = Cluster.builder() .addContactPoints(endpoints) .withRetryPolicy(DefaultRetryPolicy.INSTANCE) .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy())) .build(); session = cluster.connect(keyspace); // work with ONE for both write and read long s1 = System.currentTimeMillis(); Statement insert = QueryBuilder.insertInto(table) .value("user_id", 100) .value("fname", "john") .value("lname", "yamada") .value("number", 100); insert.setConsistencyLevel(ConsistencyLevel.ONE); session.execute(insert); long e1 = System.currentTimeMillis(); System.out.println("write ONE time taken (ms) : " + (e1 - s1)); long s2 = System.currentTimeMillis(); Statement select = QueryBuilder.select().all().from(table).where(QueryBuilder.eq("user_id", 100)); select.setConsistencyLevel(ConsistencyLevel.ONE); results = session.execute(select); for (Row row : results) { System.out.format( "%d %s %s %d\n", row.getInt("user_id"), row.getString("fname"), row.getString("lname"), row.getInt("number")); } long e2 = System.currentTimeMillis(); System.out.println("read ONE time taken (ms) : " + (e2 - s2)); Statement delete = QueryBuilder.delete().from(table).where(QueryBuilder.eq("user_id", 100)); results = session.execute(delete); // work with QUORUM for both write and read long s3 = System.currentTimeMillis(); Statement insert2 = QueryBuilder.insertInto(table) .value("user_id", 200) .value("fname", "john") .value("lname", "yamada") .value("number", 100); insert2.setConsistencyLevel(ConsistencyLevel.QUORUM); session.execute(insert2); long e3 = System.currentTimeMillis(); System.out.println("write QUORUM time taken (ms) : " + (e3 - s3)); long s4 = System.currentTimeMillis(); Statement select2 = QueryBuilder.select().all().from(table).where(QueryBuilder.eq("user_id", 200)); select2.setConsistencyLevel(ConsistencyLevel.QUORUM); results = session.execute(select2); for (Row row : results) { System.out.format( "%d %s %s %d\n", row.getInt("user_id"), row.getString("fname"), row.getString("lname"), row.getInt("number")); } long e4 = System.currentTimeMillis(); System.out.println("read QUORUM time taken (ms) : " + (e4 - s4)); Statement delete2 = QueryBuilder.delete().from(table).where(QueryBuilder.eq("user_id", 200)); results = session.execute(delete2); // Clean up the connection by closing it cluster.close(); } catch (Exception e) { e.printStackTrace(); } }
private Statement configure(Statement statement) { if (StringUtils.isNotBlank(consistency)) { statement.setConsistencyLevel(ConsistencyLevel.valueOf(consistency)); } return statement; }