cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject git commit: (cql3) always use composite types by default patch by Sylvain Lebresne; reviewed by Pavel Yaskevich for CASSANDRA-4329
Date Sat, 30 Jun 2012 13:22:14 GMT
Updated Branches:
  refs/heads/trunk 7c59d8f4d -> 44f4cac62


(cql3) always use composite types by default
patch by Sylvain Lebresne; reviewed by Pavel Yaskevich for CASSANDRA-4329


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

Branch: refs/heads/trunk
Commit: 44f4cac62e33238461274b6aec6790d623b70484
Parents: 7c59d8f
Author: Pavel Yaskevich <xedin@apache.org>
Authored: Sat Jun 30 13:12:32 2012 +0000
Committer: Pavel Yaskevich <xedin@apache.org>
Committed: Sat Jun 30 13:12:32 2012 +0000

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../org/apache/cassandra/config/CFMetaData.java    |    2 +-
 .../org/apache/cassandra/cql3/CFDefinition.java    |    4 +
 .../org/apache/cassandra/cql3/QueryProcessor.java  |    2 +
 .../apache/cassandra/cql3/UntypedResultSet.java    |   16 ++
 .../statements/CreateColumnFamilyStatement.java    |   30 ++--
 src/java/org/apache/cassandra/db/Column.java       |    2 +-
 src/java/org/apache/cassandra/db/SystemTable.java  |  181 +++++----------
 8 files changed, 94 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1700ee7..1955476 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -23,6 +23,7 @@
  * stream compressed sstables directly with java nio (CASSANDRA-4297)
  * Support multiple ranges in SliceQueryFilter (CASSANDRA-3885)
  * Add column metadata to system column families (CASSANDRA-4018)
+ * (cql3) always use composite types by default (CASSANDRA-4329)
 
 
 1.1.3

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index 4b77156..1df239e 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -107,7 +107,7 @@ public final class CFMetaData
                                                                  + "durable_writes boolean,"
                                                                  + "strategy_class text,"
                                                                  + "strategy_options text"
-                                                                 + ") WITH COMMENT='keyspace
definitions' AND gc_grace_seconds=8640");
+                                                                 + ") WITH COMPACT STORAGE
AND COMMENT='keyspace definitions' AND gc_grace_seconds=8640");
     public static final CFMetaData SchemaColumnFamiliesCf = compile(9, "CREATE TABLE " +
SystemTable.SCHEMA_COLUMNFAMILIES_CF + "("
                                                                      + "keyspace_name text,"
                                                                      + "columnfamily_name
text,"

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/cql3/CFDefinition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CFDefinition.java b/src/java/org/apache/cassandra/cql3/CFDefinition.java
index 52ffd6f..9ee1dbf 100644
--- a/src/java/org/apache/cassandra/cql3/CFDefinition.java
+++ b/src/java/org/apache/cassandra/cql3/CFDefinition.java
@@ -50,6 +50,10 @@ public class CFDefinition implements Iterable<CFDefinition.Name>
     public final Map<ColumnIdentifier, Name> metadata = new TreeMap<ColumnIdentifier,
Name>();
 
     public final boolean isComposite;
+    // Note that isCompact means here that no componet of the comparator correspond to the
column names
+    // defined in the CREATE TABLE QUERY. This is not exactly equivalent to the 'WITH COMPACT
STORAGE'
+    // option when creating a table in that "static CF" without a composite type will have
isCompact == false
+    // even though one must use 'WITH COMPACT STORAGE' to declare them.
     public final boolean isCompact;
 
     public CFDefinition(CFMetaData cfm)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index f1da676..ef8df6b 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -126,6 +126,8 @@ public class QueryProcessor
         {
             ClientState state = new ClientState();
             CqlResult result = processStatement(getStatement(query, state).statement, state,
Collections.<ByteBuffer>emptyList());
+            if (result.rows == null)
+                return null;
             return new UntypedResultSet(result.rows);
         }
         catch (UnavailableException e)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/cql3/UntypedResultSet.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/UntypedResultSet.java b/src/java/org/apache/cassandra/cql3/UntypedResultSet.java
index 1280851..73e43d0 100644
--- a/src/java/org/apache/cassandra/cql3/UntypedResultSet.java
+++ b/src/java/org/apache/cassandra/cql3/UntypedResultSet.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 import com.google.common.collect.AbstractIterator;
 
@@ -42,6 +43,16 @@ public class UntypedResultSet implements Iterable<UntypedResultSet.Row>
         this.cqlRows = cqlRows;
     }
 
