Пример #1
0
 private void doInsert(ConsistencyLevel consistency, RowMutation rm)
     throws UnavailableException, TimedOutException {
   if (consistency != ConsistencyLevel.ZERO) {
     try {
       StorageProxy.mutateBlocking(Arrays.asList(rm), thriftConsistencyLevel(consistency));
     } catch (TimeoutException e) {
       throw new TimedOutException();
     } catch (org.apache.cassandra.thrift.UnavailableException thriftE) {
       throw new UnavailableException();
     }
   } else {
     StorageProxy.mutate(Arrays.asList(rm));
   }
 }
Пример #2
0
  protected Map<String, ColumnFamily> readColumnFamily(
      List<ReadCommand> commands, ConsistencyLevel consistency)
      throws InvalidRequestException, UnavailableException, TimedOutException {
    // TODO - Support multiple column families per row, right now row only contains 1 column family
    Map<String, ColumnFamily> columnFamilyKeyMap = new HashMap<String, ColumnFamily>();

    if (consistency == ConsistencyLevel.ZERO)
      throw newInvalidRequestException(
          "Consistency level zero may not be applied to read operations");

    if (consistency == ConsistencyLevel.ALL)
      throw newInvalidRequestException(
          "Consistency level all is not yet supported on read operations");

    List<Row> rows;
    try {
      rows = StorageProxy.readProtocol(commands, thriftConsistencyLevel(consistency));
    } catch (TimeoutException e) {
      throw new TimedOutException();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    // FIXME: This suckage brought to you by StorageService and StorageProxy
    // which throw Thrift exceptions directly.
    catch (org.apache.cassandra.thrift.UnavailableException e) {
      throw new UnavailableException();
    }

    for (Row row : rows) {
      columnFamilyKeyMap.put(row.key, row.cf);
    }

    return columnFamilyKeyMap;
  }
Пример #3
0
  private LocalOrRemoteBlock getRemoteSubBlock(
      ByteBuffer blockId, ByteBuffer sblockId, int offset, ColumnParent subBlockDataPath)
      throws TimedOutException, UnavailableException, InvalidRequestException, NotFoundException {
    // The column name is the SubBlock id (UUID)
    ReadCommand rc =
        new SliceByNamesReadCommand(
            cfsKeyspace, blockId, subBlockDataPath, Arrays.asList(sblockId));

    try {
      // CL=ONE as there are NOT multiple versions of the blocks.
      List<Row> rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.ONE);

      IColumn col = null;
      try {
        col = validateAndGetColumn(rows, sblockId);
      } catch (NotFoundException e) {
        // This is a best effort to get the value. Sometimes due to the size of
        // the sublocks, the normal replication may time out leaving a replicate without
        // the piece of data. Hence we re try with higher CL.
        rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.QUORUM);
      }

      col = validateAndGetColumn(rows, sblockId);

      ByteBuffer value = col.value();

      if (value.remaining() < offset)
        throw new InvalidRequestException("Invalid offset for block of size: " + value.remaining());

      LocalOrRemoteBlock block = new LocalOrRemoteBlock();
      if (offset > 0) {
        ByteBuffer offsetBlock = value.duplicate();
        offsetBlock.position(offsetBlock.position() + offset);
        block.setRemote_block(offsetBlock);
      } else {
        block.setRemote_block(value);
      }

      return block;
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (TimeoutException e) {
      throw new TimedOutException();
    }
  }
 public CqlResult execute(ClientState state, List<ByteBuffer> variables)
     throws InvalidRequestException, UnavailableException {
   try {
     StorageProxy.truncateBlocking(keyspace(), columnFamily());
   } catch (TimeoutException e) {
     throw (UnavailableException) new UnavailableException().initCause(e);
   } catch (IOException e) {
     throw (UnavailableException) new UnavailableException().initCause(e);
   }
   return null;
 }
  protected List<Row> queryNextPage(
      int pageSize, ConsistencyLevel consistencyLevel, boolean localQuery)
      throws RequestExecutionException {
    AbstractRangeCommand pageCmd = command.withUpdatedLimit(pageSize);
    if (lastReturnedKey != null)
      pageCmd = pageCmd.forSubRange(makeExcludingKeyBounds(lastReturnedKey));

    return localQuery
        ? pageCmd.executeLocally()
        : StorageProxy.getRangeSlice(pageCmd, consistencyLevel);
  }
Пример #6
0
  public List<Row> fetchPage(int pageSize)
      throws RequestValidationException, RequestExecutionException {
    assert command.filter.countCQL3Rows() || command.filter.columns.size() <= pageSize;

    if (isExhausted()) {
      return Collections.<Row>emptyList();
    }

    queried = true;

    return localQuery
        ? Collections.singletonList(command.getRow(Keyspace.open(command.ksName)))
        : StorageProxy.read(Collections.<ReadCommand>singletonList(command), consistencyLevel);
  }