Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use isSuper instead of DatabaseDescriptor.getColumnType.

patch by jbellis; reviewed by Sandeep Tata for #85
  • Loading branch information...
commit d5971e2c5e7e16dd13fbb1005f36a1aa1c0e97e2 1 parent 82166bd
authored April 17, 2009
23  src/org/apache/cassandra/db/ColumnFamily.java
@@ -49,6 +49,7 @@
49 49
     private static Logger logger_ = Logger.getLogger( ColumnFamily.class );
50 50
     private static Map<String, String> columnTypes_ = new HashMap<String, String>();
51 51
     private static Map<String, String> indexTypes_ = new HashMap<String, String>();
  52
+    private String type_;
52 53
 
53 54
     static
54 55
     {
@@ -122,15 +123,10 @@ public static String getColumnSortProperty(String columnIndexProperty)
122 123
 		return columnComparator_;
123 124
 	}
124 125
 
125  
-    public ColumnFamily(String cfName)
126  
-    {
127  
-        name_ = cfName;
128  
-        createColumnFactoryAndColumnSerializer();
129  
-    }
130  
-
131 126
     public ColumnFamily(String cfName, String columnType)
132 127
     {
133  
-        this(cfName);
  128
+        name_ = cfName;
  129
+        type_ = columnType;
134 130
         createColumnFactoryAndColumnSerializer(columnType);
135 131
     }
136 132
 
@@ -162,7 +158,7 @@ void createColumnFactoryAndColumnSerializer()
162 158
 
163 159
     ColumnFamily cloneMe()
