cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject git commit: inline AbstractColumnContainer and IIterableColumns
Date Tue, 26 Mar 2013 22:39:56 GMT
Updated Branches:
  refs/heads/trunk b79b236d0 -> 255db5006


inline AbstractColumnContainer and IIterableColumns


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

Branch: refs/heads/trunk
Commit: 255db5006d5d164a70c6bbdcf2bacb648170068d
Parents: b79b236
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Tue Mar 26 17:39:47 2013 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Tue Mar 26 17:39:47 2013 -0500

----------------------------------------------------------------------
 .../cassandra/db/AbstractColumnContainer.java      |  205 ---------------
 src/java/org/apache/cassandra/db/ColumnFamily.java |  182 ++++++++++++--
 .../org/apache/cassandra/db/ISortedColumns.java    |    8 +-
 .../apache/cassandra/io/util/IIterableColumns.java |   28 --
 .../org/apache/cassandra/tools/SSTableExport.java  |   20 +-
 .../org/apache/cassandra/tools/SSTableImport.java  |    3 +-
 6 files changed, 179 insertions(+), 267 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/255db500/src/java/org/apache/cassandra/db/AbstractColumnContainer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/AbstractColumnContainer.java b/src/java/org/apache/cassandra/db/AbstractColumnContainer.java