+    public boolean isEmpty()
+    {
+        return cqlRows.isEmpty();
+    }
+
+    public int size()
+    {
+        return cqlRows.size();
+    }
+
     public Row one()
     {
         if (cqlRows.size() != 1)
@@ -110,6 +121,11 @@ public class UntypedResultSet implements Iterable<UntypedResultSet.Row>
             return InetAddressType.instance.compose(data.get(column));
         }
 
+        public UUID getUUID(String column)
+        {
+            return UUIDType.instance.compose(data.get(column));
+        }
+
         @Override
         public String toString()
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
index 56ce563..1ad1007 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
@@ -19,6 +19,7 @@ package org.apache.cassandra.cql3.statements;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -176,7 +177,7 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
                     throw new InvalidRequestException(String.format("counter type is not
supported for PRIMARY KEY part %s", stmt.keyAlias));
 
                 // Handle column aliases
-                if (columnAliases != null && !columnAliases.isEmpty())
+                if (!columnAliases.isEmpty())
                 {
                     // If we use compact storage and have only one alias, it is a
                     // standard "dynamic" CF, otherwise it's a composite
@@ -210,20 +211,17 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
                 }
                 else
                 {
-                    stmt.comparator = CFDefinition.definitionType;
+                    if (useCompactStorage)
+                        stmt.comparator = CFDefinition.definitionType;
+                    else
+                        stmt.comparator = CompositeType.getInstance(Collections.<AbstractType<?>>singletonList(CFDefinition.definitionType));
                 }
 
-                if (useCompactStorage)
-                {
-                    // There should at least have been one column alias
-                    if (stmt.columnAliases.isEmpty())
-                        throw new InvalidRequestException("COMPACT STORAGE requires at least
one column part of the clustering key, none found");
-                    // There should be only one column definition remaining, which gives
us the default validator.
-                    if (stmt.columns.isEmpty())
-                        throw new InvalidRequestException("COMPACT STORAGE requires one definition
not part of the PRIMARY KEY, none found");
-                    if (stmt.columns.size() > 1)
-                        throw new InvalidRequestException(String.format("COMPACT STORAGE
allows only one column not part of the PRIMARY KEY (got: %s)", StringUtils.join(stmt.columns.keySet(),
", ")));
+                if (stmt.columns.isEmpty())
+                    throw new InvalidRequestException("No definition found that is not part
of the PRIMARY KEY");
 
+                if (useCompactStorage && stmt.columns.size() == 1)
+                {
                     Map.Entry<ColumnIdentifier, AbstractType> lastEntry = stmt.columns.entrySet().iterator().next();
                     stmt.defaultValidator = lastEntry.getValue();
                     stmt.valueAlias = lastEntry.getKey().key;
@@ -231,11 +229,11 @@ public class CreateColumnFamilyStatement extends SchemaAlteringStatement
                 }
                 else
                 {
-                    if (stmt.columns.isEmpty())
-                        throw new InvalidRequestException("No definition found that is not
part of the PRIMARY KEY");
+                    if (useCompactStorage && !columnAliases.isEmpty())
+                        throw new InvalidRequestException(String.format("COMPACT STORAGE
with composite PRIMARY KEY allows only one column not part of the PRIMARY KEY (got: %s)",
StringUtils.join(stmt.columns.keySet(), ", ")));
 
-                    // There is no way to insert/access a column that is not defined for
non-compact
-                    // storage, so the actual validator don't matter much (except that we
want to recognize counter CF as limitation apply to them).
+                    // There is no way to insert/access a column that is not defined for
non-compact storage, so
+                    // the actual validator don't matter much (except that we want to recognize
counter CF as limitation apply to them).
                     stmt.defaultValidator = (stmt.columns.values().iterator().next() instanceof
CounterColumnType) ? CounterColumnType.instance : CFDefinition.definitionType;
                 }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/db/Column.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Column.java b/src/java/org/apache/cassandra/db/Column.java
index 81b30a0..db6a02d 100644
--- a/src/java/org/apache/cassandra/db/Column.java
+++ b/src/java/org/apache/cassandra/db/Column.java
@@ -322,7 +322,7 @@ public class Column implements IColumn
         return new Column(decomposeName(names), value, timestamp);
     }
 
-    public static IColumn create(InetAddress value, long timestamp, String... names)
+    public static Column create(InetAddress value, long timestamp, String... names)
     {
         return new Column(decomposeName(names), InetAddressType.instance.decompose(value),
timestamp);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/44f4cac6/src/java/org/apache/cassandra/db/SystemTable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java
index 49c208e..44b3bb2 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -49,6 +49,8 @@ import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.NodeId;
 import org.apache.cassandra.utils.UUIDGen;
 
+import static org.apache.cassandra.cql3.QueryProcessor.processInternal;
+
 public class SystemTable
 {
     private static final Logger logger = LoggerFactory.getLogger(SystemTable.class);
@@ -69,7 +71,7 @@ public class SystemTable
     @Deprecated
     public static final String OLD_HINTS_CF = "HintsColumnFamily";
 
-    private static final ByteBuffer LOCAL_KEY = ByteBufferUtil.bytes("local");
+    private static final String LOCAL_KEY = "local";
     private static final ByteBuffer CURRENT_LOCAL_NODE_ID_KEY = ByteBufferUtil.bytes("CurrentLocal");
     private static final ByteBuffer ALL_LOCAL_NODE_ID_KEY = ByteBufferUtil.bytes("Local");
 
@@ -97,13 +99,12 @@ public class SystemTable
 
     private static void setupVersion() throws IOException
     {
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-        ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, LOCAL_CF);
-        cf.addColumn(Column.create(FBUtilities.getReleaseVersionString(), FBUtilities.timestampMicros(),
"release_version"));
-        cf.addColumn(Column.create(QueryProcessor.CQL_VERSION.toString(), FBUtilities.timestampMicros(),
"cql_version"));
-        cf.addColumn(Column.create(Constants.VERSION, FBUtilities.timestampMicros(), "thrift_version"));
-        rm.add(cf);
-        rm.apply();
+        String req = "INSERT INTO system.%s (key, release_version, cql_version, thrift_version)
VALUES ('%s', '%s', '%s', '%s')";
+        processInternal(String.format(req, LOCAL_CF,
+                                         LOCAL_KEY,
+                                         FBUtilities.getReleaseVersionString(),
+                                         QueryProcessor.CQL_VERSION.toString(),
+                                         Constants.VERSION));
     }
 
     /** if system data becomes incompatible across versions of cassandra, that logic (and
associated purging) is managed here */
@@ -120,14 +121,11 @@ public class SystemTable
             ColumnFamily oldCf = oldStatusCfs.getColumnFamily(filter);
             Iterator<IColumn> oldColumns = oldCf.columns.iterator();
 
-            ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, LOCAL_CF);
-            cf.addColumn(Column.create(oldColumns.next().value(), FBUtilities.timestampMicros(),
"cluster_name"));
-            cf.addColumn(Column.create(oldColumns.next().value(), FBUtilities.timestampMicros(),
"token_bytes"));
+            String clusterName = ByteBufferUtil.string(oldColumns.next().value());
+            String tokenBytes = ByteBufferUtil.bytesToHex(oldColumns.next().value());
             // (assume that any node getting upgraded was bootstrapped, since that was stored
in a separate row for no particular reason)
-            cf.addColumn(Column.create(true, FBUtilities.timestampMicros(), "bootstrapped"));
-            RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-            rm.add(cf);
-            rm.apply();
+            String req = "INSERT INTO system.%s (key, cluster_name, token_bytes, bootstrapped)
VALUES ('%s', '%s', '%s', true)";
+            processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, clusterName, tokenBytes));
 
             oldStatusCfs.truncate();
         }
