hector tips

oxoxooxx發表於2011-06-20

hector-v2-client-doc.pdf 讀書筆記

LoadBalancingPolicy

Hector uses the slf4j logging API with the Log4J bridge to provide runtime logging.

Hector測試相關的類:
EmbeddedServerHelper
BaseEmbeddedServerTest

建立Keyspace:
Cluster cluster = HFactory.getCreateCluster("TestCluster",
new CassandraHostConfigurator("localhost:9160"));
Keyspace keyspace = HFactory.createKeyspace("Keyspace1",cluster);

StringSerializer
OrderPreservingPartitioner

IndexedSlicesQuery indexedSlicesQuery =
HFactory.createIndexedSlicesQuery(keyspace, se, se,, LongSerializer.get());
indexedSlicesQuery.addEqualsExpression("birthyear", 1975L);
indexedSlicesQuery.setColumnNames("birthdate","firstname");
indexedSlicesQuery.setColumnFamily("Users");
indexedSlicesQuery.setStartKey("");
QueryResult> result =
indexedSlicesQuery.execute();

IndexedSlicesQuery can also have expressions applied on other columns in conjunction with
the addEqualsExpression. There are two important points to note in using additional index
expressions:
● At least one equals expression against an indexed column must always be present via
addEqualsExpression
● The columns for additional clauses do not have have to be configured as indexed for the
ColumnFamily

Maven Repository for Dependencies

hector to store supercolumn:
Mutator mutator =
HFactory.createMutator(keyspace, stringSerializer);
mutator.insert("billing", "Super1", HFactory.createSuperColumn("jsmith",
Arrays.asList(HFactory.createStringColumn("first", "John")),
stringSerializer, stringSerializer, stringSerializer));

SuperColumnQuery superColumnQuery =
HFactory.createSuperColumnQuery(keyspace, stringSerializer,
stringSerializer, stringSerializer, stringSerializer);
superColumnQuery.setColumnFamily("Super1")
.setKey("billing").setSuperName("jsmith");
Result> result = superColumnQuery.execute();

To create your own approach to fail-over, for example to try the next three hosts pausing 200
milliseconds between each, you would construct the following FailoverPolicy:
FailoverPolicy failoverPolicy = new FailoverPolicy(3,200);

attributes exposed via JMX:
status and counters on the connections and pools
aggreate performance statics

If you do not want the overhead of having Pef4j running, it is possible to disable the statistics
gathering entirely by setting the system property com.prettyprint.cassandra.load_hector_log4j
to false at system startup and setting the level in your logging configuretion to WARN for the
appender named: me.prettyprint.hector.TimingLogger

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23937368/viewspace-1051381/,如需轉載,請註明出處,否則將追究法律責任。