164 160
     {
165  
-    	ColumnFamily cf = new ColumnFamily(name_);
  161
+    	ColumnFamily cf = new ColumnFamily(name_, type_);
166 162
     	cf.markedForDeleteAt = markedForDeleteAt;
167 163
     	cf.columns_ = columns_.cloneMe();
168 164
     	return cf;
@@ -220,7 +216,7 @@ int getColumnCount()
220 216
 
221 217
     public boolean isSuper()
222 218
     {
223  
-        return DatabaseDescriptor.getColumnType(name_).equals("Super");
  219
+        return type_.equals("Super");
224 220
     }
225 221
 
226 222
     public void addColumn(String name, byte[] value)
@@ -329,7 +325,7 @@ void repair(ColumnFamily columnFamily)
329 325
      */
330 326
     ColumnFamily diff(ColumnFamily columnFamily)
331 327
     {
332  
-    	ColumnFamily cfDiff = new ColumnFamily(columnFamily.name());
  328
+    	ColumnFamily cfDiff = new ColumnFamily(columnFamily.name(), columnFamily.type_);
333 329
         Map<String, IColumn> columns = columnFamily.getColumns();
334 330
         Set<String> cNames = columns.keySet();
335 331
 
@@ -421,6 +417,11 @@ public long getMarkedForDeleteAt() {
421 417
         return markedForDeleteAt;
422 418
     }
423 419
 
  420
+    public String type()
  421
+    {
  422
+        return type_;
  423
+    }
  424
+
424 425
     public static class ColumnFamilySerializer implements ICompactSerializer2<ColumnFamily>
425 426
     {
426 427
         /*
@@ -473,7 +474,7 @@ public void serialize(ColumnFamily columnFamily, DataOutputStream dos) throws IO
473 474
         private ColumnFamily defreezeColumnFamily(DataInputStream dis) throws IOException
474 475
         {
475 476
             String name = dis.readUTF();
476  
-            ColumnFamily cf = new ColumnFamily(name);
  477
+            ColumnFamily cf = new ColumnFamily(name, DatabaseDescriptor.getColumnFamilyType(name));
477 478
             cf.delete(dis.readLong());
478 479
             return cf;
479 480
         }
16  src/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -70,8 +70,9 @@
70 70
     private static int compactionMemoryThreshold_ = 1 << 30;
71 71
     private static Logger logger_ = Logger.getLogger(ColumnFamilyStore.class);
72 72
 
73  
-    private String table_;
74  
-    public String columnFamily_;
  73
+    private final String table_;
  74
+    public final String columnFamily_;
  75
+    private final boolean isSuper_;
75 76
     
76 77
     private volatile Integer memtableSwitchCount = 0;
77 78
 
@@ -91,10 +92,11 @@
91 92
     /* Flag indicates if a compaction is in process */
92 93
     private AtomicBoolean isCompacting_ = new AtomicBoolean(false);
93 94
 
94  
-    ColumnFamilyStore(String table, String columnFamily, int indexValue) throws IOException
  95
+    ColumnFamilyStore(String table, String columnFamily, boolean isSuper, int indexValue) throws IOException
95 96
     {
96 97
         table_ = table;
97 98
         columnFamily_ = columnFamily;
  99
+        isSuper_ = isSuper;
98 100
         fileIndexGenerator_.set(indexValue);
99 101
         memtable_ = new AtomicReference<Memtable>(new Memtable(table_, columnFamily_));
100 102
         binaryMemtable_ = new AtomicReference<BinaryMemtable>(new BinaryMemtable(table_, columnFamily_));
@@ -130,7 +132,7 @@ public static ColumnFamilyStore getColumnFamilyStore(String table, String column
130 132
         Collections.sort(indices);
131 133
         int value = (indices.size() > 0) ? (indices.get(indices.size() - 1)) : 0;
132 134
 
133  
-        ColumnFamilyStore cfs = new ColumnFamilyStore(table, columnFamily, value);
  135
+        ColumnFamilyStore cfs = new ColumnFamilyStore(table, columnFamily, "Super".equals(DatabaseDescriptor.getColumnType(columnFamily)), value);
134 136
 
135 137
         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
136 138
         try
@@ -579,8 +581,8 @@ static ColumnFamily resolve(List<ColumnFamily> columnFamilies)
579 581
             return null;
580 582
 
581 583
         // start from nothing so that we don't include potential deleted columns from the first instance
582  
-        String cfname = columnFamilies.get(0).name();
583  
-        ColumnFamily cf = new ColumnFamily(cfname);
  584
+        ColumnFamily cf0 = columnFamilies.get(0);
  585
+        ColumnFamily cf = new ColumnFamily(cf0.name(), cf0.type());
584 586
 
585 587
         // merge
586 588
         for (ColumnFamily cf2 : columnFamilies)
@@ -1383,7 +1385,7 @@ void  doFileCompaction(List<String> files,  int minBufferSize) throws IOExceptio
1383 1385
 
1384 1386
     public boolean isSuper()
1385 1387
     {
1386  
-        return DatabaseDescriptor.getColumnType(getColumnFamilyName()).equals("Super");
  1388
+        return isSuper_;
1387 1389
     }
1388 1390
 
1389 1391
     public void flushMemtableOnRecovery() throws IOException
3  src/org/apache/cassandra/db/CountFilter.java
@@ -49,8 +49,7 @@ public ColumnFamily filter(String cfNameParam, ColumnFamily columnFamily)
49 49
         if ( columnFamily == null )
50 50
             return columnFamily;
51 51
 
52  
-		String cfName = columnFamily.name();
53  
-		ColumnFamily filteredCf = new ColumnFamily(cfName);
  52
+        ColumnFamily filteredCf = new ColumnFamily(columnFamily.name(), columnFamily.type());
54 53
 		if( countLimit_ <= 0 )
55 54
 		{
56 55
 			isDone_ = true;
2  src/org/apache/cassandra/db/DBManager.java
@@ -130,7 +130,7 @@ public DBManager() throws IOException
130 130
 
131 131
             String key = FBUtilities.getHostName();
132 132
             row = new Row(key);
133  
-            ColumnFamily cf = new ColumnFamily(SystemTable.cfName_);
  133
+            ColumnFamily cf = new ColumnFamily(SystemTable.cfName_, "Standard");
134 134
             cf.addColumn(new Column(SystemTable.token_, token.toByteArray()));
135 135
             cf.addColumn(new Column(SystemTable.generation_, BasicUtilities.intToByteArray(generation)));
136 136
             row.addColumnFamily(cf);
4  src/org/apache/cassandra/db/IdentityFilter.java
@@ -25,13 +25,13 @@ public ColumnFamily filter(String cfString, ColumnFamily columnFamily)
25 25
     	if( columnFamily == null )
26 26
     		return columnFamily;
27 27
 		String cfName = columnFamily.name();
28  
-		if ( values.length == 2 && !DatabaseDescriptor.getColumnType(cfName).equals("Super") )
  28
+		if (values.length == 2 && !columnFamily.isSuper())
29 29
 		{
30 30
 			Collection<IColumn> columns = columnFamily.getAllColumns();
31 31
 			if(columns.size() >= 1)
32 32
 				isDone_ = true;
33 33
 		}
34  
-		if ( values.length == 3 && DatabaseDescriptor.getColumnType(cfName).equals("Super"))
  34
+		if (values.length == 3 && columnFamily.isSuper())
35 35
 		{
36 36
     		Collection<IColumn> columns = columnFamily.getAllColumns();
37 37
     		for(IColumn column : columns)
4  src/org/apache/cassandra/db/Memtable.java
@@ -314,7 +314,7 @@ ColumnFamily getLocalCopy(String key, String columnFamilyColumn, IFilter filter)
314 314
                 IColumn column = cFamily.getColumn(values[1]); // super or normal column
315 315
                 if (column != null )
316 316
                 {
317  
-                    columnFamily = new ColumnFamily(cfName_);
  317
+                    columnFamily = new ColumnFamily(cfName_, cFamily.type());
318 318
                     columnFamily.addColumn(column);
319 319
                 }
320 320
         	}
@@ -327,7 +327,7 @@ ColumnFamily getLocalCopy(String key, String columnFamilyColumn, IFilter filter)
327 327
                     IColumn subColumn = superColumn.getSubColumn(values[2]);
328 328
                     if (subColumn != null)
329 329
                     {
330  
-                        columnFamily = new ColumnFamily(cfName_);
  330
+                        columnFamily = new ColumnFamily(cfName_, cFamily.type());
331 331
                         columnFamily.addColumn(values[1] + ":" + values[2], subColumn.value(), subColumn.timestamp(), subColumn.isMarkedForDelete());
332 332
                     }
333 333
                 }
5  src/org/apache/cassandra/db/NamesFilter.java
@@ -46,8 +46,7 @@ public ColumnFamily filter(String cf, ColumnFamily columnFamily)
46 46
             return columnFamily;
47 47
         }
48 48
     	String[] values = RowMutation.getColumnAndColumnFamily(cf);
49  
-		String cfName = columnFamily.name();
50  
-		ColumnFamily filteredCf = new ColumnFamily(cfName);
  49
+        ColumnFamily filteredCf = new ColumnFamily(columnFamily.name(), columnFamily.type());
51 50
 		if( values.length == 1 )
52 51
 		{
53 52
 			Collection<IColumn> columns = columnFamily.getAllColumns();
@@ -64,7 +63,7 @@ public ColumnFamily filter(String cf, ColumnFamily columnFamily)
64 63
 				}
65 64
 			}
66 65
 		}
67  
-		else if ( values.length == 2 && DatabaseDescriptor.getColumnType(cfName).equals("Super"))
  66
+		else if (values.length == 2 && columnFamily.isSuper())
68 67
 		{
69 68
     		Collection<IColumn> columns = columnFamily.getAllColumns();
70 69
     		for(IColumn column : columns)
2  src/org/apache/cassandra/db/RangeFilter.java
@@ -63,7 +63,7 @@ public ColumnFamily filter(String cfName, ColumnFamily cf)
63 63
             return null;
64 64
         }
65 65
 
66  
-        ColumnFamily filteredColumnFamily = new ColumnFamily(cfName);
  66
+        ColumnFamily filteredColumnFamily = new ColumnFamily(cfName, cf.type());
67 67
 
68 68
         Collection<IColumn> columns = cf.getAllColumns();
69 69
         for (IColumn c : columns)
2  src/org/apache/cassandra/db/Row.java
@@ -120,7 +120,7 @@ public void repair(Row row)
120 120
             ColumnFamily cf = columnFamilies_.get(cfName);
121 121
             if (cf == null)
122 122
             {
123  
-                cf = new ColumnFamily(cfName);
  123
+                cf = new ColumnFamily(cfName, cf.type());
124 124
                 columnFamilies_.put(cfName, cf);
125 125
             }
126 126
             cf.repair(columnFamilies.get(cfName));
12  src/org/apache/cassandra/db/RowMutation.java
@@ -185,19 +185,19 @@ public void delete(String columnFamilyColumn, long timestamp)
185 185
 
186 186
         ColumnFamily columnFamily = modifications_.get(cfName);
187 187
         if (columnFamily == null)
188  
-            columnFamily = new ColumnFamily(cfName);
  188
+            columnFamily = new ColumnFamily(cfName, DatabaseDescriptor.getColumnType(cfName));
189 189
         if (values.length == 2)
190 190
         {
191  
-            if (DatabaseDescriptor.getColumnFamilyType(cfName).equals("Standard"))
192  
-            {
193  
-                columnFamily.addColumn(values[1], ArrayUtils.EMPTY_BYTE_ARRAY, timestamp, true);
194  
-            }
195  
-            else
  191
+            if (columnFamily.isSuper())
196 192
             {
197 193
                 SuperColumn sc = new SuperColumn(values[1]);
198 194
                 sc.markForDeleteAt(timestamp);
199 195
                 columnFamily.addColumn(sc);
200 196
             }
  197
+            else
  198
+            {
  199
+                columnFamily.addColumn(values[1], ArrayUtils.EMPTY_BYTE_ARRAY, timestamp, true);
  200
+            }
201 201
         }
202 202
         else if (values.length == 3)
203 203
         {
7  src/org/apache/cassandra/db/TimeFilter.java
@@ -51,9 +51,8 @@ public ColumnFamily filter(String cf, ColumnFamily columnFamily)
51 51
     		return columnFamily;
52 52
 
53 53
         String[] values = RowMutation.getColumnAndColumnFamily(cf);
54  
-		String cfName = columnFamily.name();
55  
-		ColumnFamily filteredCf = new ColumnFamily(cfName);
56  
-		if( values.length == 1 && !DatabaseDescriptor.getColumnType(cfName).equals("Super"))
  54
+        ColumnFamily filteredCf = new ColumnFamily(columnFamily.name(), columnFamily.type());
  55
+		if (values.length == 1 && !columnFamily.isSuper())
57 56
 		{
58 57
     		Collection<IColumn> columns = columnFamily.getAllColumns();
59 58
     		int i =0; 
@@ -74,7 +73,7 @@ public ColumnFamily filter(String cf, ColumnFamily columnFamily)
74 73
     			isDone_ = true;
75 74
     		}
76 75
 		}    	
77  
-    	else if ( values.length == 2 && DatabaseDescriptor.getColumnType(cfName).equals("Super") )
  76
+    	else if (values.length == 2 && columnFamily.isSuper())
78 77
     	{
79 78
     		/* 
80 79
     		 * TODO : For super columns we need to re-visit this issue.
3  src/org/apache/cassandra/net/http/ColumnFamilyFormatter.java
@@ -35,9 +35,8 @@ public void printColumnFamily(StringBuilder sb, ColumnFamily cf)
35 35
     	// first print the column family specific data
36 36
     	sb.append("ColumnFamily = " + cf.name() + "<br>");
37 37
 
38  
-    	String columnFamilyType = DatabaseDescriptor.getColumnType(cf.name());
39 38
     	Collection<IColumn> cols = cf.getAllColumns();
40  
-    	if("Super".equals(columnFamilyType))
  39
+    	if (cf.isSuper())
41 40
     	{
42 41
     		printSuperColumns(sb, cols);
43 42
     	}

0 notes on commit d5971e2

Please sign in to comment.
Something went wrong with that request. Please try again.