Exemple #1
0
 private void clear(Entity ent) {
   for (Index ei : graph.getIndexList()) {
     if (ei.getIndex() != IGRAPH) {
       Entity rem = ei.delete(ent);
       if (isDebug && rem != null) logger.debug("** EI clear: " + ei.getIndex() + " " + rem);
     }
   }
 }
  protected int removeAll() {
    int count = 0;
    Index index = getIndex();
    GetRequest request = GetRequest.newBuilder().setReturningIdsOnly(true).setLimit(200).build();
    GetResponse<Document> response = index.getRange(request);

    // can only delete documents in blocks of 200 so we need to iterate until they're all gone
    while (!response.getResults().isEmpty()) {
      List<String> ids = new ArrayList<String>();
      for (Document document : response) {
        ids.add(document.getId());
      }
      index.delete(ids);
      count += ids.size();
      response = index.getRange(request);
    }
    return count;
  }
Exemple #3
0
  @Test
  public void testEvictBase() throws IOException {
    int size = mSize;
    boolean autoLoad = mAutoLoad;
    Index ix = mDb.openIndex("test");
    int initialRecordCount = 100_000 * (1024 / size);
    for (int i = 0; i < initialRecordCount; i++) {
      String key = textOfLength(i, 'k', size);
      String val = textOfLength(i, 'v', size);
      ix.store(null, key.getBytes(), val.getBytes());
    }

    // basic eviction
    TestEvictionFilter evictionFilter = new TestEvictionFilter();
    long evicted = ix.evict(null, null, null, evictionFilter, autoLoad);
    int recordCount = initialRecordCount - evictionFilter.mKeys.size();
    long keyValueSize = 0;
    for (int i = 0; i < evictionFilter.mKeys.size(); ++i) {
      keyValueSize += evictionFilter.mKeys.get(i).length + evictionFilter.mValues.get(i).length;
    }
    assertEquals(
        evicted,
        autoLoad
            ? keyValueSize
            : keyValueSize * 2); // if autoload is not enabled, only keys are load
    assertEquals(recordCount, ix.count(null, null));
    for (byte[] key : evictionFilter.mKeys) {
      assertNull(ix.load(null, key));
    }
    assertTrue(evictionFilter.mKeys.size() >= 1);
    assertTrue(evictionFilter.mKeys.size() <= 1024 / size);

    // empty range
    evictionFilter = new TestEvictionFilter();
    assertEquals(0, ix.evict(null, "a".getBytes(), "b".getBytes(), evictionFilter, autoLoad));
    assertEquals(recordCount, ix.count(null, null));
    assertEquals(0, evictionFilter.mKeys.size());
    assertEquals(0, evictionFilter.mValues.size());

    // evict nodes in a particular range
    evictionFilter = new TestEvictionFilter();
    ix.newCursor(null).find("a".getBytes()); // loads rightmost nodes at all levels into cache
    assertEquals(
        size * 2,
        ix.evict(null, "009998".getBytes(), "009999".getBytes(), evictionFilter, autoLoad));
    assertEquals(1, evictionFilter.mKeys.size());
    assertEquals(1, evictionFilter.mValues.size());
    assertTrue(new String(evictionFilter.mKeys.get(0)).startsWith("009998"));
    if (autoLoad) {
      assertTrue(new String(evictionFilter.mValues.get(0)).startsWith("009998"));
    } else {
      assertTrue(evictionFilter.mValues.get(0) == Cursor.NOT_LOADED);
    }
    assertEquals(--recordCount, ix.count(null, null));

    // ghost records
    evictionFilter = new TestEvictionFilter();
    Transaction txn = mDb.newTransaction();
    int lowKey = initialRecordCount - 11;
    int highKey = initialRecordCount - 20;
    for (int i = lowKey; i <= highKey; i++) {
      String key = textOfLength(i, 'k', size);
      ix.delete(txn, key.getBytes());
    }
    assertEquals(
        0,
        ix.evict(
            null,
            String.valueOf(lowKey).getBytes(),
            String.valueOf(highKey).getBytes(),
            evictionFilter,
            autoLoad));
    assertEquals(0, evictionFilter.mKeys.size());
    assertEquals(0, evictionFilter.mValues.size());
    txn.reset();

    VerificationObserver observer = new VerificationObserver();
    ix.verify(observer);
    assertFalse(observer.failed);
  }