@@ -152,18 +150,9 @@ public class SystemTable
         }
 
         IPartitioner p = StorageService.getPartitioner();
-        ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, PEERS_CF);
-        cf.addColumn(Column.create(ep, FBUtilities.timestampMicros(), "peer"));
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, p.getTokenFactory().toByteArray(token));
-        rm.add(cf);
-        try
-        {
-            rm.apply();
-        }
-        catch (IOException e)
-        {
-            throw new IOError(e);
-        }
+        String req = "INSERT INTO system.%s (token_bytes, peer) VALUES ('%s', '%s')";
+        String tokenBytes = ByteBufferUtil.bytesToHex(p.getTokenFactory().toByteArray(token));
+        processInternal(String.format(req, PEERS_CF, tokenBytes, ep.getHostAddress()));
         forceBlockingFlush(PEERS_CF);
     }
 
@@ -173,16 +162,9 @@ public class SystemTable
     public static synchronized void removeToken(Token token)
     {
         IPartitioner p = StorageService.getPartitioner();
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, p.getTokenFactory().toByteArray(token));
-        rm.delete(new QueryPath(PEERS_CF, null, null), FBUtilities.timestampMicros());
-        try
-        {
-            rm.apply();
-        }
-        catch (IOException e)
-        {
-            throw new IOError(e);
-        }
+        String req = "DELETE FROM system.%s WHERE token_bytes = '%s'";
+        String tokenBytes = ByteBufferUtil.bytesToHex(p.getTokenFactory().toByteArray(token));
+        processInternal(String.format(req, PEERS_CF, tokenBytes));
         forceBlockingFlush(PEERS_CF);
     }
 
