예제 #1
0
  public void checkSlice(
      String[][] values, Set<KeyColumn> removed, int key, int start, int end, int limit) {
    List<Entry> entries;
    if (limit <= 0)
      entries =
          store.getSlice(
              KeyValueStoreUtil.getBuffer(key),
              KeyValueStoreUtil.getBuffer(start),
              KeyValueStoreUtil.getBuffer(end),
              tx);
    else
      entries =
          store.getSlice(
              KeyValueStoreUtil.getBuffer(key),
              KeyValueStoreUtil.getBuffer(start),
              KeyValueStoreUtil.getBuffer(end),
              limit,
              tx);

    int pos = 0;
    for (int i = start; i < end; i++) {
      if (removed.contains(new KeyColumn(key, i))) continue;
      if (limit <= 0 || pos < limit) {
        Entry entry = entries.get(pos);
        int col = KeyValueStoreUtil.getID(entry.getColumn());
        String str = KeyValueStoreUtil.getString(entry.getValue());
        assertEquals(i, col);
        assertEquals(values[key][i], str);
      }
      pos++;
    }
    assertNotNull(entries);
    if (limit > 0 && pos > limit) assertEquals(limit, entries.size());
    else assertEquals(pos, entries.size());
  }
예제 #2
0
  private List<Entry> appendResults(
      ByteBuffer key,
      ByteBuffer columnStart,
      ByteBuffer columnEnd,
      List<Entry> entries,
      LimitTracker limit,
      TransactionHandle txh) {
    if (limit.limitExhausted()) return null;
    List<Entry> results = null;

    for (int readAttempt = 0; readAttempt < maxReadRetryAttempts; readAttempt++) {
      try {
        results = edgeStore.getSlice(key, columnStart, columnEnd, limit.getLimit(), txh);
        break;
      } catch (StorageException e) {
        if (e instanceof TemporaryStorageException) {
          if (readAttempt < maxReadRetryAttempts - 1) temporaryStorageException(e);
          else throw readException(e, maxReadRetryAttempts);
        } else throw readException(e);
      }
    }

    limit.retrieved(results.size());

    if (entries == null) return results;
    else {
      entries.addAll(results);
      return entries;
    }
  }
예제 #3
0
  @Test
  public void getSliceRespectsAllBoundsInclusionArguments() throws Exception {
    // Test case where endColumn=startColumn+1
    ByteBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    ByteBuffer columnBeforeStart = KeyColumnValueStoreUtil.longToByteBuffer(776);
    ByteBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(777);
    ByteBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(778);
    ByteBuffer columnAfterEnd = KeyColumnValueStoreUtil.longToByteBuffer(779);

    // First insert four test Entries
    TransactionHandle txn = manager.beginTransaction();
    List<Entry> entries =
        Arrays.asList(
            new Entry(columnBeforeStart, columnBeforeStart),
            new Entry(columnStart, columnStart),
            new Entry(columnEnd, columnEnd),
            new Entry(columnAfterEnd, columnAfterEnd));
    store.mutate(key, entries, null, txn);
    txn.commit();

    // getSlice() with only start inclusive
    txn = manager.beginTransaction();
    List<Entry> result = store.getSlice(key, columnStart, columnEnd, txn);
    assertEquals(1, result.size());
    assertEquals(777, result.get(0).getColumn().getLong());
    txn.commit();
  }
예제 #4
0
  @Test
  public void getSliceRespectsColumnLimit() throws Exception {
    TransactionHandle txn = manager.beginTransaction();
    ByteBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);

    final int cols = 1024;

    List<Entry> entries = new LinkedList<Entry>();
    for (int i = 0; i < cols; i++) {
      ByteBuffer col = KeyColumnValueStoreUtil.longToByteBuffer(i);
      entries.add(new Entry(col, col));
    }
    store.mutate(key, entries, null, txn);
    txn.commit();

    txn = manager.beginTransaction();
    ByteBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(0);
    ByteBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(cols);
    /*
     * When limit is greater than or equal to the matching column count,
     * all matching columns must be returned.
     */
    List<Entry> result = store.getSlice(key, columnStart, columnEnd, cols, txn);
    assertEquals(cols, result.size());
    assertEquals(entries, result);
    result = store.getSlice(key, columnStart, columnEnd, cols + 10, txn);
    assertEquals(cols, result.size());
    assertEquals(entries, result);

    /*
     * When limit is less the matching column count, the columns up to the
     * limit (ordered bytewise) must be returned.
     */
    result = store.getSlice(key, columnStart, columnEnd, cols - 1, txn);
    assertEquals(cols - 1, result.size());
    entries.remove(entries.size() - 1);
    assertEquals(entries, result);
    result = store.getSlice(key, columnStart, columnEnd, 1, txn);
    assertEquals(1, result.size());
    List<Entry> firstEntrySingleton = Arrays.asList(entries.get(0));
    assertEquals(firstEntrySingleton, result);
    txn.commit();
  }
예제 #5
0
  @Override
  public long[] indexRetrieval(Object key, TitanKey pt, InternalTitanTransaction tx) {
    Preconditions.checkArgument(
        pt.isSimple(), "Currently, only simple properties are supported for index retrieval");
    Preconditions.checkArgument(
        pt.hasIndex(), "Cannot retrieve for given property key - it does not have an index");

    long[] vertices = null;

    Preconditions.checkArgument(
        pt.getDataType().isInstance(key),
        "Specified object is incompatible with property data type [" + pt.getName() + "]");

    for (int readAttempt = 0; readAttempt < maxReadRetryAttempts; readAttempt++) {
      try {
        if (pt.isUnique()) {
          ByteBuffer value =
              propertyIndex.get(getIndexKey(key), getKeyedIndexColumn(pt), tx.getTxHandle());
          if (value != null) {
            vertices = new long[1];
            vertices[0] = VariableLong.readPositive(value);
          }
        } else {
          ByteBuffer startColumn = VariableLong.positiveByteBuffer(pt.getID());
          List<Entry> entries =
              propertyIndex.getSlice(
                  getIndexKey(key),
                  startColumn,
                  ByteBufferUtil.nextBiggerBuffer(startColumn),
                  tx.getTxHandle());
          vertices = new long[entries.size()];
          int i = 0;
          for (Entry ent : entries) {
            vertices[i++] = VariableLong.readPositive(ent.getValue());
          }
        }

        break;
      } catch (StorageException e) {
        if (e instanceof TemporaryStorageException) {
          if (readAttempt < maxReadRetryAttempts - 1) temporaryStorageException(e);
          else throw readException(e, maxReadRetryAttempts);
        } else throw readException(e);
      }
    }

    if (vertices == null) return new long[0];
    else return vertices;
  }