deleted file mode 100644
index 1a38e4b..0000000
--- a/src/java/org/apache/cassandra/db/AbstractColumnContainer.java
+++ /dev/null
@@ -1,205 +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.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.SortedSet;
-
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-
-import org.apache.cassandra.db.filter.ColumnSlice;
-import org.apache.cassandra.db.index.SecondaryIndexManager;
-import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.io.util.IIterableColumns;
-import org.apache.cassandra.utils.Allocator;
-import org.apache.cassandra.utils.HeapAllocator;
-
-public abstract class AbstractColumnContainer implements IIterableColumns
-{
-    protected final ISortedColumns columns;
-
-    protected AbstractColumnContainer(ISortedColumns columns)
-    {
-        this.columns = columns;
-    }
-
-    public void delete(AbstractColumnContainer cc2)
-    {
-        delete(cc2.columns.getDeletionInfo());
-    }
-
-    public void delete(DeletionInfo delInfo)
-    {
-        columns.delete(delInfo);
-    }
-
-    // Contrarily to delete(), this will use the provided info even if those
-    // are older that the current ones. Used for SuperColumn in QueryFilter.
-    // delete() is probably the right method in all other cases.
-    public void setDeletionInfo(DeletionInfo delInfo)
-    {
-        columns.setDeletionInfo(delInfo);
-    }
-
-    public boolean isMarkedForDelete()
-    {
-        return !deletionInfo().isLive();
-    }
-
-    public DeletionInfo deletionInfo()
-    {
-        return columns.getDeletionInfo();
-    }
-
-    public AbstractType<?> getComparator()
-    {
-        return columns.getComparator();
-    }
-
-    /**
-     * Drops expired row-level tombstones.  Normally, these are dropped once the row no longer
exists, but
-     * if new columns are inserted into the row post-deletion, they can keep the row tombstone
alive indefinitely,
-     * with non-intuitive results.  See https://issues.apache.org/jira/browse/CASSANDRA-2317
-     */
-    public void maybeResetDeletionTimes(int gcBefore)
-    {
-        columns.maybeResetDeletionTimes(gcBefore);
-    }
-
-    public long addAllWithSizeDelta(AbstractColumnContainer cc, Allocator allocator, Function<Column,
Column> transformation, SecondaryIndexManager.Updater indexer)
-    {
-        return columns.addAllWithSizeDelta(cc.columns, allocator, transformation, indexer);
-    }
-
-    public void addAll(AbstractColumnContainer cc, Allocator allocator, Function<Column,
Column> transformation)
-    {
-        columns.addAll(cc.columns, allocator, transformation);
-    }
-
-    public void addAll(AbstractColumnContainer cc, Allocator allocator)
-    {
-        addAll(cc, allocator, Functions.<Column>identity());
-    }
-
-    public void addColumn(Column column)
-    {
-        addColumn(column, HeapAllocator.instance);
-    }
-
-    public void addColumn(Column column, Allocator allocator)
-    {
-        columns.addColumn(column, allocator);
-    }
-
-    public Column getColumn(ByteBuffer name)
-    {
-        return columns.getColumn(name);
-    }
-
-    public boolean replace(Column oldColumn, Column newColumn)
-    {
-        return columns.replace(oldColumn, newColumn);
-    }
-
-    /*
-     * Note that for some of the implementation backing the container, the
-     * return set may not have implementation for tailSet, headSet and subSet.
-     * See ColumnNamesSet in ArrayBackedSortedColumns for more details.
-     */
-    public SortedSet<ByteBuffer> getColumnNames()
-    {
-        return columns.getColumnNames();
-    }
-
-    public Collection<Column> getSortedColumns()
-    {
-        return columns.getSortedColumns();
-    }
-
-    public Collection<Column> getReverseSortedColumns()
-    {
-        return columns.getReverseSortedColumns();
-    }
-
-    public void remove(ByteBuffer columnName)
-    {
-        columns.removeColumn(columnName);
-    }
-
-    public void retainAll(AbstractColumnContainer container)
-    {
-        columns.retainAll(container.columns);
-    }
-
-    public int getColumnCount()
-    {
-        return columns.size();
-    }
-
-    public boolean isEmpty()
-    {
-        return columns.isEmpty();
-    }
-
-    public int getEstimatedColumnCount()
-    {
-        return getColumnCount();
-    }
-
-    public boolean hasOnlyTombstones()
-    {
-        for (Column column : columns)
-        {
-            if (column.isLive())
-                return false;
-        }
-        return true;
-    }
-
-    public Iterator<Column> iterator()
-    {
-        return columns.iterator();
-    }
-
-    public Iterator<Column> iterator(ColumnSlice[] slices)
-    {
-        return columns.iterator(slices);
-    }
-
-    public Iterator<Column> reverseIterator(ColumnSlice[] slices)
-    {
-        return columns.reverseIterator(slices);
-    }
-
-    public boolean hasIrrelevantData(int gcBefore)
-    {
-        // Do we have gcable deletion infos?
-        if (!deletionInfo().purge(gcBefore).equals(deletionInfo()))
-            return true;
-
-        // Do we have colums that are either deleted by the container or gcable tombstone?
-        for (Column column : columns)
-            if (deletionInfo().isDeleted(column) || column.hasIrrelevantData(gcBefore))
-                return true;
-
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/255db500/src/java/org/apache/cassandra/db/ColumnFamily.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnFamily.java b/src/java/org/apache/cassandra/db/ColumnFamily.java
index 1509f9e..c183412 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamily.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamily.java
@@ -17,11 +17,19 @@
  */
 package org.apache.cassandra.db;
 
-import java.io.DataInput;
 import java.nio.ByteBuffer;
 import java.security.MessageDigest;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.SortedSet;
 import java.util.UUID;
 
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
+
+import org.apache.cassandra.db.filter.ColumnSlice;
+import org.apache.cassandra.db.index.SecondaryIndexManager;
+import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.io.sstable.SSTable;
 import org.apache.cassandra.utils.*;
 
@@ -30,16 +38,15 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.cassandra.cache.IRowCacheEntry;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.MarshalException;
-import org.apache.cassandra.io.sstable.Descriptor;
 import org.apache.cassandra.io.sstable.ColumnStats;
 
-public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEntry
+public class ColumnFamily implements IRowCacheEntry, Iterable<Column>
 {
     /* The column serializer for this Column Family. Create based on config. */
     public static final ColumnFamilySerializer serializer = new ColumnFamilySerializer();
     private final CFMetaData cfm;
+    protected final ISortedColumns columns;
 
     public static ColumnFamily create(UUID cfId)
     {
@@ -71,9 +78,9 @@ public class ColumnFamily extends AbstractColumnContainer implements IRowCacheEn
         return new ColumnFamily(cfm, factory.create(cfm.comparator, reversedInsertOrder));
     }
 
-    protected ColumnFamily(CFMetaData cfm, ISortedColumns map)
+    protected ColumnFamily(CFMetaData cfm, ISortedColumns columns)
     {
-        super(map);
+        this.columns = columns;
         assert cfm != null;
         this.cfm = cfm;
     }
@@ -196,17 +203,6 @@ public class ColumnFamily extends AbstractColumnContainer implements
IRowCacheEn
         return null;
     }
 
-    /** the size of user-provided data, not including internal overhead */
-    int dataSize()
-    {
-        int size = deletionInfo().dataSize();
-        for (Column column : columns)
-        {
-            size += column.dataSize();
-        }
-        return size;
-    }
-
     public long maxTimestamp()
     {
         long maxTimestamp = deletionInfo().maxTimestamp();
@@ -319,4 +315,156 @@ public class ColumnFamily extends AbstractColumnContainer implements
IRowCacheEn
         }
         return new ColumnStats(getColumnCount(), minTimestampSeen, maxTimestampSeen, maxLocalDeletionTime,
tombstones);
     }
+
+    public void delete(ColumnFamily cc2)
+    {
+        delete(cc2.columns.getDeletionInfo());
+    }
+
+    public void delete(DeletionInfo delInfo)
+    {
+        columns.delete(delInfo);
+    }
+
+    // Contrarily to delete(), this will use the provided info even if those
+    // are older that the current ones. Used for SuperColumn in QueryFilter.
+    // delete() is probably the right method in all other cases.
+    public void setDeletionInfo(DeletionInfo delInfo)
+    {
+        columns.setDeletionInfo(delInfo);
+    }
+
+    public boolean isMarkedForDelete()
+    {
+        return !deletionInfo().isLive();
+    }
+
+    public DeletionInfo deletionInfo()
+    {
+        return columns.getDeletionInfo();
+    }
+
+    public AbstractType<?> getComparator()
+    {
+        return columns.getComparator();
+    }
+
+    /**
+     * Drops expired row-level tombstones.  Normally, these are dropped once the row no longer
exists, but
+     * if new columns are inserted into the row post-deletion, they can keep the row tombstone
alive indefinitely,
+     * with non-intuitive results.  See https://issues.apache.org/jira/browse/CASSANDRA-2317
+     */
+    public void maybeResetDeletionTimes(int gcBefore)
+    {
+        columns.maybeResetDeletionTimes(gcBefore);
+    }
+
+    public long addAllWithSizeDelta(ColumnFamily cc, Allocator allocator, Function<Column,
Column> transformation, SecondaryIndexManager.Updater indexer)
+    {
+        return columns.addAllWithSizeDelta(cc.columns, allocator, transformation, indexer);
+    }
+
+    public void addAll(ColumnFamily cc, Allocator allocator, Function<Column, Column>
transformation)
+    {
+        columns.addAll(cc.columns, allocator, transformation);
+    }
+
+    public void addAll(ColumnFamily cc, Allocator allocator)
+    {
+        addAll(cc, allocator, Functions.<Column>identity());
+    }
+
+    public void addColumn(Column column)
+    {
+        addColumn(column, HeapAllocator.instance);
+    }
+
+    public void addColumn(Column column, Allocator allocator)
+    {
+        columns.addColumn(column, allocator);
+    }
+
+    public Column getColumn(ByteBuffer name)
+    {
+        return columns.getColumn(name);
+    }
+
+    public boolean replace(Column oldColumn, Column newColumn)
+    {
+        return columns.replace(oldColumn, newColumn);
+    }
+
+    /*
+    * Note that for some of the implementation backing the container, the
+    * return set may not have implementation for tailSet, headSet and subSet.
+    * See ColumnNamesSet in ArrayBackedSortedColumns for more details.
+    */
+    public SortedSet<ByteBuffer> getColumnNames()
+    {
+        return columns.getColumnNames();
+    }
+
+    public Collection<Column> getSortedColumns()
+    {
+        return columns.getSortedColumns();
+    }
+
+    public Collection<Column> getReverseSortedColumns()
+    {
+        return columns.getReverseSortedColumns();
+    }
+
+    public void remove(ByteBuffer columnName)
+    {
+        columns.removeColumn(columnName);
+    }
+
+    public int getColumnCount()
+    {
+        return columns.size();
+    }
+
+    public boolean isEmpty()
+    {
+        return columns.isEmpty();
+    }
+
+    public boolean hasOnlyTombstones()
+    {
+        for (Column column : columns)
+        {
+            if (column.isLive())
+                return false;
+        }
+        return true;
+    }
+
+    public Iterator<Column> iterator()
+    {
+        return columns.iterator();
+    }
+
+    public Iterator<Column> iterator(ColumnSlice[] slices)
+    {
+        return columns.iterator(slices);
+    }
+
+    public Iterator<Column> reverseIterator(ColumnSlice[] slices)
+    {
+        return columns.reverseIterator(slices);
+    }
+
+    public boolean hasIrrelevantData(int gcBefore)
+    {
+        // Do we have gcable deletion infos?
+        if (!deletionInfo().purge(gcBefore).equals(deletionInfo()))
+            return true;
+
+        // Do we have colums that are either deleted by the container or gcable tombstone?
+        for (Column column : columns)
+            if (deletionInfo().isDeleted(column) || column.hasIrrelevantData(gcBefore))
+                return true;
+
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/255db500/src/java/org/apache/cassandra/db/ISortedColumns.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ISortedColumns.java b/src/java/org/apache/cassandra/db/ISortedColumns.java
index df288aa..7214eb1 100644
--- a/src/java/org/apache/cassandra/db/ISortedColumns.java
+++ b/src/java/org/apache/cassandra/db/ISortedColumns.java
@@ -28,7 +28,6 @@ import com.google.common.base.Function;
 import org.apache.cassandra.db.filter.ColumnSlice;
 import org.apache.cassandra.db.index.SecondaryIndexManager;
 import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.io.util.IIterableColumns;
 import org.apache.cassandra.utils.Allocator;
 
 /**
@@ -38,7 +37,7 @@ import org.apache.cassandra.utils.Allocator;
  * Whether the implementation is thread safe or not is left to the
  * implementing classes.
  */
-public interface ISortedColumns extends IIterableColumns
+public interface ISortedColumns extends Iterable<Column>
 {
     /**
      * Shallow cloning of the column map.
@@ -153,6 +152,11 @@ public interface ISortedColumns extends IIterableColumns
      */
     public boolean isInsertReversed();
 
+    /**
+     * @return the comparator whose sorting order the contained columns conform to
+     */
+    public AbstractType<?> getComparator();
+
     public interface Factory
     {
         /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/255db500/src/java/org/apache/cassandra/io/util/IIterableColumns.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/IIterableColumns.java b/src/java/org/apache/cassandra/io/util/IIterableColumns.java
deleted file mode 100644
index 68c5645..0000000
--- a/src/java/org/apache/cassandra/io/util/IIterableColumns.java
+++ /dev/null
@@ -1,28 +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.io.util;
-
-import org.apache.cassandra.db.Column;
-import org.apache.cassandra.db.marshal.AbstractType;
-
-public interface IIterableColumns extends Iterable<Column>
-{
-    public int getEstimatedColumnCount();
-
-    AbstractType<?> getComparator();
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/255db500/src/java/org/apache/cassandra/tools/SSTableExport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableExport.java b/src/java/org/apache/cassandra/tools/SSTableExport.java
index 726da5c..f3ee10b 100644
--- a/src/java/org/apache/cassandra/tools/SSTableExport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableExport.java
@@ -43,7 +43,6 @@ import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.AbstractColumnContainer;
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.CounterColumn;
 import org.apache.cassandra.db.DecoratedKey;
@@ -118,22 +117,17 @@ public class SSTableExport
      *
      * @param out
      *            The output steam to write data
-     * @param columnFamily
+     * @param cf
      *            to which the metadata belongs
      */
-    private static void writeMeta(PrintStream out, AbstractColumnContainer columnContainer)
+    private static void writeMeta(PrintStream out, ColumnFamily cf)
     {
-        if (columnContainer instanceof ColumnFamily)
+        if (!cf.deletionInfo().equals(DeletionInfo.LIVE))
         {
-            ColumnFamily columnFamily = (ColumnFamily) columnContainer;
-            if (!columnFamily.deletionInfo().equals(DeletionInfo.LIVE))
-            {
-                // begin meta
-                writeKey(out, "metadata");
-                writeDeletionInfo(out, columnFamily.deletionInfo().getTopLevelDeletion());
-                out.print(",");
-            }
-            return;
+            // begin meta
+            writeKey(out, "metadata");
+            writeDeletionInfo(out, cf.deletionInfo().getTopLevelDeletion());
+            out.print(",");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/255db500/src/java/org/apache/cassandra/tools/SSTableImport.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableImport.java b/src/java/org/apache/cassandra/tools/SSTableImport.java
index 06ccaa7..be31540 100644
--- a/src/java/org/apache/cassandra/tools/SSTableImport.java
+++ b/src/java/org/apache/cassandra/tools/SSTableImport.java
@@ -38,7 +38,6 @@ import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.exceptions.ConfigurationException;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.Schema;
-import org.apache.cassandra.db.AbstractColumnContainer;
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.ColumnFamilyType;
 import org.apache.cassandra.db.CounterColumn;
@@ -270,7 +269,7 @@ public class SSTableImport
         {
             Map<?, ?> unparsedDeletionInfo = (Map<?, ?>) map.get("deletionInfo");
             Number number = (Number) unparsedDeletionInfo.get("markedForDeleteAt");
-            long markedForDeleteAt = number instanceof Long ? (Long) number : ((Integer)
number).longValue();
+            long markedForDeleteAt = number instanceof Long ? (Long) number : number.longValue();
             int localDeletionTime = (Integer) unparsedDeletionInfo.get("localDeletionTime");
             if (superColumnName == null)
                 cf.setDeletionInfo(new DeletionInfo(markedForDeleteAt, localDeletionTime));


Mime
View raw message