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];
  }
    public Binding addBinding(Binding newBinding) {
      ResourceAddress bindAddress = newBinding.bindAddress();
      String nextProtocol = bindAddress.getOption(NEXT_PROTOCOL);

      if (nextProtocol == null) {
        if (nullNextProtocol.compareAndSet(null, newBinding)) {
          newBinding.incrementReferenceCount();
          return null;
        }
        Binding oldBinding = nullNextProtocol.get();
        if (equivalent(newBinding, oldBinding)) {
          oldBinding.incrementReferenceCount();
          return null;
        }
        return oldBinding;
      }

      Binding oldBinding = nextProtocols.putIfAbsent(nextProtocol, newBinding);
      if (oldBinding == null) {
        newBinding.incrementReferenceCount();
      } else if (equivalent(newBinding, oldBinding)) {
        oldBinding.incrementReferenceCount();
        oldBinding = null;
      }
      return oldBinding;
    }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 @Validate
 public V putIfAbsent(@NotNull final T key, @NotNull final K subkey, V value) {
   ConcurrentSkipListMap<K, V> newer = new ConcurrentSkipListMap<K, V>();
   ConcurrentNavigableMap<K, V> m = map.putIfAbsent(key, newer);
   if (m == null) m = newer;
   return m.putIfAbsent(subkey, value);
 }
 /** putIfAbsent(null, x) throws NPE */
 public void testPutIfAbsent1_NullPointerException() {
   try {
     ConcurrentNavigableMap c = map5();
     c.putIfAbsent(null, "whatever");
     shouldThrow();
   } catch (NullPointerException success) {
   }
 }
 public static void handleOrphan(Cluster cluster, ClusterAddressInfo address) {
   Integer orphanCount = 1;
   orphanCount = orphans.putIfAbsent(address, orphanCount);
   orphanCount = (orphanCount == null) ? 1 : orphanCount;
   orphans.put(address, orphanCount + 1);
   EventRecord.caller(
           ClusterState.class,
           EventType.ADDRESS_STATE,
           "Updated orphaned public ip address: "
               + LogUtil.dumpObject(address)
               + " count="
               + orphanCount)
       .debug();
   if (orphanCount > AddressingConfiguration.getInstance().getMaxKillOrphans()) {
     EventRecord.caller(
             ClusterState.class,
             EventType.ADDRESS_STATE,
             "Unassigning orphaned public ip address: "
                 + LogUtil.dumpObject(address)
                 + " count="
                 + orphanCount)
         .warn();
     try {
       final Address addr = Addresses.getInstance().lookup(address.getAddress());
       if (addr.isPending()) {
         try {
           addr.clearPending();
         } catch (Exception ex) {
         }
       }
       try {
         if (addr.isAssigned() && "0.0.0.0".equals(address.getInstanceIp())) {
           addr.unassign().clearPending();
           if (addr.isSystemOwned()) {
             addr.release();
           }
         } else if (addr.isAssigned() && !"0.0.0.0".equals(address.getInstanceIp())) {
           AsyncRequests.newRequest(new UnassignAddressCallback(address))
               .sendSync(cluster.getConfiguration());
           if (addr.isSystemOwned()) {
             addr.release();
           }
         } else if (!addr.isAssigned() && addr.isAllocated() && addr.isSystemOwned()) {
           addr.release();
         }
       } catch (ExecutionException ex) {
         if (!addr.isAssigned() && addr.isAllocated() && addr.isSystemOwned()) {
           addr.release();
         }
       }
     } catch (InterruptedException ex) {
       Exceptions.maybeInterrupted(ex);
     } catch (NoSuchElementException ex) {
     } finally {
       orphans.remove(address);
     }
   }
 }
Exemplo n.º 6
0
  private void resolve(DecoratedKey key, ColumnFamily cf) {
    currentThroughput.addAndGet(cf.size());
    currentOperations.addAndGet(
        (cf.getColumnCount() == 0) ? cf.isMarkedForDelete() ? 1 : 0 : cf.getColumnCount());

    ColumnFamily oldCf = columnFamilies.putIfAbsent(key, cf);
    if (oldCf == null) return;

    oldCf.resolve(cf);
  }
Exemplo n.º 7
0
 private static void handleOrphan(String cluster, Address address) {
   Integer orphanCount = 1;
   orphanCount = orphans.putIfAbsent(address.getName(), orphanCount);
   orphanCount = (orphanCount == null) ? 1 : orphanCount;
   orphans.put(address.getName(), orphanCount + 1);
   LOG.warn("Found orphaned public ip address: " + address + " count=" + orphanCount);
   if (orphanCount > 10) {
     orphans.remove(address.getName());
     Clusters.dispatchClusterEvent(cluster, new UnassignAddressCallback(address));
   }
 }
Exemplo n.º 8
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);
    }
  }
 /** putIfAbsent does not add the pair if the key is already present */
 public void testDescendingPutIfAbsent2() {
   ConcurrentNavigableMap map = dmap5();
   assertEquals("A", map.putIfAbsent(m1, "Z"));
 }
 /** putIfAbsent works when the given key is not present */
 public void testDescendingPutIfAbsent() {
   ConcurrentNavigableMap map = dmap5();
   map.putIfAbsent(six, "Z");
   assertTrue(map.containsKey(six));
 }
 /** putIfAbsent does not add the pair if the key is already present */
 public void testPutIfAbsent2() {
   ConcurrentNavigableMap map = map5();
   assertEquals("A", map.putIfAbsent(one, "Z"));
 }