Beispiel #1
0
  public void update(
      String keyspace,
      String string,
      String string2,
      String string3,
      String string4,
      String string5,
      String string6,
      int index,
      long l,
      long latency_update2,
      String cLevel,
      String CLID,
      long tInv,
      Tuple tuple) {
    // TODO Auto-generated method stub
    String cqlStr =
        "update "
            + keyspace
            + "."
            + string
            + " set "
            + string2
            + " = '"
            + string3
            + "' WHERE "
            + string4
            + " = '"
            + string5
            + "'";
    Statement statement = new SimpleStatement(cqlStr);
    String operationtype = "update";
    // System.out.println("***update executed:="+cqlStr);
    // System.out.println("**statement:="+statement.toString());
    scheduleAndQueue(
        operationtype,
        statement,
        tuple.getSession(),
        index,
        l,
        latency_update2,
        cLevel,
        CLID,
        tInv,
        tuple);
    // QueryResult<CqlRows<String,String,Long>> result = cqlQuery.execute();

  }
Beispiel #2
0
  public String read(
      String keyspace,
      String string,
      String string2,
      String string3,
      int index,
      long l,
      long latency_read2,
      String cLevel,
      String CLID,
      long tInv,
      Tuple tuple) {
    // TODO Auto-generated method stub
    String
        cqlStr =
            "SELECT * from "
                + keyspace
                + "."
                + string
                + " WHERE "
                + string2
                + " = '"
                + string3
                + "' ALLOW FILTERING",
        res = null;
    Statement statement = new SimpleStatement(cqlStr);
    String operationtype = "read";
    // System.out.println("***read executed:-"+cqlStr);
    ResultSet results =
        scheduleAndQueue(
            operationtype,
            statement,
            tuple.getSession(),
            index,
            l,
            latency_read2,
            cLevel,
            CLID,
            tInv,
            tuple);
    if (results != null) {
      for (Row aRow : results) {
        res = aRow.getString("price");
      }
    }

    return res;
  }
Beispiel #3
0
 public void insert(
     String keyspace,
     String string,
     String string2,
     String string3,
     String string4,
     String string5,
     String string6,
     String string7,
     String string8,
     String string9,
     String string10,
     String string11,
     String string12,
     int index,
     long l,
     long latency_insert2,
     String cLevel,
     String CLID,
     long tInv,
     Tuple tuple) {
   // TODO Auto-generated method stub
   UUID idOne = UUID.randomUUID();
   // System.out.println("string8 value:---"+string8);
   // String cqlStr = "INSERT INTO " + keyspace + "." + string +"(key,"+ string3 +","+ string5
   // +","+ string7 +","+ string9 +","+ string11 + ") VALUES ('"+ string2 + "','"+ string4 +"','"+
   // string6 +"','"+ string8 +"','"+ string10 +"','"+ string12 + "')";
   String cqlStr =
       "INSERT INTO "
           + keyspace
           + "."
           + string
           + "("
           + string2
           + ","
           + string4
           + ","
           + string6
           + ","
           + string8
           + ") VALUES ('"
           + string3
           + "','"
           + string5
           + "','"
           + string7
           + "','"
           + string9
           + "')";
   Statement statement = new SimpleStatement(cqlStr);
   String operationtype = "insert";
   // System.out.println("***insert executed:="+cqlStr);
   scheduleAndQueue(
       operationtype,
       statement,
       tuple.getSession(),
       index,
       l,
       latency_insert2,
       cLevel,
       CLID,
       tInv,
       tuple);
 }
