Example #1
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];
  }
 /** get(null) of nonempty map throws NPE */
 public void testGet_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.get(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 /** 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));
 }
 /** 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));
 }
 /** get returns the correct element at the given key, or null if not present */
 public void testGet() {
   ConcurrentNavigableMap map = map5();
   assertEquals("A", (String) map.get(one));
   ConcurrentNavigableMap empty = map0();
   assertNull(empty.get(one));
 }
 /** replace value succeeds when the given key mapped to expected value */
 public void testDescendingReplaceValue2() {
   ConcurrentNavigableMap map = dmap5();
   assertEquals("A", map.get(m1));
   assertTrue(map.replace(m1, "A", "Z"));
   assertEquals("Z", map.get(m1));
 }
 /** get returns the correct element at the given key, or null if not present */
 public void testDescendingGet() {
   ConcurrentNavigableMap map = dmap5();
   assertEquals("A", (String) map.get(m1));
   ConcurrentNavigableMap empty = dmap0();
   assertNull(empty.get(m1));
 }
 /** replace value succeeds when the given key mapped to expected value */
 public void testReplaceValue2() {
   ConcurrentNavigableMap map = map5();
   assertEquals("A", map.get(one));
   assertTrue(map.replace(one, "A", "Z"));
   assertEquals("Z", map.get(one));
 }
 /** replace succeeds if the key is already present */
 public void testReplace2() {
   ConcurrentNavigableMap map = map5();
   assertNotNull(map.replace(one, "Z"));
   assertEquals("Z", map.get(one));
 }
Example #10
0
 public Partition getPartition(DecoratedKey key) {
   return partitions.get(key);
 }