예제 #1
0
  public MemtableUnfilteredPartitionIterator makePartitionIterator(
      final ColumnFilter columnFilter, final DataRange dataRange, final boolean isForThrift) {
    AbstractBounds<PartitionPosition> keyRange = dataRange.keyRange();

    boolean startIsMin = keyRange.left.isMinimum();
    boolean stopIsMin = keyRange.right.isMinimum();

    boolean isBound = keyRange instanceof Bounds;
    boolean includeStart = isBound || keyRange instanceof IncludingExcludingBounds;
    boolean includeStop = isBound || keyRange instanceof Range;
    Map<PartitionPosition, AtomicBTreePartition> subMap;
    if (startIsMin)
      subMap = stopIsMin ? partitions : partitions.headMap(keyRange.right, includeStop);
    else
      subMap =
          stopIsMin
              ? partitions.tailMap(keyRange.left, includeStart)
              : partitions.subMap(keyRange.left, includeStart, keyRange.right, includeStop);

    int minLocalDeletionTime = Integer.MAX_VALUE;

    // avoid iterating over the memtable if we purge all tombstones
    if (cfs.getCompactionStrategyManager().onlyPurgeRepairedTombstones())
      minLocalDeletionTime = findMinLocalDeletionTime(subMap.entrySet().iterator());

    final Iterator<Map.Entry<PartitionPosition, AtomicBTreePartition>> iter =
        subMap.entrySet().iterator();

    return new MemtableUnfilteredPartitionIterator(
        cfs, iter, isForThrift, minLocalDeletionTime, columnFilter, dataRange);
  }
 public void testSubMapContents2() {
   ConcurrentNavigableMap map = map5();
   SortedMap sm = map.subMap(two, three);
   assertEquals(1, sm.size());
   assertEquals(two, sm.firstKey());
   assertEquals(two, sm.lastKey());
   assertFalse(sm.containsKey(one));
   assertTrue(sm.containsKey(two));
   assertFalse(sm.containsKey(three));
   assertFalse(sm.containsKey(four));
   assertFalse(sm.containsKey(five));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(two, k);
   assertFalse(i.hasNext());
   Iterator j = sm.keySet().iterator();
   j.next();
   j.remove();
   assertFalse(map.containsKey(two));
   assertEquals(4, map.size());
   assertEquals(0, sm.size());
   assertTrue(sm.isEmpty());
   assertSame(sm.remove(three), null);
   assertEquals(4, map.size());
 }
 public void testDescendingSubMapContents2() {
   ConcurrentNavigableMap map = dmap5();
   SortedMap sm = map.subMap(m2, m3);
   assertEquals(1, sm.size());
   assertEquals(m2, sm.firstKey());
   assertEquals(m2, sm.lastKey());
   assertFalse(sm.containsKey(m1));
   assertTrue(sm.containsKey(m2));
   assertFalse(sm.containsKey(m3));
   assertFalse(sm.containsKey(m4));
   assertFalse(sm.containsKey(m5));
   Iterator i = sm.keySet().iterator();
   Object k;
   k = (Integer) (i.next());
   assertEquals(m2, k);
   assertFalse(i.hasNext());
   Iterator j = sm.keySet().iterator();
   j.next();
   j.remove();
   assertFalse(map.containsKey(m2));
   assertEquals(4, map.size());
   assertEquals(0, sm.size());
   assertTrue(sm.isEmpty());
   assertSame(sm.remove(m3), null);
   assertEquals(4, map.size());
 }
 /** toString contains toString of elements */
 public void testToString() {
   ConcurrentNavigableMap map = map5();
   String s = map.toString();
   for (int i = 1; i <= 5; ++i) {
     assertTrue(s.indexOf(String.valueOf(i)) >= 0);
   }
 }
