cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r991622 - in /cassandra/trunk: interface/cassandra.genavro src/java/org/apache/cassandra/avro/AvroRecordFactory.java src/java/org/apache/cassandra/avro/CassandraServer.java
Date Wed, 01 Sep 2010 17:50:51 GMT
Author: eevans
Date: Wed Sep  1 17:50:50 2010
New Revision: 991622

URL: http://svn.apache.org/viewvc?rev=991622&view=rev
Log:
avro: describe_ring, check_schema_agreement, and truncate

Patch by Nirmal Ranganathan; reviewed by eevans

Modified:
    cassandra/trunk/interface/cassandra.genavro
    cassandra/trunk/src/java/org/apache/cassandra/avro/AvroRecordFactory.java
    cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java

Modified: cassandra/trunk/interface/cassandra.genavro
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.genavro?rev=991622&r1=991621&r2=991622&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.genavro (original)
+++ cassandra/trunk/interface/cassandra.genavro Wed Sep  1 17:50:50 2010
@@ -67,6 +67,12 @@ protocol Cassandra {
         union { SliceRange, null } slice_range;
     }
 
+	record TokenRange {
+		string start_token;
+		string end_token;
+		array<string> endpoints;
+	}
+
     record Deletion {
         Clock clock;
         union { bytes, null } super_column;
@@ -242,6 +248,27 @@ protocol Cassandra {
                       ConsistencyLevel consistency_level)
     throws InvalidRequestException, UnavailableException, TimedOutException;
 
+    /**
+     * Truncate will mark and entire column family as deleted. From the user's
+     * perspective a successful call to truncate will result in complete data
+     * deletion from column family. Internally, however, disk space will not be
+     * immediately released, as with all deletes in Cassandra, this one only
+     * marks the data as deleted. The operation succeeds only if all hosts in
+     * the cluster at available and will throw an UnavailableException if some
+     * hosts are down.
+     */
+    void truncate(string column_family)
+    throws InvalidRequestException, UnavailableException;
+
+    /** 
+     * Ask the cluster if they all are using the same migration id. Returns a
+     * map of version->hosts-on-that-version. Hosts that did not respond will
+     * be under the key DatabaseDescriptor.INITIAL_VERSION. Agreement can be
+     * determined by checking if the size of the map is 1. 
+     */
+    map<array<string>> check_schema_agreement()
+    throws InvalidRequestException;
+
     string system_add_column_family(CfDef cf_def)
     throws InvalidRequestException;
 
@@ -268,4 +295,11 @@ protocol Cassandra {
     string describe_version();
 
     string describe_partitioner();
+    
+    /** 
+     * Get the token ring: a map of ranges to host addresses, represented as
+     * an array of TokenRange->start-end range and list of host addresses.
+     */
+    array<TokenRange> describe_ring(string keyspace)
+    throws InvalidRequestException;
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/AvroRecordFactory.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/AvroRecordFactory.java?rev=991622&r1=991621&r2=991622&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/AvroRecordFactory.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/AvroRecordFactory.java Wed Sep  1 17:50:50
2010
@@ -22,6 +22,9 @@ package org.apache.cassandra.avro;
 
 
 import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.avro.generic.GenericArray;
 import org.apache.avro.util.Utf8;
 
@@ -122,6 +125,13 @@ class ErrorFactory
     {
         return newInvalidRequestException(new Utf8(why));
     }
+
+    static InvalidRequestException newInvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException
e)
+    {
+        InvalidRequestException exception = newInvalidRequestException(e.why);
+        exception.initCause(e);
+        return exception;
+    }
     
     static NotFoundException newNotFoundException(Utf8 why)
     {
@@ -168,9 +178,25 @@ class ErrorFactory
     {
         return newUnavailableException(new Utf8(why));
     }
+
+    static UnavailableException newUnavailableException(Throwable t) 
+    {
+        UnavailableException exception = newUnavailableException(t.getMessage());
+        exception.initCause(t);
+        return exception;
+    }
     
     static UnavailableException newUnavailableException()
     {
         return newUnavailableException(new Utf8());
     }
+    
+    public static TokenRange newTokenRange(String startRange, String endRange, List<?
extends CharSequence> endpoints)
+    {
+        TokenRange tRange = new TokenRange();
+        tRange.start_token = startRange;
+        tRange.end_token = endRange;
+        tRange.endpoints = (List<CharSequence>) endpoints;
+        return tRange;
+    }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=991622&r1=991621&r2=991622&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Wed Sep  1 17:50:50
2010
@@ -65,6 +65,8 @@ import org.apache.cassandra.db.migration
 import org.apache.cassandra.db.migration.DropColumnFamily;
 import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.db.migration.RenameColumnFamily;
+import org.apache.cassandra.dht.Range;
+import org.apache.cassandra.dht.Token;
 import org.apache.cassandra.locator.AbstractReplicationStrategy;
 import org.apache.cassandra.scheduler.IRequestScheduler;
 import org.apache.cassandra.service.ClientState;
@@ -746,10 +748,10 @@ public class CassandraServer implements 
         return API_VERSION;
     }
     
-    public Map<String, List<String>> check_schema_agreement()
+    public Map<CharSequence, List<CharSequence>> check_schema_agreement()
     {
-        logger.debug("checking schema agreement");      
-        return StorageProxy.checkSchemaAgreement();
+        logger.debug("checking schema agreement");
+        return (Map) StorageProxy.checkSchemaAgreement();
     }
 
     protected void checkKeyspaceAndLoginAuthorized(Permission perm) throws InvalidRequestException
@@ -999,4 +1001,53 @@ public class CassandraServer implements 
         
         return counts;
     }
+
+    public List<TokenRange> describe_ring(CharSequence keyspace) throws AvroRemoteException,
InvalidRequestException
+    {
+        if (keyspace == null || !DatabaseDescriptor.getNonSystemTables().contains(keyspace))
+            throw newInvalidRequestException("There is no ring for the keyspace: " + keyspace);
+        List<TokenRange> ranges = new ArrayList<TokenRange>();
+        Token.TokenFactory<?> tf = StorageService.getPartitioner().getTokenFactory();
+        for (Map.Entry<Range, List<String>> entry : StorageService.instance.getRangeToEndpointMap(keyspace.toString()).entrySet())
+        {
+            Range range = entry.getKey();
+            List<String> endpoints = entry.getValue();
+            ranges.add(newTokenRange(tf.toString(range.left), tf.toString(range.right), endpoints));
+        }
+        return ranges;
+    }
+
+    public Void truncate(CharSequence columnFamily) throws AvroRemoteException, InvalidRequestException,
UnavailableException
+    {
+        if (logger.isDebugEnabled())
+            logger.debug("truncating {} in {}", columnFamily, clientState.getKeyspace());
+
+        try
+        {
+            clientState.hasKeyspaceAccess(Permission.WRITE_VALUE);
+            schedule();
+            StorageProxy.truncateBlocking(clientState.getKeyspace(), columnFamily.toString());
+        }
+        catch (org.apache.cassandra.thrift.InvalidRequestException e)
+        {
+            throw newInvalidRequestException(e);
+        }
+        catch (org.apache.cassandra.thrift.UnavailableException e)
+        {
+            throw newUnavailableException(e);
+        }
+        catch (TimeoutException e)
+        {
+            throw newUnavailableException(e);
+        }
+        catch (IOException e)
+        {
+            throw newUnavailableException(e);
+        }
+        finally
+        {
+            release();
+        }
+        return null;
+    }
 }



Mime
View raw message