cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject git commit: Replace EmptyColumns with updated ArrayBackedSortedColumns
Date Wed, 12 Feb 2014 02:24:54 GMT
Updated Branches:
  refs/heads/trunk 67101c29c -> 5cf381f57


Replace EmptyColumns with updated ArrayBackedSortedColumns

patch by Aleksey Yeschenko; reviewed by Jonathan Ellis for
CASSANDRA-6690


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5cf381f5
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5cf381f5
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5cf381f5

Branch: refs/heads/trunk
Commit: 5cf381f57da41e986e7434fb7a46531c42c2cdd3
Parents: 67101c2
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Wed Feb 12 05:22:29 2014 +0300
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Wed Feb 12 05:22:29 2014 +0300

----------------------------------------------------------------------
 CHANGES.txt                                     |   4 +-
 .../db/AbstractThreadUnsafeSortedColumns.java   |  70 ------------
 .../cassandra/db/ArrayBackedSortedColumns.java  |  50 ++++++++-
 .../org/apache/cassandra/db/EmptyColumns.java   | 112 -------------------
 .../org/apache/cassandra/db/SystemKeyspace.java |   2 +-
 .../db/columniterator/IndexedSliceReader.java   |   2 +-
 .../db/columniterator/SimpleSliceReader.java    |   2 +-
 .../db/compaction/LazilyCompactedRow.java       |   2 +-
 .../io/sstable/SSTableIdentityIterator.java     |   2 +-
 .../apache/cassandra/service/StorageProxy.java  |   4 +-
 .../cassandra/service/pager/QueryPagers.java    |   2 +-
 .../apache/cassandra/service/paxos/Commit.java  |   4 +-
 12 files changed, 56 insertions(+), 200 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1025510..3831b38 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -25,8 +25,8 @@
  * CF id is changed to be non-deterministic. Data dir/key cache are created
    uniquely for CF id (CASSANDRA-5202)
  * New counters implementation (CASSANDRA-6504)
- * Replace UnsortedColumns and TreeMapBackedSortedColumns with rewritten
-   ArrayBackedSortedColumns (CASSANDRA-6630, CASSANDRA-6662)
+ * Replace UnsortedColumns, EmptyColumns, TreeMapBackedSortedColumns with new
+   ArrayBackedSortedColumns (CASSANDRA-6630, CASSANDRA-6662, CASSANDRA-6690)
  * Add option to use row cache with a given amount of rows (CASSANDRA-5357)
  * Avoid repairing already repaired data (CASSANDRA-5351)
  * Reject counter updates with USING TTL/TIMESTAMP (CASSANDRA-6649)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java b/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java