예제 #5
0
  /**
   * Should only be called by ColumnFamilyStore.apply via Keyspace.apply, which supplies the
   * appropriate OpOrdering.
   *
   * <p>replayPosition should only be null if this is a secondary index, in which case it is
   * *expected* to be null
   */
  long put(PartitionUpdate update, UpdateTransaction indexer, OpOrder.Group opGroup) {
    AtomicBTreePartition previous = partitions.get(update.partitionKey());

    long initialSize = 0;
    if (previous == null) {
      final DecoratedKey cloneKey = allocator.clone(update.partitionKey(), opGroup);
      AtomicBTreePartition empty = new AtomicBTreePartition(cfs.metadata, cloneKey, allocator);
      // We'll add the columns later. This avoids wasting works if we get beaten in the putIfAbsent
      previous = partitions.putIfAbsent(cloneKey, empty);
      if (previous == null) {
        previous = empty;
        // allocate the row overhead after the fact; this saves over allocating and having to free
        // after, but
        // means we can overshoot our declared limit.
        int overhead = (int) (cloneKey.getToken().getHeapSize() + ROW_OVERHEAD_HEAP_SIZE);
        allocator.onHeap().allocate(overhead, opGroup);
        initialSize = 8;
      } else {
        allocator.reclaimer().reclaimImmediately(cloneKey);
      }
    }

    long[] pair = previous.addAllWithSizeDelta(update, opGroup, indexer);
    minTimestamp = Math.min(minTimestamp, previous.stats().minTimestamp);
    liveDataSize.addAndGet(initialSize + pair[0]);
    columnsCollector.update(update.columns());
    statsCollector.update(update.stats());
    currentOperations.addAndGet(update.operationCount());
    return pair[1];
  }
 /** remove(null) throws NPE */
 public void testDescendingRemove1_NullPointerException() {
   try {
     ConcurrentNavigableMap c = dmap5();
     c.remove(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** replace(null, x, y) throws NPE */
 public void testDescendingReplaceValue_NullPointerException() {
   try {
     ConcurrentNavigableMap c = dmap5();
     c.replace(null, m1, "whatever");
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** containsKey(null) of nm1mpty map throws NPE */
 public void testDescendingContainsKey_NullPointerException() {
   try {
     ConcurrentNavigableMap c = dmap5();
     c.containsKey(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** containsValue(null) throws NPE */
 public void testContainsValue_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map0();
     c.containsValue(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** putIfAbsent(null, x) throws NPE */
 public void testPutIfAbsent1_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.putIfAbsent(null, "whatever");
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** remove(null, x) throws NPE */
 public void testRemove2_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.remove(null, "whatever");
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** get(null) of nonempty map throws NPE */
 public void testGet_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.get(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** Maps with same contents are equal */
 public void testEquals() {
   ConcurrentNavigableMap map1 = map5();
   ConcurrentNavigableMap map2 = map5();
   assertEquals(map1, map2);
   assertEquals(map2, map1);
   map1.clear();
   assertFalse(map1.equals(map2));
   assertFalse(map2.equals(map1));
 }
 /** descendingkeySet.toArray returns contains all keys */
 public void testDescendingDescendingKeySetToArray() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.descendingKeySet();
   Object[] ar = s.toArray();
   assertEquals(5, ar.length);
   assertTrue(s.containsAll(Arrays.asList(ar)));
   ar[0] = m10;
   assertFalse(s.containsAll(Arrays.asList(ar)));
 }
 /** values collection contains all values */
 public void testDescendingValues() {
   ConcurrentNavigableMap map = dmap5();
   Collection s = map.values();
   assertEquals(5, s.size());
   assertTrue(s.contains("A"));
   assertTrue(s.contains("B"));
   assertTrue(s.contains("C"));
   assertTrue(s.contains("D"));
   assertTrue(s.contains("E"));
 }
 /** keySet returns a Set containing all the keys */
 public void testDescendingKeySet() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.keySet();
   assertEquals(5, s.size());
   assertTrue(s.contains(m1));
   assertTrue(s.contains(m2));
   assertTrue(s.contains(m3));
   assertTrue(s.contains(m4));
   assertTrue(s.contains(m5));
 }
 /** keySet returns a Set containing all the keys */
 public void testKeySet() {
   ConcurrentNavigableMap map = map5();
   Set s = map.keySet();
   assertEquals(5, s.size());
   assertTrue(s.contains(one));
   assertTrue(s.contains(two));
   assertTrue(s.contains(three));
   assertTrue(s.contains(four));
   assertTrue(s.contains(five));
 }
 /** keySet is ordered */
 public void testDescendingKeySetOrder() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.keySet();
   Iterator i = s.iterator();
   Integer last = (Integer) i.next();
   assertEquals(last, m1);
   while (i.hasNext()) {
     Integer k = (Integer) i.next();
     assertTrue(last.compareTo(k) > 0);
     last = k;
   }
 }
 /** Values.toArray contains all values */
 public void testDescendingValuesToArray() {
   ConcurrentNavigableMap map = dmap5();
   Collection v = map.values();
   Object[] ar = v.toArray();
   ArrayList s = new ArrayList(Arrays.asList(ar));
   assertEquals(5, ar.length);
   assertTrue(s.contains("A"));
   assertTrue(s.contains("B"));
   assertTrue(s.contains("C"));
   assertTrue(s.contains("D"));
   assertTrue(s.contains("E"));
 }
  /** lowerEntry returns preceding entry. */
  public void testLowerEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e1 = map.lowerEntry(three);
    assertEquals(two, e1.getKey());

    Map.Entry e2 = map.lowerEntry(six);
    assertEquals(five, e2.getKey());

    Map.Entry e3 = map.lowerEntry(one);
    assertNull(e3);

    Map.Entry e4 = map.lowerEntry(zero);
    assertNull(e4);
  }
  /** lowerEntry returns preceding entry. */
  public void testDescendingLowerEntry() {
    ConcurrentNavigableMap map = dmap5();
    Map.Entry e1 = map.lowerEntry(m3);
    assertEquals(m2, e1.getKey());

    Map.Entry e2 = map.lowerEntry(m6);
    assertEquals(m5, e2.getKey());

    Map.Entry e3 = map.lowerEntry(m1);
    assertNull(e3);

    Map.Entry e4 = map.lowerEntry(zero);
    assertNull(e4);
  }
  /** ceilingEntry returns next entry. */
  public void testCeilingEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e1 = map.ceilingEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.ceilingEntry(zero);
    assertEquals(one, e2.getKey());

    Map.Entry e3 = map.ceilingEntry(five);
    assertEquals(five, e3.getKey());

    Map.Entry e4 = map.ceilingEntry(six);
    assertNull(e4);
  }
  /** higherEntry returns next entry. */
  public void testHigherEntry() {
    ConcurrentNavigableMap map = map5();
    Map.Entry e1 = map.higherEntry(three);
    assertEquals(four, e1.getKey());

    Map.Entry e2 = map.higherEntry(zero);
    assertEquals(one, e2.getKey());

    Map.Entry e3 = map.higherEntry(five);
    assertNull(e3);

    Map.Entry e4 = map.higherEntry(six);
    assertNull(e4);
  }
  /** ceilingEntry returns next entry. */
  public void testDescendingCeilingEntry() {
    ConcurrentNavigableMap map = dmap5();
    Map.Entry e1 = map.ceilingEntry(m3);
    assertEquals(m3, e1.getKey());

    Map.Entry e2 = map.ceilingEntry(zero);
    assertEquals(m1, e2.getKey());

    Map.Entry e3 = map.ceilingEntry(m5);
    assertEquals(m5, e3.getKey());

    Map.Entry e4 = map.ceilingEntry(m6);
    assertNull(e4);
  }
 /** remove(key,value) removes only if pair present */
 public void testRemove2() {
   ConcurrentNavigableMap map = map5();
   assertTrue(map.containsKey(five));
   assertEquals("E", map.get(five));
   map.remove(five, "E");
   assertEquals(4, map.size());
   assertFalse(map.containsKey(five));
   map.remove(four, "A");
   assertEquals(4, map.size());
   assertTrue(map.containsKey(four));
 }
 /** remove(key,value) removes only if pair present */
 public void testDescendingRemove2() {
   ConcurrentNavigableMap map = dmap5();
   assertTrue(map.containsKey(m5));
   assertEquals("E", map.get(m5));
   map.remove(m5, "E");
   assertEquals(4, map.size());
   assertFalse(map.containsKey(m5));
   map.remove(m4, "A");
   assertEquals(4, map.size());
   assertTrue(map.containsKey(m4));
 }
 /** entrySet contains all pairs */
 public void testEntrySet() {
   ConcurrentNavigableMap map = map5();
   Set s = map.entrySet();
   assertEquals(5, s.size());
   Iterator it = s.iterator();
   while (it.hasNext()) {
     Map.Entry e = (Map.Entry) it.next();
     assertTrue(
         (e.getKey().equals(one) && e.getValue().equals("A"))
             || (e.getKey().equals(two) && e.getValue().equals("B"))
             || (e.getKey().equals(three) && e.getValue().equals("C"))
             || (e.getKey().equals(four) && e.getValue().equals("D"))
             || (e.getKey().equals(five) && e.getValue().equals("E")));
   }
 }
 /** entrySet contains all pairs */
 public void testDescendingEntrySet() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.entrySet();
   assertEquals(5, s.size());
   Iterator it = s.iterator();
   while (it.hasNext()) {
     Map.Entry e = (Map.Entry) it.next();
     assertTrue(
         (e.getKey().equals(m1) && e.getValue().equals("A"))
             || (e.getKey().equals(m2) && e.getValue().equals("B"))
             || (e.getKey().equals(m3) && e.getValue().equals("C"))
             || (e.getKey().equals(m4) && e.getValue().equals("D"))
             || (e.getKey().equals(m5) && e.getValue().equals("E")));
   }
 }
예제 #29
0
  @SuppressWarnings("resource") // log and writer closed by SSTableTxnWriter
  public SSTableTxnWriter createFlushWriter(
      String filename, PartitionColumns columns, EncodingStats stats) {
    // we operate "offline" here, as we expose the resulting reader consciously when done
    // (although we may want to modify this behaviour in future, to encapsulate full flush behaviour
    // in LifecycleTransaction)
    LifecycleTransaction txn = null;
    try {
      txn = LifecycleTransaction.offline(OperationType.FLUSH);
      MetadataCollector sstableMetadataCollector =
          new MetadataCollector(cfs.metadata.comparator)
              .commitLogIntervals(
                  new IntervalSet(commitLogLowerBound.get(), commitLogUpperBound.get()));

      return new SSTableTxnWriter(
          txn,
          cfs.createSSTableMultiWriter(
              Descriptor.fromFilename(filename),
              (long) partitions.size(),
              ActiveRepairService.UNREPAIRED_SSTABLE,
              sstableMetadataCollector,
              new SerializationHeader(true, cfs.metadata, columns, stats),
              txn));
    } catch (Throwable t) {
      if (txn != null) txn.close();
      throw t;
    }
  }
  /** headMap returns map with keys in requested range */
  public void testTailMapContents() {
    ConcurrentNavigableMap map = map5();
    SortedMap sm = map.tailMap(two);
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertTrue(sm.containsKey(four));
    assertTrue(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());

    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(two, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(three, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(four, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());

    SortedMap ssm = sm.tailMap(four);
    assertEquals(four, ssm.firstKey());
    assertEquals(five, ssm.lastKey());
    assertEquals("D", ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
  }