Exemplo n.º 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];
  }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  @Validate
  public V get(@NotNull final T key, @NotNull final K subkey) {
    final ConcurrentNavigableMap<K, V> m = map.get(key);
    if (m != null) return m.get(subkey);

    return null;
  }
 /** get(null) of nonempty map throws NPE */
 public void testGet_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.get(null);
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
Exemplo n.º 4
0
 /** {@inheritDoc} */
 @Override
 @Validate
 public Iterable<V> getValuesBySubkey(@NotNull final K subkey) {
   for (ConcurrentNavigableMap<K, V> m : map.values()) {
     V value = m.get(subkey);
     if (value != null) yield(value);
   }
 }
 public void deleteTestCase(long id) {
   String jsonTestCase = testCaseMap.get(id);
   if (jsonTestCase != null) {
     TestCase testCase = new Gson().fromJson(jsonTestCase, TestCase.class);
     testCaseIndex.remove(testCase.title);
     testCaseMap.remove(id);
     db.commit();
   }
 }
    public Binding getBinding(ResourceAddress address) {
      String nextProtocol = address.getOption(NEXT_PROTOCOL);

      if (nextProtocol == null) {
        return nullNextProtocol.get();
      }

      return nextProtocols.get(nextProtocol);
    }
 public void putTestCase(TestCase testCase) {
   Long id = testCaseIndex.get(testCase.title);
   if (id != null && !id.equals(testCase.id))
     throw new IllegalArgumentException("Duplicate title");
   String jsonTestCase = new Gson().toJson(testCase);
   testCaseMap.put(testCase.id, jsonTestCase);
   testCaseIndex.put(testCase.title, testCase.id);
   db.commit();
 }
Exemplo n.º 8
0
  /** {@inheritDoc} */
  @Override
  @Validate
  public V removeSubKey(@NotNull final K subkey) {
    for (ConcurrentNavigableMap<K, V> m : map.values()) {
      V value = m.get(subkey);
      if (value != null) return m.remove(subkey);
    }

    return null;
  }
 /** 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));
 }
Exemplo n.º 11
0
  private void registerRemoval(String id, long lifeTime, TimeUnit unit) {
    ITaskManagerHook hook = taskManagerHooks.get(id);
    if (hook != null) {

      long removalTime = unit.toMillis(lifeTime) + System.currentTimeMillis();

      // Remove current scheduled removal
      Long currentRemovalTime = taskManagerRemovalBackRegister.get(hook);
      if (currentRemovalTime != null) {
        taskManagerRemovalRegister.remove(currentRemovalTime);
      }

      // Find an empty spot in the sorted map's key register
      removalTime--;
      do {
        removalTime++;
        taskManagerRemovalRegister.putIfAbsent(removalTime, hook);
      } while (taskManagerRemovalRegister.get(removalTime) != hook);

      // Back reference the removal
      taskManagerRemovalBackRegister.put(hook, removalTime);
    }
  }
    public boolean removeBinding(ResourceAddress address, Binding binding) {
      ResourceAddress bindAddress = binding.bindAddress();
      String nextProtocol = bindAddress.getOption(NEXT_PROTOCOL);

      if (nextProtocol == null) {
        Binding oldBinding = nullNextProtocol.get();
        if (equivalent(oldBinding, binding)) {
          binding = oldBinding;
        }
        if (binding.decrementReferenceCount() == 0) {
          return nullNextProtocol.compareAndSet(binding, null);
        }
        return false;
      }

      Binding oldBinding = nextProtocols.get(nextProtocol);
      if (equivalent(oldBinding, binding)) {
        binding = oldBinding;
      }
      if (binding.decrementReferenceCount() == 0) {
        return nextProtocols.remove(nextProtocol, binding);
      }
      return false;
    }
 /** 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));
 }
 public TestCase getTestCase(String title) {
   Long id = testCaseIndex.get(title);
   if (id == null) return null;
   String jsonTestCase = testCaseMap.get(id);
   return (jsonTestCase == null) ? null : new Gson().fromJson(jsonTestCase, TestCase.class);
 }
 public TestCase getTestCase(long id) {
   String jsonTestCase = testCaseMap.get(id);
   return (jsonTestCase == null) ? null : new Gson().fromJson(jsonTestCase, TestCase.class);
 }
Exemplo n.º 16
0
 public ColumnFamily getColumnFamily(DecoratedKey key) {
   return columnFamilies.get(key);
 }
Exemplo n.º 17
0
 public String get(String key) {
   return treeMap.get(key);
 }
 /** 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));
 }
 /** 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));
 }
Exemplo n.º 20
0
 public Partition getPartition(DecoratedKey key) {
   return partitions.get(key);
 }
 /** 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));
 }