@Override
    public String toString() {
      StringBuilder sb = new StringBuilder();
      sb.append("{");

      int mark = sb.length();
      Binding nullNextProtocolSnapshot = nullNextProtocol.get();
      if (nullNextProtocolSnapshot != null) {
        sb.append("null: ");
        ResourceAddress bindAddress = nullNextProtocolSnapshot.bindAddress();
        sb.append(bindAddress);
        sb.append(", ");
      }

      for (Binding binding : nextProtocols.values()) {
        ResourceAddress bindAddress = binding.bindAddress();
        sb.append(bindAddress);
        sb.append(", ");
      }

      if (sb.length() > mark) {
        // rewind last ", "
        sb.setLength(sb.length() - 2);
      }

      sb.append('}');

      return sb.toString();
    }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  @Validate
  public Iterable<V> getAllValues(@NotNull final T key) {
    ConcurrentNavigableMap<K, V> m = map.get(key);
    if (m != null) return m.values();

    return new ArrayList<V>();
  }
 /** 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"));
 }
 /** 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"));
 }
Exemplo n.º 5
0
 /** {@inheritDoc} */
 @Override
 public Iterable<V> values() {
   for (ConcurrentNavigableMap<K, V> m : map.values()) for (V value : m.values()) yield(value);
 }
Exemplo n.º 6
0
  private Collection<SSTableReader> writeSortedContents(File sstableDirectory) {
    boolean isBatchLogTable =
        cfs.name.equals(SystemKeyspace.BATCHES)
            && cfs.keyspace.getName().equals(SystemKeyspace.NAME);

    logger.debug("Writing {}", Memtable.this.toString());

    Collection<SSTableReader> ssTables;
    try (SSTableTxnWriter writer =
        createFlushWriter(
            cfs.getSSTablePath(sstableDirectory), columnsCollector.get(), statsCollector.get())) {
      boolean trackContention = logger.isTraceEnabled();
      int heavilyContendedRowCount = 0;
      // (we can't clear out the map as-we-go to free up memory,
      //  since the memtable is being used for queries in the "pending flush" category)
      for (AtomicBTreePartition partition : partitions.values()) {
        // Each batchlog partition is a separate entry in the log. And for an entry, we only do 2
        // operations: 1) we insert the entry and 2) we delete it. Further, BL data is strictly
        // local,
        // we don't need to preserve tombstones for repair. So if both operation are in this
        // memtable (which will almost always be the case if there is no ongoing failure), we can
        // just skip the entry (CASSANDRA-4667).
        if (isBatchLogTable && !partition.partitionLevelDeletion().isLive() && partition.hasRows())
          continue;

        if (trackContention && partition.usePessimisticLocking()) heavilyContendedRowCount++;

        if (!partition.isEmpty()) {
          try (UnfilteredRowIterator iter = partition.unfilteredIterator()) {
            writer.append(iter);
          }
        }
      }

      if (writer.getFilePointer() > 0) {
        logger.debug(
            String.format(
                "Completed flushing %s (%s) for commitlog position %s",
                writer.getFilename(),
                FBUtilities.prettyPrintMemory(writer.getFilePointer()),
                commitLogUpperBound));

        // sstables should contain non-repaired data.
        ssTables = writer.finish(true);
      } else {
        logger.debug(
            "Completed flushing {}; nothing needed to be retained.  Commitlog position was {}",
            writer.getFilename(),
            commitLogUpperBound);
        writer.abort();
        ssTables = Collections.emptyList();
      }

      if (heavilyContendedRowCount > 0)
        logger.trace(
            String.format(
                "High update contention in %d/%d partitions of %s ",
                heavilyContendedRowCount, partitions.size(), Memtable.this.toString()));

      return ssTables;
    }
  }