Beispiel #4
0
  public ResultSet scheduleAndQueue(
      String operationtype,
      Statement statement,
      Session session,
      int index,
      long l,
      long latency_insert2,
      String cLevel,
      String clId,
      long tInv,
      Tuple tuple) {
    Query q = null;
    String key = null;
    // UUID idOne = UUID.randomUUID();
    String CLID = null; // String.valueOf(idOne) + String.valueOf(System.currentTimeMillis());
    long latencyDep = 0;
    CopyOnWriteArrayList<RegistryEntry> rList = null;
    String STATUS;
    ResultSet result = null;
    Scheduler scheduler = new Scheduler();

    if ((DependencyChecker.causalList.size() > index
            && ((Query) DependencyChecker.causalList.get(index))
                .getGuarantee()
                .equalsIgnoreCase("C"))
        || (DependencyChecker.serializeList.size() > index
            && ((Query) DependencyChecker.serializeList.get(index))
                .getGuarantee()
                .equalsIgnoreCase("S"))) {
      // System.out.println("***in iof constion causal:serialise");
      if (DependencyChecker.causalList.contains(index)
          && ((Query) DependencyChecker.causalList.get(index))
              .getGuarantee()
              .equalsIgnoreCase("C")) {
        while (!((Query) DependencyChecker.causalList.get(index))
            .getIndex()
            .equalsIgnoreCase(String.valueOf(index))) {
          // System.out.println("***Waiting in causal queue");
        }
        // if(((Query)DependencyChecker.causalList.get(index)).getIndex().equalsIgnoreCase(String.valu             eOf(index)))
        // {
        statement = updateConsistencyLevel(statement, cLevel, index, tuple);
        result = session.execute(statement); // unblock for deploy
        q = tuple.getCausalQueue().remove();
      } else {
        // System.out.println("***in else
        // constionL===="+((Query)tuple.getDependencyChecker().getSerializeList().get(index)).getIndex()+": index"+String.valueOf((int)tuple.getDependencyChecker().getQueryList().size()-index-1));
        if (((Query) DependencyChecker.serializeList.get(index))
            .getIndex()
            .equalsIgnoreCase(
                String.valueOf((int) DependencyChecker.queryList.size() - 1 - index))) {
          // System.out.println("1111in else
          // constionL===="+((Query)tuple.getDependencyChecker().getSerializeList().get(index)).getIndex());
          l = System.currentTimeMillis() - l;
          // key = (String)
          // ((HashMap<String,String>)DependencyChecker.serializeList.get(index)).keySet().toArray()[0];
          key = ((Query) DependencyChecker.serializeList.get(index)).getKey();
          for (int i = index; i < DependencyChecker.serializeList.size(); i++) {
            latencyDep = latencyDep + ((Query) DependencyChecker.serializeList.get(i)).getLatency();
          }
          curr_deadline = curr_deadline - (System.currentTimeMillis() - tInv);
          createRegistry(session);

          writeToRegister(
              ((Query) DependencyChecker.serializeList.get(index)).getKey(),
              index,
              clId,
              l,
              latencyDep,
              curr_deadline,
              "OFF",
              session); // unblock for deploy
          // System.out.println("***After write to register");//for thread
          // "+Thread.currentThread().getName());
          // CLID = readFromRegister(key, session);//unblock for deploy
          // System.out.println("****rlist size:="+ rList.size());
          // if(rList.size()>0)
          // if(CLID!=null)
          // {
          // CLID = scheduler.schedule(rList).split(":")[0];
          // STATUS = scheduler.schedule(rList).split(":")[1];

          while (readFromRegister(key, session) != null
              && readFromRegister(key, session).contains(":")
              && readFromRegister(key, session).split(":")[1].equalsIgnoreCase("OFF")
              && !clId.equalsIgnoreCase(
                  readFromRegister(key, session)
                      .split(":")[0])) // || !STATUS.equalsIgnoreCase("OFF"))
          {
            // System.out.println("***Client " + clId +"Waiting for the lock to the column "+key);//
            // for thread "+Thread.currentThread().getName());
            // System.out.println("***Waiting for the lock to the column "+key);// for thread
            // "+Thread.currentThread().getName());
          }
          scheduler.requestLock(session, key, clId, index); // unblock for deploy
          // System.out.println("***After requesting the lock to the columnfor the query index"+
          // index);
          statement = updateConsistencyLevel(statement, cLevel, index, tuple);
          result = session.execute(statement); // unblock for deploy
          // System.out.println("***After executing the query index"+ index);
          scheduler.releaseLock(session, key, clId, index); // unblock for deploy
          if (tuple.getCausalQueue().peek() != null) {
            q = tuple.getCausalQueue().remove();
            scheduler.removeregistry(session, key, clId, index); // unblock for deploy
          }
          // System.out.println("***After release lock and registry cleanup for the query index"+
          // index);
          // }
        } else {

        }
      }
    } else {
      // System.out.println("In eventual guarantee case:"+mutator);
      statement = updateConsistencyLevel(statement, cLevel, index, tuple);
      // System.out.println("***111 Executing eventual consistent queries statement:="+statement);
      // System.out.println("***222 Executing eventual consistent queries tuple
      // session:="+tuple.getSession());
      result = session.execute(statement); // unblock for deploy
      // if(causalQueue.peek()!=null)
      // q = causalQueue.remove();
    }
    return result;
  }