deleted file mode 100644
index 36b051b..0000000
--- a/src/java/org/apache/cassandra/db/AbstractThreadUnsafeSortedColumns.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.db;
-
-import org.apache.cassandra.config.CFMetaData;
-
-public abstract class AbstractThreadUnsafeSortedColumns extends ColumnFamily
-{
-    protected DeletionInfo deletionInfo;
-
-    public AbstractThreadUnsafeSortedColumns(CFMetaData metadata)
-    {
-        this(metadata, DeletionInfo.live());
-    }
-
-    protected AbstractThreadUnsafeSortedColumns(CFMetaData metadata, DeletionInfo deletionInfo)
-    {
-        super(metadata);
-        this.deletionInfo = deletionInfo;
-    }
-
-    public DeletionInfo deletionInfo()
-    {
-        return deletionInfo;
-    }
-
-    public void delete(DeletionTime delTime)
-    {
-        deletionInfo.add(delTime);
-    }
-
-    public void delete(DeletionInfo newInfo)
-    {
-        deletionInfo.add(newInfo);
-    }
-
-    protected void delete(RangeTombstone tombstone)
-    {
-        deletionInfo.add(tombstone, getComparator());
-    }
-
-    public void setDeletionInfo(DeletionInfo newInfo)
-    {
-        deletionInfo = newInfo;
-    }
-
-    /**
-     * Purges any tombstones with a local deletion time before gcBefore.
-     * @param gcBefore a timestamp (in seconds) before which tombstones should be purged
-     */
-    public void purgeTombstones(int gcBefore)
-    {
-        deletionInfo.purge(gcBefore);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java b/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java
index 8049d87..eaebd11 100644
--- a/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java
+++ b/src/java/org/apache/cassandra/db/ArrayBackedSortedColumns.java
@@ -37,13 +37,13 @@ import org.apache.cassandra.db.filter.ColumnSlice;
  * main operations performed are iterating over the cells and adding cells
  * (especially if insertion is in sorted order).
  */
-public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns
+public class ArrayBackedSortedColumns extends ColumnFamily
 {
-    private static final int INITIAL_CAPACITY = 10;
-
     private static final Cell[] EMPTY_ARRAY = new Cell[0];
+    private static final int MINIMAL_CAPACITY = 10;
 
     private final boolean reversed;
+    private DeletionInfo deletionInfo;
 
     private Cell[] cells;
     private int size;
@@ -61,7 +61,8 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns
     {
         super(metadata);
         this.reversed = reversed;
-        this.cells = new Cell[INITIAL_CAPACITY];
+        this.deletionInfo = DeletionInfo.live();
+        this.cells = EMPTY_ARRAY;
         this.size = 0;
         this.sortedSize = 0;
     }
@@ -70,6 +71,7 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns
     {
         super(original.metadata);
         this.reversed = original.reversed;
+        this.deletionInfo = DeletionInfo.live(); // this is INTENTIONALLY not set to original.deletionInfo.
         this.cells = Arrays.copyOf(original.cells, original.size);
         this.size = original.size;
         this.sortedSize = original.sortedSize;
@@ -211,9 +213,11 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns
      */
     private void internalAdd(Cell cell)
     {
-        // Resize the backing array if we hit the capacity
-        if (cells.length == size)
+        if (cells == EMPTY_ARRAY)
+            cells = new Cell[MINIMAL_CAPACITY];
+        else if (cells.length == size)
             cells = Arrays.copyOf(cells, size * 3 / 2 + 1);
+
         cells[size++] = cell;
     }
 
@@ -318,6 +322,40 @@ public class ArrayBackedSortedColumns extends AbstractThreadUnsafeSortedColumns
         size = sortedSize = 0;
     }
 
+    public DeletionInfo deletionInfo()
+    {
+        return deletionInfo;
+    }
+
+    public void delete(DeletionTime delTime)
+    {
+        deletionInfo.add(delTime);
+    }
+
+    public void delete(DeletionInfo newInfo)
+    {
+        deletionInfo.add(newInfo);
+    }
+
+    protected void delete(RangeTombstone tombstone)
+    {
+        deletionInfo.add(tombstone, getComparator());
+    }
+
+    public void setDeletionInfo(DeletionInfo newInfo)
+    {
+        deletionInfo = newInfo;
+    }
+
+    /**
+     * Purges any tombstones with a local deletion time before gcBefore.
+     * @param gcBefore a timestamp (in seconds) before which tombstones should be purged
+     */
+    public void purgeTombstones(int gcBefore)
+    {
+        deletionInfo.purge(gcBefore);
+    }
+
     public Iterable<CellName> getColumnNames()
     {
         maybeSortCells();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/EmptyColumns.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/EmptyColumns.java b/src/java/org/apache/cassandra/db/EmptyColumns.java
deleted file mode 100644
index fa6ea1b..0000000
--- a/src/java/org/apache/cassandra/db/EmptyColumns.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * 
- */
-package org.apache.cassandra.db;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-
-import com.google.common.collect.Iterators;
-
-import org.apache.cassandra.config.CFMetaData;
-import org.apache.cassandra.db.composites.CellName;
-import org.apache.cassandra.db.filter.ColumnSlice;
-
-public class EmptyColumns extends AbstractThreadUnsafeSortedColumns
-{
-    public static final Factory<EmptyColumns> factory = new Factory<EmptyColumns>()
-    {
-        public EmptyColumns create(CFMetaData metadata, boolean insertReversed)
-        {
-            assert !insertReversed;
-            return new EmptyColumns(metadata, DeletionInfo.live());
-        }
-    };
-
-    public EmptyColumns(CFMetaData metadata, DeletionInfo info)
-    {
-        super(metadata, info);
-    }
-
-    public ColumnFamily cloneMe()
-    {
-        return new EmptyColumns(metadata, deletionInfo);
-    }
-
-    public void clear()
-    {
-    }
-
-    public Factory<EmptyColumns> getFactory()
-    {
-        return factory;
-    }
-
-    public void addColumn(Cell cell)
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void addAll(ColumnFamily cm)
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Cell getColumn(CellName name)
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Iterable<CellName> getColumnNames()
-    {
-        return Collections.emptyList();
-    }
-
-    public Collection<Cell> getSortedColumns()
-    {
-        return Collections.emptyList();
-    }
-
-    public Collection<Cell> getReverseSortedColumns()
-    {
-        return Collections.emptyList();
-    }
-
-    public int getColumnCount()
-    {
-        return 0;
-    }
-
-    public Iterator<Cell> iterator(ColumnSlice[] slices)
-    {
-        return Iterators.emptyIterator();
-    }
-
-    public Iterator<Cell> reverseIterator(ColumnSlice[] slices)
-    {
-        return Iterators.emptyIterator();
-    }
-
-    public boolean isInsertReversed()
-    {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/SystemKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java
index f8637c1..1a00cc0 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspace.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java
@@ -810,7 +810,7 @@ public class SystemKeyspace
             return new PaxosState(key, metadata);
         UntypedResultSet.Row row = results.one();
         Commit promised = row.has("in_progress_ballot")
-                        ? new Commit(key, row.getUUID("in_progress_ballot"), EmptyColumns.factory.create(metadata))
+                        ? new Commit(key, row.getUUID("in_progress_ballot"), ArrayBackedSortedColumns.factory.create(metadata))
                         : Commit.emptyCommit(key, metadata);
         // either we have both a recently accepted ballot and update or we have neither
         Commit accepted = row.has("proposal")

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java b/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
index 8715a90..2a596ea 100644
--- a/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
+++ b/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
@@ -77,7 +77,7 @@ class IndexedSliceReader extends AbstractIterator<OnDiskAtom> implements
OnDiskA
         try
         {
             this.indexes = indexEntry.columnsIndex();
-            emptyColumnFamily = EmptyColumns.factory.create(sstable.metadata);
+            emptyColumnFamily = ArrayBackedSortedColumns.factory.create(sstable.metadata);
             if (indexes.isEmpty())
             {
                 setToRowStart(indexEntry, input);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java b/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java
index 862fad2..7fb48e3 100644
--- a/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java
+++ b/src/java/org/apache/cassandra/db/columniterator/SimpleSliceReader.java
@@ -71,7 +71,7 @@ class SimpleSliceReader extends AbstractIterator<OnDiskAtom> implements
OnDiskAt
             if (version.hasRowSizeAndColumnCount)
                 file.readLong();
 
-            emptyColumnFamily = EmptyColumns.factory.create(sstable.metadata);
+            emptyColumnFamily = ArrayBackedSortedColumns.factory.create(sstable.metadata);
             emptyColumnFamily.delete(DeletionTime.serializer.deserialize(file));
             int columnCount = version.hasRowSizeAndColumnCount ? file.readInt() : Integer.MAX_VALUE;
             atomIterator = emptyColumnFamily.metadata().getOnDiskIterator(file, columnCount,
sstable.descriptor.version);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java b/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
index 89181e6..53be765 100644
--- a/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
+++ b/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
@@ -81,7 +81,7 @@ public class LazilyCompactedRow extends AbstractCompactedRow
         // containing `key` outside of the set of sstables involved in this compaction.
         maxPurgeableTimestamp = controller.maxPurgeableTimestamp(key);
 
-        emptyColumnFamily = EmptyColumns.factory.create(controller.cfs.metadata);
+        emptyColumnFamily = ArrayBackedSortedColumns.factory.create(controller.cfs.metadata);
         emptyColumnFamily.delete(maxRowTombstone);
         if (maxRowTombstone.markedForDeleteAt < maxPurgeableTimestamp)
             emptyColumnFamily.purgeTombstones(controller.gcBefore);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java b/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
index 4e23ac2..11f2f71 100644
--- a/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
+++ b/src/java/org/apache/cassandra/io/sstable/SSTableIdentityIterator.java
@@ -99,7 +99,7 @@ public class SSTableIdentityIterator implements Comparable<SSTableIdentityIterat
 
         try
         {
-            columnFamily = EmptyColumns.factory.create(metadata);
+            columnFamily = ArrayBackedSortedColumns.factory.create(metadata);
             columnFamily.delete(DeletionTime.serializer.deserialize(in));
             columnCount = dataVersion.hasRowSizeAndColumnCount ? in.readInt() : Integer.MAX_VALUE;
             atomIterator = columnFamily.metadata().getOnDiskIterator(in, columnCount, dataVersion);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/service/StorageProxy.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java
index 8c31192..05fdd61 100644
--- a/src/java/org/apache/cassandra/service/StorageProxy.java
+++ b/src/java/org/apache/cassandra/service/StorageProxy.java
@@ -232,7 +232,7 @@ public class StorageProxy implements StorageProxyMBean
             {
                 Tracing.trace("CAS precondition {} does not match current values {}", conditions,
current);
                 // We should not return null as this means success
-                return current == null ? EmptyColumns.factory.create(metadata) : current;
+                return current == null ? ArrayBackedSortedColumns.factory.create(metadata)
: current;
             }
 
             // finish the paxos round w/ the desired updates
@@ -603,7 +603,7 @@ public class StorageProxy implements StorageProxyMBean
 
     private static void asyncRemoveFromBatchlog(Collection<InetAddress> endpoints,
UUID uuid)
     {
-        ColumnFamily cf = EmptyColumns.factory.create(Schema.instance.getCFMetaData(Keyspace.SYSTEM_KS,
SystemKeyspace.BATCHLOG_CF));
+        ColumnFamily cf = ArrayBackedSortedColumns.factory.create(Schema.instance.getCFMetaData(Keyspace.SYSTEM_KS,
SystemKeyspace.BATCHLOG_CF));
         cf.delete(new DeletionInfo(FBUtilities.timestampMicros(), (int) (System.currentTimeMillis()
/ 1000)));
         AbstractWriteResponseHandler handler = new WriteResponseHandler(endpoints,
                                                                         Collections.<InetAddress>emptyList(),

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/service/pager/QueryPagers.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/pager/QueryPagers.java b/src/java/org/apache/cassandra/service/pager/QueryPagers.java
index 32ff86c..f186e69 100644
--- a/src/java/org/apache/cassandra/service/pager/QueryPagers.java
+++ b/src/java/org/apache/cassandra/service/pager/QueryPagers.java
@@ -147,7 +147,7 @@ public class QueryPagers
                 {
                     List<Row> rows = pager.fetchPage(pageSize);
                     ColumnFamily cf = rows.isEmpty() ? null : rows.get(0).cf;
-                    return cf == null ? EmptyColumns.factory.create(cfs.metadata) : cf;
+                    return cf == null ? ArrayBackedSortedColumns.factory.create(cfs.metadata)
: cf;
                 }
                 catch (Exception e)
                 {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5cf381f5/src/java/org/apache/cassandra/service/paxos/Commit.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/paxos/Commit.java b/src/java/org/apache/cassandra/service/paxos/Commit.java
index aae9b72..6abfe4c 100644
--- a/src/java/org/apache/cassandra/service/paxos/Commit.java
+++ b/src/java/org/apache/cassandra/service/paxos/Commit.java
@@ -57,7 +57,7 @@ public class Commit
 
     public static Commit newPrepare(ByteBuffer key, CFMetaData metadata, UUID ballot)
     {
-        return new Commit(key, ballot, EmptyColumns.factory.create(metadata));
+        return new Commit(key, ballot, ArrayBackedSortedColumns.factory.create(metadata));
     }
 
     public static Commit newProposal(ByteBuffer key, UUID ballot, ColumnFamily update)
@@ -67,7 +67,7 @@ public class Commit
 
     public static Commit emptyCommit(ByteBuffer key, CFMetaData metadata)
     {
-        return new Commit(key, UUIDGen.minTimeUUID(0), EmptyColumns.factory.create(metadata));
+        return new Commit(key, UUIDGen.minTimeUUID(0), ArrayBackedSortedColumns.factory.create(metadata));
     }
 
     public boolean isAfter(Commit other)


Mime
View raw message