[
https://issues.apache.org/jira/browse/STORM-1211?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15038179#comment-15038179
]
ASF GitHub Bot commented on STORM-1211:
---------------------------------------
Github user fhussonnois commented on a diff in the pull request:
https://github.com/apache/storm/pull/915#discussion_r46584477
--- Diff:
external/storm-cassandra/src/main/java/org/apache/storm/cassandra/trident/state/CassandraState.java
---
@@ -0,0 +1,149 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.storm.cassandra.trident.state;
+
+import backtype.storm.task.IMetricsContext;
+import backtype.storm.topology.FailedException;
+import backtype.storm.tuple.Values;
+import com.datastax.driver.core.BatchStatement;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.Statement;
+import com.google.common.base.Preconditions;
+import org.apache.storm.cassandra.client.SimpleClient;
+import org.apache.storm.cassandra.client.SimpleClientProvider;
+import org.apache.storm.cassandra.query.CQLResultSetValuesMapper;
+import org.apache.storm.cassandra.query.CQLStatementTupleMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import storm.trident.operation.TridentCollector;
+import storm.trident.state.State;
+import storm.trident.tuple.TridentTuple;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ */
+public class CassandraState implements State {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(CassandraState.class);
+
+ private final Map conf;
+ private final Options options;
+
+ private Session session;
+ private SimpleClient client;
+
+ public CassandraState(Map conf, IMetricsContext metrics, int
partitionIndex, int numPartitions, Options options) {
+ this.conf = conf;
+ this.options = options;
+ }
+
+ public static final class Options implements Serializable {
+ private final SimpleClientProvider clientProvider;
+ private CQLStatementTupleMapper cqlStatementTupleMapper;
+ private CQLResultSetValuesMapper cqlResultSetValuesMapper;
+ private BatchStatement.Type batchingType =
BatchStatement.Type.LOGGED;
+
+
+ public Options(SimpleClientProvider clientProvider) {
+ this.clientProvider = clientProvider;
+ }
+
+ public Options withCQLStatementTupleMapper(CQLStatementTupleMapper
cqlStatementTupleMapper) {
+ this.cqlStatementTupleMapper = cqlStatementTupleMapper;
+ return this;
+ }
+
+ public Options
withCQLResultSetValuesMapper(CQLResultSetValuesMapper cqlResultSetValuesMapper)
{
+ this.cqlResultSetValuesMapper = cqlResultSetValuesMapper;
+ return this;
+ }
+
+ public Options withBatching(BatchStatement.Type batchingType) {
+ this.batchingType = batchingType;
+ return this;
+ }
+
+ }
+
+ @Override
+ public void beginCommit(Long txid) {
+ LOG.debug("beginCommit is noop");
+ }
+
+ @Override
+ public void commit(Long txid) {
+ LOG.debug("commit is noop");
+ }
+
+ public void prepare() {
+ Preconditions.checkNotNull(options.cqlStatementTupleMapper,
"CassandraState.Options should have cqlStatementTupleMapper");
+
+ client = options.clientProvider.getClient(conf);
+ session = client.connect();
+ }
+
+ public void cleanup() {
+ session.close();
+ client.close();
+ }
+
+ public void updateState(List<TridentTuple> tuples, final
TridentCollector collector) {
--- End diff --
I think async writes should be used to update state. In cassandra batch
statements must not be used to improved write performance. In addition,
Cassandra will warn if the batch size is too large and this may lead to an
overloading of the cluster. Batches must only be used to make few writes atomic.
> Add trident state and query support for cassandra connector
> -----------------------------------------------------------
>
> Key: STORM-1211
> URL: https://issues.apache.org/jira/browse/STORM-1211
> Project: Apache Storm
> Issue Type: Improvement
> Reporter: Satish Duggana
> Assignee: Satish Duggana
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)