@@ -192,19 +174,9 @@ public class SystemTable
     public static synchronized void updateToken(Token token)
     {
         IPartitioner p = StorageService.getPartitioner();
-        ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, LOCAL_CF);
-        cf.addColumn(Column.create(p.getTokenFactory().toByteArray(token), FBUtilities.timestampMicros(),
"token_bytes"));
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-        rm.add(cf);
-        try
-        {
-            rm.apply();
-        }
-        catch (IOException e)
-        {
-            throw new IOError(e);
-        }
-
+        String req = "INSERT INTO system.%s (key, token_bytes) VALUES ('%s', '%s')";
+        String tokenBytes = ByteBufferUtil.bytesToHex(p.getTokenFactory().toByteArray(token));
+        processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, tokenBytes));
         forceBlockingFlush(LOCAL_CF);
     }
 
@@ -233,7 +205,7 @@ public class SystemTable
         IPartitioner p = StorageService.getPartitioner();
 
         HashMap<Token, InetAddress> tokenMap = new HashMap<Token, InetAddress>();
-        for (UntypedResultSet.Row row : QueryProcessor.processInternal("SELECT * FROM system.peers"))
+        for (UntypedResultSet.Row row : processInternal("SELECT * FROM system." + PEERS_CF))
             tokenMap.put(p.getTokenFactory().fromByteArray(row.getBytes("token_bytes")),
row.getInetAddress("peer"));
 
         return tokenMap;
