Examples of ErrorQueryStatus


Examples of com.splout.db.qnode.beans.ErrorQueryStatus

   * @throws QuerierException
   */
  public QueryStatus query(String tablespaceName, String key, String sql, String partition) throws JSONSerDeException, QuerierException {
    Long version = context.getCurrentVersionsMap().get(tablespaceName);
    if(version == null) {
      return new ErrorQueryStatus("Unknown tablespace or no version ready to be served! (" + tablespaceName + ")");
    }
    Tablespace tablespace = context.getTablespaceVersionsMap().get(
        new TablespaceVersion(tablespaceName, version));
    if(tablespace == null) {
      return new ErrorQueryStatus("Unknown tablespace version:(" + version +") tablespace:(" + tablespaceName + ")");
    }
    PartitionMap partitionMap = tablespace.getPartitionMap();
   
    // find the partition
    int partitionId;
    // use a key to find the appropriated partition
    if(key != null) {
      partitionId = partitionMap.findPartition(key);
      if(partitionId == PartitionMap.NO_PARTITION) {
        return new ErrorQueryStatus("Key out of partition ranges: " + key + " for tablespace "
            + tablespaceName);
      }
    } else { // use provided partition
      // partition shouldn't be null here -> we check it before at QNodeHandler
      if(partition.toLowerCase().equals(PARTITION_RANDOM)) {
View Full Code Here

Examples of com.splout.db.qnode.beans.ErrorQueryStatus

   * API method for querying a tablespace when you already know the partition Id. Can be used for multi-querying.
   */
  public QueryStatus query(String tablespaceName, String sql, int partitionId) throws JSONSerDeException {
    Long version = context.getCurrentVersionsMap().get(tablespaceName);
    if(version == null) {
      return new ErrorQueryStatus("Unknown tablespace! (" + tablespaceName + ")");
    }
    Tablespace tablespace = context.getTablespaceVersionsMap().get(
        new TablespaceVersion(tablespaceName, version));
    if(tablespace == null) {
      return new ErrorQueryStatus("Unknown tablespace! (" + tablespaceName + ")");
    }
    ReplicationMap replicationMap = tablespace.getReplicationMap();
    ReplicationEntry repEntry = null;

    for(ReplicationEntry rEntry : replicationMap.getReplicationEntries()) {
      if(rEntry.getShard() == partitionId) {
        repEntry = rEntry;
      }
    }
   
    if(repEntry == null) {
      return new ErrorQueryStatus("Incomplete Tablespace information for tablespace (" + tablespaceName
          + ") Maybe let the Splout warmup a little bit and try later?");
    }
    if(repEntry.getNodes().size() == 0) { // No one alive for serving the query!
      return new ErrorQueryStatus("No alive DNodes for " + tablespace);
    }

    String electedNode;
    int tried = 0;
    for(;;) { // Fail-over loop
      electedNode = null;
      Integer lastNode = partitionRoundRobin.get().get(partitionId);
      if(lastNode == null) {
        lastNode = -1;
      }
      lastNode++;
      tried++;
      int index = lastNode % repEntry.getNodes().size();
      electedNode = repEntry.getNodes().get(index);
      partitionRoundRobin.get().put(partitionId, index);

      // Perform query
      QueryStatus qStatus = new QueryStatus();
      long start = System.currentTimeMillis();

      DNodeService.Client client = null;
      boolean renew = false;
     
      try {
        client = context.getDNodeClientFromPool(electedNode);

        String r;
        try {
          r = client.sqlQuery(tablespaceName, version, partitionId, sql);
        } catch(TTransportException e) {
          renew = true;
          throw e;
        }

        qStatus.setResult(JSONSerDe.deSer(r, ArrayList.class));
        long end = System.currentTimeMillis();
        // Report the time of the query
        qStatus.setMillis((end - start));
        // ... and the shard hit.
        qStatus.setShard(partitionId);
        return qStatus;
      } catch(DNodeException e) {
        log.error("Exception in Querier", e);
        if(tried == repEntry.getNodes().size()) {
          return new ErrorQueryStatus("DNode exception (" + e.getMsg() + ") from " + electedNode);
        }
      } catch(TException e) {
        log.error("Exception in Querier", e);
        if(tried == repEntry.getNodes().size()) {
          return new ErrorQueryStatus("Error connecting to client " + electedNode);
        }
      } finally {
        if(client != null) {
          context.returnDNodeClientToPool(electedNode, client, renew);
        }
View Full Code Here

Examples of com.splout.db.qnode.beans.ErrorQueryStatus

    Querier querier = new Querier(context);
   
    // All DNodes are tried since they are alive and because all including the last one fail, the error is returned
    for(int i = 0; i < 3; i++) {
      ErrorQueryStatus status = (ErrorQueryStatus) querier.query("t1", "", 0);
      assertTrue(status.getError().contains("connecting to client localhost:6666"));
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.