cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r947121 - in /cassandra/trunk/src/java/org/apache/cassandra: config/CFMetaData.java config/DatabaseDescriptor.java db/ColumnFamily.java db/Table.java db/commitlog/CommitLog.java db/commitlog/CommitLogHeader.java
Date Fri, 21 May 2010 18:39:20 GMT
Author: gdusbabek
Date: Fri May 21 18:39:19 2010
New Revision: 947121

URL: http://svn.apache.org/viewvc?rev=947121&view=rev
Log:
add easy reverse lookup from id cf. Patch by Stu Hood, reviewed by Gary Dusbabek. CASSANDRA-956

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
    cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
    cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java
    cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
    cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
    cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogHeader.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java?rev=947121&r1=947120&r2=947121&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java Fri May 21 18:39:19
2010
@@ -38,6 +38,8 @@ import org.apache.cassandra.db.ColumnFam
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.utils.Pair;
 
+import com.google.common.collect.*;
+
 public final class CFMetaData
 {
     public final static double DEFAULT_READ_REPAIR_CHANCE = 1.0;
@@ -50,29 +52,43 @@ public final class CFMetaData
     
     private static final Map<Integer, String> currentCfNames = new HashMap<Integer,
String>();
     
-    private static final Map<Pair<String, String>, Integer> cfIdMap = new HashMap<Pair<String,
String>, Integer>();
+    private static final BiMap<Pair<String, String>, Integer> cfIdMap = HashBiMap.<Pair<String,
String>, Integer>create();
     
     public static final CFMetaData StatusCf = new CFMetaData(Table.SYSTEM_TABLE, SystemTable.STATUS_CF,
ColumnFamilyType.Standard, new UTF8Type(), null, "persistent metadata for the local node",
0, false, 0.01, 0);
     public static final CFMetaData HintsCf = new CFMetaData(Table.SYSTEM_TABLE, HintedHandOffManager.HINTS_CF,
ColumnFamilyType.Super, new UTF8Type(), new BytesType(), "hinted handoff data", 0, false,
0.01, 1);
     public static final CFMetaData MigrationsCf = new CFMetaData(Table.SYSTEM_TABLE, Migration.MIGRATIONS_CF,
ColumnFamilyType.Standard, new TimeUUIDType(), null, "individual schema mutations", 0, false,
2);
     public static final CFMetaData SchemaCf = new CFMetaData(Table.SYSTEM_TABLE, Migration.SCHEMA_CF,
ColumnFamilyType.Standard, new UTF8Type(), null, "current state of the schema", 0, false,
3);
 
-    public static final Map<Pair<String, String>, Integer> getCfIdMap()
+    /**
+     * @return An immutable mapping of (ksname,cfname) to id.
+     */
+    public static final Map<Pair<String, String>, Integer> getCfToIdMap()
+    {
+        return Collections.unmodifiableMap(cfIdMap);
+    }
+    
+    /**
+     * @return An immutable mapping of id to (ksname,cfname).
+     */
+    public static final Map<Integer, Pair<String, String>> getIdToCfMap()
     {
-        return Collections.unmodifiableMap(cfIdMap);    
+        return Collections.unmodifiableMap(cfIdMap.inverse());
     }
     
-    public static final String getCurrentName(int id)
+    /**
+     * @return The (ksname,cfname) pair for the given id, or null if it has been dropped.
+     */
+    public static final Pair<String,String> getCF(int id)
     {
-        return currentCfNames.get(id);
+        return cfIdMap.inverse().get(Integer.valueOf(id));
     }
     
-    public static final int getId(String table, String cfName)
+    /**
+     * @return The id for the given (ksname,cfname) pair, or null if it has been dropped.
+     */
+    public static final Integer getId(String table, String cfName)
     {
-        Integer id = cfIdMap.get(new Pair<String, String>(table, cfName));
-        if (id == null)
-            throw new IllegalArgumentException(String.format("Illegal table/cf pair (%s.%s)",
table, cfName));
-        return id;
+        return cfIdMap.get(new Pair<String, String>(table, cfName));
     }
     
     // this gets called after initialization to make sure that id generation happens properly.

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=947121&r1=947120&r2=947121&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java Fri May 21
18:39:19 2010
@@ -32,6 +32,7 @@ import org.apache.cassandra.locator.Abst
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.Pair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.cassandra.locator.IEndpointSnitch;
@@ -655,6 +656,14 @@ public class DatabaseDescriptor
         return ksm.cfMetaData().get(cfName);
     }
     
+    public static CFMetaData getCFMetaData(int cfid)
+    {
+        Pair<String,String> cf = CFMetaData.getCF(cfid);
+        if (cf == null)
+            return null;
+        return getCFMetaData(cf.left, cf.right);
+    }
+
     public static ColumnFamilyType getColumnFamilyType(String tableName, String cfName)
     {
         assert tableName != null && cfName != null;

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java?rev=947121&r1=947120&r2=947121&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java Fri May 21 18:39:19
2010
@@ -58,7 +58,9 @@ public class ColumnFamily implements ICo
         ColumnFamilyType cfType = DatabaseDescriptor.getColumnFamilyType(tableName, cfName);
         AbstractType comparator = DatabaseDescriptor.getComparator(tableName, cfName);
         AbstractType subcolumnComparator = DatabaseDescriptor.getSubComparator(tableName,
cfName);
-        int id = CFMetaData.getId(tableName, cfName);
+        Integer id = CFMetaData.getId(tableName, cfName);
+        if (id == null)
+            throw new RuntimeException("Cannot create ColumnFamily for non-existant table/cf
pair.");
         return new ColumnFamily(cfName, cfType, comparator, subcolumnComparator, id);
     }
 

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=947121&r1=947120&r2=947121&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Fri May 21 18:39:19 2010
@@ -132,7 +132,10 @@ public class Table 
     @Deprecated
     public ColumnFamilyStore getColumnFamilyStore(String cfName)
     {
-        return columnFamilyStores.get(CFMetaData.getId(name, cfName));
+        Integer id = CFMetaData.getId(name, cfName);
+        if (id == null)
+            throw new IllegalArgumentException(String.format("Unknown table/cf pair (%s.%s)",
name, cfName));
+        return columnFamilyStores.get(id);
     }
 
     /**

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java?rev=947121&r1=947120&r2=947121&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLog.java Fri May 21 18:39:19
2010
@@ -250,12 +250,9 @@ public class CommitLog
                         // thing based on the cfid instead.
                         for (ColumnFamily columnFamily : columnFamilies)
                         {
-                            // make sure to use the current name of the cf (null means its
been dropped).
-                            String currentName = CFMetaData.getCurrentName(columnFamily.id());
-                            if (currentName == null)
+                            if (CFMetaData.getCF(columnFamily.id()) == null)
+                                // null means the cf has been dropped
                                 continue;
-                            else if (!currentName.equals(columnFamily.name()))
-                                columnFamily.rename(currentName);
                             
                             if (clHeader.isDirty(columnFamily.id()) && entryLocation
>= clHeader.getPosition(columnFamily.id()))
                                 newRm.add(columnFamily);

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogHeader.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogHeader.java?rev=947121&r1=947120&r2=947121&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogHeader.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/commitlog/CommitLogHeader.java Fri May
21 18:39:19 2010
@@ -56,7 +56,7 @@ class CommitLogHeader
     
     CommitLogHeader()
     {
-        this(new HashMap<Integer, Integer>(), CFMetaData.getCfIdMap().size());
+        this(new HashMap<Integer, Integer>(), CFMetaData.getCfToIdMap().size());
     }
     
     /*



Mime
View raw message