@@ -260,52 +232,44 @@ public class SystemTable
             ex.initCause(err);
             throw ex;
         }
-
-        QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCAL_KEY),
-                                                        new QueryPath(LOCAL_CF),
-                                                        ImmutableSortedSet.<ByteBuffer>of(ByteBufferUtil.bytes("cluster_name")));
         ColumnFamilyStore cfs = table.getColumnFamilyStore(LOCAL_CF);
-        ColumnFamily cf = cfs.getColumnFamily(filter);
 
-        if (cf == null)
+        String req = "SELECT cluster_name FROM system.%s WHERE key='%s'";
+        UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
+
+        if (result.isEmpty() || !result.one().has("cluster_name"))
         {
             // this is a brand new node
             if (!cfs.getSSTables().isEmpty())
                 throw new ConfigurationException("Found system table files, but they couldn't
be loaded!");
 
             // no system files.  this is a new node.
-            RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-            cf = ColumnFamily.create(Table.SYSTEM_TABLE, LOCAL_CF);
-            cf.addColumn(Column.create(ByteBufferUtil.bytes(DatabaseDescriptor.getClusterName()),
FBUtilities.timestampMicros(), "cluster_name"));
-            rm.add(cf);
-            rm.apply();
-
+            req = "INSERT INTO system.%s (key, cluster_name) VALUES ('%s', '%s')";
+            processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, DatabaseDescriptor.getClusterName()));
             return;
         }
 
-
-        IColumn clusterCol = cf.columns.iterator().next();
-        String savedClusterName = ByteBufferUtil.string(clusterCol.value());
+        String savedClusterName = result.one().getString("cluster_name");
         if (!DatabaseDescriptor.getClusterName().equals(savedClusterName))
             throw new ConfigurationException("Saved cluster name " + savedClusterName + "
!= configured name " + DatabaseDescriptor.getClusterName());
     }
 
     public static Token getSavedToken()
     {
-        Table table = Table.open(Table.SYSTEM_TABLE);
-        QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCAL_KEY), new QueryPath(LOCAL_CF),
ByteBufferUtil.bytes("token_bytes"));
-        ColumnFamily cf = table.getColumnFamilyStore(LOCAL_CF).getColumnFamily(filter);
-        return cf == null ? null : StorageService.getPartitioner().getTokenFactory().fromByteArray(cf.columns.iterator().next().value());
+        String req = "SELECT token_bytes FROM system.%s WHERE key='%s'";
+        UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
+        return result.isEmpty() || !result.one().has("token_bytes")
+             ? null
+             : StorageService.getPartitioner().getTokenFactory().fromByteArray(result.one().getBytes("token_bytes"));
     }
 
     public static int incrementAndGetGeneration() throws IOException
     {
-        Table table = Table.open(Table.SYSTEM_TABLE);
-        QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCAL_KEY), new QueryPath(LOCAL_CF),
ByteBufferUtil.bytes("gossip_generation"));
-        ColumnFamily cf = table.getColumnFamilyStore(LOCAL_CF).getColumnFamily(filter);
+        String req = "SELECT gossip_generation FROM system.%s WHERE key='%s'";
+        UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
 
         int generation;
-        if (cf == null)
+        if (result.isEmpty() || !result.one().has("gossip_generation"))
         {
             // seconds-since-epoch isn't a foolproof new generation
             // (where foolproof is "guaranteed to be larger than the last one seen at this
ip address"),
@@ -315,7 +279,7 @@ public class SystemTable
         else
         {
             // Other nodes will ignore gossip messages about a node that have a lower generation
than previously seen.
-            final int storedGeneration = ByteBufferUtil.toInt(cf.columns.iterator().next().value())
+ 1;
+            final int storedGeneration = result.one().getInt("gossip_generation") + 1;
             final int now = (int) (System.currentTimeMillis() / 1000);
             if (storedGeneration >= now)
             {
@@ -329,11 +293,8 @@ public class SystemTable
             }
         }
 
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-        cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.LOCAL_CF);
-        cf.addColumn(Column.create(generation, FBUtilities.timestampMicros(), "gossip_generation"));
-        rm.add(cf);
-        rm.apply();
+        req = "INSERT INTO system.%s (key, gossip_generation) VALUES ('%s', %d)";
+        processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, generation));
         forceBlockingFlush(LOCAL_CF);
 
         return generation;
