Adding column families from Hector

22 views
Skip to first unread message

Patel, Chirag

unread,
Oct 26, 2010, 5:06:09 PM10/26/10
to hector-users
Hi guys,

We are using hector client with 0.7 version of Cassandra. Since 0.7
version has live schema updates we want to create the schema from a
script using hector. However I do not see any API for this in hector.
Only one I see is "HFactory.createKeyspace" but I do not see the one
to create column families. Can any one point me in right direction on
how to achieve this?

Thanks,
-Chirag

Nate McCall

unread,
Oct 26, 2010, 5:38:55 PM10/26/10
to hector...@googlegroups.com
This can be accomplished from the Cluster as retrieved from
HFactory.getOrCreateCluster

The following class provides coverage for these methods and can be
used as an example of how to structure your own code:
http://github.com/rantav/hector/blob/master/src/test/java/me/prettyprint/cassandra/service/CassandraClusterTest.java

Patel, Chirag

unread,
Oct 26, 2010, 7:08:02 PM10/26/10
to hector-users
ahh Perfect.......Thanks Nate!...

On Oct 26, 5:38 pm, Nate McCall <n...@riptano.com> wrote:
> This can be accomplished from the Cluster as retrieved from
> HFactory.getOrCreateCluster
>
> The following class provides coverage for these methods and can be
> used as an example of how to structure your own code:http://github.com/rantav/hector/blob/master/src/test/java/me/prettypr...

B. Todd Burruss

unread,
Oct 26, 2010, 11:01:51 PM10/26/10
to hector-users
i glanced through ThriftCluster.java and didn't see any "schema sync"
code for waiting until the cluster is in sync with the latest schema
changes. below are three methods i use to wait for schema changes to
propagate throughout the cluster. being that cassandra is
distributed, you can't assume that the changes are immediate
throughout the cluster. start with "waitForSchemaSync" and pass it
the version ID returned by the add/remove keyspace or column family
command (the system_ methods in the Thrift API)

cheers


private void waitForSchemaSync(String newVer) {
if (null == newVer || newVer.isEmpty()) {
throw new IllegalArgumentException("version cannot be null
or empty");
}

long start = System.currentTimeMillis();
while (!isSchemaInSync(newVer) && (System.currentTimeMillis()
- start < MAX_WAIT_SCHEMA_SYNC)) {
try {
Thread.sleep(200);
}
catch (InterruptedException e) {
Thread.interrupted();
}
}
logger.info("Waited {}ms to sync schema",
System.currentTimeMillis() - start);
}

public boolean isSchemaInSync(String version) {
Map<String, List<String>> schemaMap = getSchemaVersionMap();
if (null == schemaMap) {
return false;
}

return null != schemaMap && schemaMap.containsKey(version) &&
1 == schemaMap.size();
}

protected Map<String, List<String>> getSchemaVersionMap() {
Map<String, List<String>> schemaMap;
CassandraClient client = cluster.borrowClient();
try {
Client thriftClient = client.getCassandra();
schemaMap = thriftClient.describe_schema_versions();
}
catch (Exception e) {
throw new RuntimeException(e);
}
finally {
cluster.releaseClient(client);
}

return schemaMap;
Reply all
Reply to author
Forward
0 new messages