@@ -341,31 +302,18 @@ public class SystemTable
 
     public static boolean isBootstrapped()
     {
-        Table table = Table.open(Table.SYSTEM_TABLE);
-        QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCAL_KEY),
-                                                        new QueryPath(LOCAL_CF),
-                                                        ByteBufferUtil.bytes("bootstrapped"));
-        ColumnFamily cf = table.getColumnFamilyStore(LOCAL_CF).getColumnFamily(filter);
-        if (cf == null)
+        String req = "SELECT bootstrapped FROM system.%s WHERE key='%s'";
+        UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
+
+        if (result.isEmpty() || !result.one().has("bootstrapped"))
             return false;
-        IColumn c = cf.iterator().next();
-        return c.value().get(c.value().position()) == 1;
+        return result.one().getBoolean("bootstrapped");
     }
 
     public static void setBootstrapped(boolean isBootstrapped)
     {
-        ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, LOCAL_CF);
-        cf.addColumn(Column.create(isBootstrapped, FBUtilities.timestampMicros(), "bootstrapped"));
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-        rm.add(cf);
-        try
-        {
-            rm.apply();
-        }
-        catch (IOException e)
-        {
-            throw new RuntimeException(e);
-        }
+        String req = "INSERT INTO system.%s (key, bootstrapped) VALUES ('%s', '%b')";
+        processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, isBootstrapped));
     }
 
     public static boolean isIndexBuilt(String table, String indexName)
@@ -419,40 +367,21 @@ public class SystemTable
     {
         UUID hostId = null;
 
+        String req = "SELECT ring_id FROM system.%s WHERE key='%s'";
+        UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
+
         // Look up the Host UUID (return it if found)
-        Table table = Table.open(Table.SYSTEM_TABLE);
-        QueryFilter filter = QueryFilter.getNamesFilter(decorate(LOCAL_KEY),
-                                                        new QueryPath(LOCAL_CF),
-                                                        ImmutableSortedSet.<ByteBuffer>of(ByteBufferUtil.bytes("ring_id")));
-        ColumnFamily cf = table.getColumnFamilyStore(LOCAL_CF).getColumnFamily(filter);
-        if (cf != null)
+        if (!result.isEmpty() && result.one().has("ring_id"))
         {
-            cf = ColumnFamilyStore.removeDeleted(cf, 0);
-            assert cf.getColumnCount() <= 1;
-            if (cf.getColumnCount() > 0)
-                return UUIDGen.getUUID(cf.iterator().next().value());
+            return result.one().getUUID("ring_id");
         }
 
         // ID not found, generate a new one, persist, and then return it.
         hostId = UUID.randomUUID();
-        long now = FBUtilities.timestampMicros();
-
         logger.warn("No host ID found, created {} (Note: This should happen exactly once
per node).", hostId);
 
-        cf = ColumnFamily.create(Table.SYSTEM_TABLE, LOCAL_CF);
-        cf.addColumn(Column.create(ByteBuffer.wrap(UUIDGen.decompose(hostId)), now, "ring_id"));
-
-        RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCAL_KEY);
-        rm.add(cf);
-        try
-        {
-            rm.apply();
-        }
-        catch (IOException e)
-        {
-            throw new RuntimeException(e);
-        }
-
+        req = "INSERT INTO system.%s (key, ring_id) VALUES ('%s', '%s')";
+        processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, hostId));
         return hostId;
     }
 


Mime
View raw message