libQtCassandra: QtCassandra::QCassandraPrivate Class Reference

QtCassandra::QCassandraPrivate Class Reference

Private data for the QCassandra class. More...

#include <src/QCassandraPrivate.h>

Collaboration diagram for QtCassandra::QCassandraPrivate:

List of all members.

Public Member Functions

 QCassandraPrivate (QCassandra *parent)
 Initialize the private QCassandra object.

 ~QCassandraPrivate ()
 Clean up the object.

void addValue (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, int64_t value)
 Add value to a Cassandra counter.

QString clusterName () const
 Retrieve the name of the cluster.

bool connect (const QString &host, int port, const QString &password)
 Connect to the Cassandra server.

void contexts () const
 Go through the list of contexts and build a list of such.

void createContext (const QCassandraContext &context)
 Create a new context.

void createTable (const QCassandraTable *table)
 Create a table in the Cassandra server.

void disconnect ()
 Disconnect from the Cassandra server.

void dropContext (const QCassandraContext &context)
 Drop an existing context.

void dropTable (const QString &table_name)
 Drop a table from the Cassandra server.

int32_t getCellCount (const QString &table_name, const QByteArray &row_key, const QCassandraColumnPredicate &column_predicate)
 Get a slice of columns from the Cassandra database.

void getColumnSlice (QCassandraTable &table, const QByteArray &row_key, QCassandraColumnPredicate &column_predicate)
 Get a slice of columns from the Cassandra database.

void getCounter (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, QCassandraValue &value)
 Get the value of a counter from the Cassandra database.

uint32_t getRowSlices (QCassandraTable &table, QCassandraRowPredicate &row_predicate)
 This function retrieves a set of rows.

void getValue (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, QCassandraValue &value)
 Get a value from the Cassandra database.

void insertValue (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, const QCassandraValue &value)
 Insert a value in the Cassandra database.

bool isConnected () const
 Check whether we're connected.

QString partitioner () const
 Retrieve the partitioner of the cluster.

QString protocolVersion () const
 Retrieve the version of the protocol.

void remove (const QString &table_name, const QByteArray &row_key, const QByteArray &column_key, int64_t timestamp, consistency_level_t consistency_level)
 Remove a cell from the Cassandra database.

void setContext (const QString &context)
 Set the context keyspace name.

QString snitch () const
 Retrieve the snitch of the cluster.

void synchronizeSchemaVersions (int timeout)
 Synchronize the version of schemas on all nodes.

void truncateTable (const QCassandraTable *table)
 Truncate a table in the Cassandra server.

void updateContext (const QCassandraContext &context)
 Update an existing context.

void updateTable (const QCassandraTable *table)
 Update a table in the Cassandra server.

Private Member Functions

 QCassandraPrivate (const QCassandraPrivate &)
 Forbid the copy operator.

void mustBeConnected () const throw (std::runtime_error)
 Check that we're connected.

Private Attributes

boost::shared_ptr
< org::apache::cassandra::CassandraClient > 
f_client
 Define a client object.

QCassandraf_parent
 The pointer to the QCassandra object.

boost::shared_ptr
< apache::thrift::protocol::TProtocol > 
f_protocol
 The protocol between us and the Cassandra server.

boost::shared_ptr
< apache::thrift::transport::TTransport > 
f_socket
 The socket used to connect to the Cassandra server.

boost::shared_ptr
< apache::thrift::transport::TTransport > 
f_transport
 The transport handler.


Detailed Description

This class handles such things as the connection to the Cassandra server and hiding all the thrift definitions.

Definition at line 57 of file QCassandraPrivate.h.


Constructor & Destructor Documentation

This function initialize the QCassandra private object.

Parameters:
[in]parentThe parent pointer (i.e. QCassandra object)

Definition at line 197 of file QCassandraPrivate.cpp.

This function makes sure we clean up after ourselves.

Definition at line 222 of file QCassandraPrivate.cpp.

References disconnect().

By default we forbid the copy operator of the QCassandraPrivate class.

The class includes a network connection and we really do not want to have to clone such a thing.

Note that most of the objects do not define the copy operator since they are QObject's and these are already not copyable.

Definition at line 95 of file QCassandraPrivate.h.


Member Function Documentation

void QtCassandra::QCassandraPrivate::addValue ( const QString &  table_name,
const QByteArray &  row_key,
const QByteArray &  column_key,
int64_t  value 
)

This function adds value to the specified Cassandra counter.

The counter is defined in the current context with the table_name, row_key, and column_key.

Parameters:
[in]table_nameName of the table where the value is inserted.
[in]row_keyThe key used to identify the row.
[in]column_keyThe key used to identify the column.
[in]valueThe value to add to the counter.

Definition at line 904 of file QCassandraPrivate.cpp.

References QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, and mustBeConnected().

Referenced by QtCassandra::QCassandraContext::addValue().

This function sends a message to the Cassandra server to determine the name of the cluster.

Returns:
The name of the cluster.

Definition at line 476 of file QCassandraPrivate.cpp.

References f_client, and mustBeConnected().

bool QtCassandra::QCassandraPrivate::connect ( const QString &  host,
int  port,
const QString &  password 
)

This function needs to be called before most of the others.

It is not mentioned in each other function that if the connection is not up then an exception is generated. It will be noted, however, that a connection is required for the function to work.

Note that the main QCassandra object is responsible to test whether the connection is valid (isConnected()) and to capture exceptions that should be replaced by a boolean return values and similar approaches.

In the early days expect to see exceptions coming up until we take care of them all.

Note that this function first disconnects the existing connection if there is one.

When passing a password, the function attempts an SSL connection instead of a standard direct connection. These should be used when connecting over the Internet. If you do not have a password but still wanted to use SSL, then set the password to the special value "ignore".

Warning:
Although there is a password parameter, it has not yet been successfully tested by us. If it works for you, great! You may have to tweak the code though (in which case we'd really appreciate a patch!)
Todo:
Add means for users to be able to define SSL parameters such as the ciphers accepted, certificates, public/private keys, etc.
Parameters:
[in]hostThe host of the Cassandra server.
[in]portThe port of the Cassandra server.
[in]passwordThe password to use on an SSL connection if not empty.
Returns:
true when the server connected, false otherwise
See also:
isConnected()
disconnect()
QCassandraSocketFactory

Definition at line 269 of file QCassandraPrivate.cpp.

References disconnect(), f_client, f_protocol, f_socket, and f_transport.

This function creates a list of QCassandraContexts and returns the result.

The function retrieves all the keyspaces from Cassandra, transforms them in QCassandraContext objects, and save the result in a QCassandraContexts map indexed by name and returns that object.

The QCassandra object is responsible for caching the result. The result should not change until we create a new table although if another process on another machine changes the Cassandra cluster structure, it will not be seen until the cache is cleared.

Definition at line 568 of file QCassandraPrivate.cpp.

References QtCassandra::QCassandra::context(), f_client, f_parent, and mustBeConnected().

This function creates a new context. Trying to create a context with the name of an existing context will fail. Use the update function instead.

The new context identifier is not returned. I'm not too sure what you could do with it anyway since no function make use of it.

At this time, it looks like you cannot include an array of tables in the context or the create function fails.

Parameters:
[in]contextThe context definition used to create the new context.
See also:
updateContext()

Definition at line 600 of file QCassandraPrivate.cpp.

References f_client, mustBeConnected(), and QtCassandra::QCassandraContext::prepareContextDefinition().

Referenced by QtCassandra::QCassandraContext::create().

This function creates a table in the cassandra server transforming a QCassandraTable in a table definition (CfDef) and then calling the system_add_column_family() function.

Parameters:
[in]tableThe table to be created.

Definition at line 655 of file QCassandraPrivate.cpp.

References f_client, mustBeConnected(), and QtCassandra::QCassandraTable::prepareTableDefinition().

Referenced by QtCassandra::QCassandraContext::createTable().

This function destroys the connection of the Cassandra server.

After calling this function, any other function that require a connection will fail.

Definition at line 322 of file QCassandraPrivate.cpp.

References f_client, f_protocol, f_socket, and f_transport.

Referenced by connect(), and ~QCassandraPrivate().

This function drops an existing context. After this call, do not try to access the context again until you re-create it.

Parameters:
[in]contextThe context to drop from the attached Cassandra cluster.
See also:
createContext()

Definition at line 639 of file QCassandraPrivate.cpp.

References QtCassandra::QCassandra::clearCurrentContextIf(), QtCassandra::QCassandraContext::contextName(), f_client, f_parent, and mustBeConnected().

Referenced by QtCassandra::QCassandraContext::drop().

void QtCassandra::QCassandraPrivate::dropTable ( const QString &  table_name)

This function drops the named table from the cassandra server.

Parameters:
[in]table_nameThe name of the table to be dropped.

Definition at line 685 of file QCassandraPrivate.cpp.

References f_client, and mustBeConnected().

Referenced by QtCassandra::QCassandraContext::dropTable().

int32_t QtCassandra::QCassandraPrivate::getCellCount ( const QString &  table_name,
const QByteArray &  row_key,
const QCassandraColumnPredicate column_predicate 
)

This function retrieves the number of columns as defined by a slice of the Cassandra database. A slice is an array of column from a specific row.

Remember that this number represents the number of cells in a specific row. Each row may have a different number of cells.

Parameters:
[in]table_nameName of the table where the cell counting is processed.
[in]row_keyThe key used to identify the row.
[in]column_predicateThe predicate defining the name of the columns to count.
Returns:
The number of cells (Columns) found using the specified predicate.

Definition at line 947 of file QCassandraPrivate.cpp.

References QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraColumnPredicate::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), and QtCassandra::QCassandraColumnPredicate::toPredicate().

Referenced by QtCassandra::QCassandraContext::getCellCount().

void QtCassandra::QCassandraPrivate::getColumnSlice ( QCassandraTable table,
const QByteArray &  row_key,
QCassandraColumnPredicate column_predicate 
)

This function retrieves a slice from the Cassandra database. A slice is an array of column from a specific row.

The result is passed to a QCassandraTable which is expected to save it as a set of rows, cells, and values.

Parameters:
[in,out]tableThe table where values found get inserted.
[in]row_keyThe key used to identify the row.
[in]column_predicateThe predicate defining the name of the columns to return.

Definition at line 984 of file QCassandraPrivate.cpp.

References QtCassandra::QCassandraTable::assignRow(), QtCassandra::QCassandraValue::assignTimestamp(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraColumnPredicate::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), QtCassandra::QCassandraColumnRangePredicate::excludeFirst(), f_client, f_parent, QtCassandra::QCassandraColumnRangePredicate::index(), mustBeConnected(), QtCassandra::QCassandraValue::setBinaryValue(), QtCassandra::QCassandraColumnRangePredicate::setLastKey(), QtCassandra::QCassandraValue::setTtl(), QtCassandra::QCassandraTable::tableName(), and QtCassandra::QCassandraColumnPredicate::toPredicate().

Referenced by QtCassandra::QCassandraContext::getColumnSlice().

void QtCassandra::QCassandraPrivate::getCounter ( const QString &  table_name,
const QByteArray &  row_key,
const QByteArray &  column_key,
QCassandraValue value 
)

This function retrieves a counter value from the Cassandra database.

It is retrieved from the current context, table_name, row_key, and column_key.

Parameters:
[in]table_nameName of the table where the value is inserted.
[in]row_keyThe key used to identify the row.
[in]column_keyThe key used to identify the column.
[out]valueThe new value of the cell.

Definition at line 845 of file QCassandraPrivate.cpp.

References QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraValue::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), and QtCassandra::QCassandraValue::setInt64Value().

Referenced by QtCassandra::QCassandraContext::getCounter().

void QtCassandra::QCassandraPrivate::getValue ( const QString &  table_name,
const QByteArray &  row_key,
const QByteArray &  column_key,
QCassandraValue value 
)

This function retrieves a value from the Cassandra database.

It is retrieved from the current context, table_name, row_key, and column_key.

Parameters:
[in]table_nameName of the table where the value is inserted.
[in]row_keyThe key used to identify the row.
[in]column_keyThe key used to identify the column.
[out]valueThe new value of the cell.

Definition at line 776 of file QCassandraPrivate.cpp.

References QtCassandra::QCassandraValue::assignTimestamp(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraValue::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), QtCassandra::QCassandraValue::setBinaryValue(), QtCassandra::QCassandraValue::setNullValue(), and QtCassandra::QCassandraValue::setTtl().

Referenced by QtCassandra::QCassandraContext::getValue().

void QtCassandra::QCassandraPrivate::insertValue ( const QString &  table_name,
const QByteArray &  row_key,
const QByteArray &  column_key,
const QCassandraValue value 
)

This function insert the specified value in the Cassandra database.

It is saved in the current context, table_name, row_key, and column_key.

Parameters:
[in]table_nameName of the table where the value is inserted.
[in]row_keyThe key used to identify the row.
[in]column_keyThe key used to identify the column.
[in]valueThe new value of the cell.

Definition at line 717 of file QCassandraPrivate.cpp.

References QtCassandra::QCassandraValue::binaryValue(), QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandraValue::consistencyLevel(), QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, mustBeConnected(), QtCassandra::QCassandra::timeofday(), QtCassandra::QCassandraValue::timestamp(), QtCassandra::QCassandraValue::TIMESTAMP_MODE_AUTO, QtCassandra::QCassandraValue::TIMESTAMP_MODE_DEFINED, QtCassandra::QCassandraValue::timestampMode(), QtCassandra::QCassandraValue::ttl(), and QtCassandra::QCassandraValue::TTL_PERMANENT.

Referenced by QtCassandra::QCassandraContext::insertValue().

This checks whether an f_client point exists.

Note:
To test whether the actual TCP/IP connection is up we'll want to have some NOOP function (i.e. describe_cluster_name()).
Returns:
true if the server is connected

Definition at line 344 of file QCassandraPrivate.cpp.

References f_client.

Referenced by mustBeConnected().

void QtCassandra::QCassandraPrivate::mustBeConnected ( ) const throw (std::runtime_error) [private]

This function verifies that the cassandra server is connected (as in the connect() function was called ans succeeded. If not connected, then an exception is raised.

Exceptions:
std::runtime_errorThis function raises an exception if the QCassandraPrivate object is not currently connected to a Cassandra server.

Definition at line 462 of file QCassandraPrivate.cpp.

References isConnected().

Referenced by addValue(), clusterName(), contexts(), createContext(), createTable(), dropContext(), dropTable(), getCellCount(), getColumnSlice(), getCounter(), getRowSlices(), getValue(), insertValue(), partitioner(), protocolVersion(), remove(), setContext(), snitch(), truncateTable(), updateContext(), and updateTable().

This function sends a message to the Cassandra server to determine the partitioner defined for the cluster.

The partitioner determines how data is distributed between nodes in your Cassandra environment. Like with SQL data, if bad paritioning of the data creates side effects when handling the data. In case of Cassandra, a partitioner that ends up sending all of its data to one or two nodes will end up not making much use of all your other nodes.

This information is defined in the cassandra.yaml configuration file. It cannot be changed once you created your cluster.

Returns:
The name of the partitioner.

Definition at line 517 of file QCassandraPrivate.cpp.

References f_client, and mustBeConnected().

This function sends a message to the Cassandra server to determine the version of the protocol.

Returns:
The version of the protocol.

Definition at line 491 of file QCassandraPrivate.cpp.

References f_client, and mustBeConnected().

void QtCassandra::QCassandraPrivate::remove ( const QString &  table_name,
const QByteArray &  row_key,
const QByteArray &  column_key,
int64_t  timestamp,
consistency_level_t  consistency_level 
)

This function calls the Cassandra server to remove a cell in the Cassandra database.

Parameters:
[in]table_nameThe name of the column where the row is defined.
[in]row_keyThe row in which the cell is to be removed.
[in]column_keyThe cell to be removed, may be empty to remove all the cells.
[in]timestampThe time when the key to be removed was created.
[in]consistency_levelThe consistency level to use to remove this cell.

Definition at line 1051 of file QCassandraPrivate.cpp.

References QtCassandra::CONSISTENCY_LEVEL_DEFAULT, QtCassandra::QCassandra::defaultConsistencyLevel(), f_client, f_parent, and mustBeConnected().

Referenced by QtCassandra::QCassandraContext::remove().

void QtCassandra::QCassandraPrivate::setContext ( const QString &  context_name)

The Cassandra database system reacts to commands in a specific keyspace which is managed like a context. This context must be specified before other functions are called or those other functions will fail.

Parameters:
[in]context_nameThe name of the context to use as the current context.

Definition at line 548 of file QCassandraPrivate.cpp.

References f_client, and mustBeConnected().

This function sends a message to the Cassandra server to determine the snitch defined for the cluster.

Returns:
The snitch used by the cluster.

Definition at line 532 of file QCassandraPrivate.cpp.

References f_client, and mustBeConnected().

This function waits until the schema on all nodes that are currently up agree on their version. Nodes that are down are ignored, although it can be a problem to change a schema when a node is down...

This function should be called any time a schema is changed and multiple nodes are in use. This is why in most cases you do not want to create, update, drop schemas (contexts or column families) on a live system. If you do so, be sure to do it from your backend to avoid potential slow downs of your front end.

When you make multiple changes, you are free to do all the changes at once and then call this function. It will generally be faster since the first changes are likely through by the time you check the schema versions.

The following functions affect the schema version:

You are required to make a call to the synchronization function:

  • If you create or update a context/table and intend to use it immediately;
  • If you drop a context/table and then intend to re-created it immediately;

You'll need two synchronizations if you first drop a context/table then create it again. Also, to create a table in a context, you want to synchronize the context first, then create the table (and synchronize the table if you want to create rows.)

Note that if you have many clients and any one of them may create, drop, or update a context or a table, then all your clients need to call the synchronization function to make sure all the nodes are in agreement. This is a rather faster process, but it sure will slow down your service. It would be better to have a backend tool used to create contexts and tables, that backend tool can then call this synchronization function and once it returns, you are ready to start using those new contexts and tables. Of course, you could also make use of the Cassandra console (cassandra-cli) to do that work.

Exceptions:
std::runtime_error()This exception is raised if the synchronization does not happen in the specified amount of time
Parameters:
[in]timeoutThe number of seconds to wait for the synchronization to happen

Definition at line 402 of file QCassandraPrivate.cpp.

References f_client, and QtCassandra::QCassandra::timeofday().

This function truncates (i.e. removes all the rows and their data) a table from the cassandra server.

Parameters:
[in]tableThe table to be created.

Definition at line 699 of file QCassandraPrivate.cpp.

References f_client, mustBeConnected(), and QtCassandra::QCassandraTable::tableName().

Referenced by QtCassandra::QCassandraContext::truncateTable().

This function updates an existing context. Some options may not be updateable.

The context should be one that you loaded from the cluster to be sure that you start with the right data.

Parameters:
[in]contextThe context to update in the attached Cassandra cluster.
See also:
createContext()

Definition at line 621 of file QCassandraPrivate.cpp.

References f_client, mustBeConnected(), and QtCassandra::QCassandraContext::prepareContextDefinition().

Referenced by QtCassandra::QCassandraContext::update().

This function updates a table int the cassandra server.

Parameters:
[in]tableThe table to be updated.

Definition at line 670 of file QCassandraPrivate.cpp.

References f_client, mustBeConnected(), and QtCassandra::QCassandraTable::prepareTableDefinition().

Referenced by QtCassandra::QCassandraContext::updateTable().


Member Data Documentation

The client object is what we use everywhere to communicate with the Cassandra server. It is a Cassandra Client object that knows how to convert the Cassandra specific messages and send them over the transport object.

To create a client, we need to create a socket, a transport and a protocol. If any one of those steps fails, then you cannot communicate with the Cassandra server.

The main raison for failure is an invalid IP/port combinaison or your Cassandra server isn't running.

Definition at line 104 of file QCassandraPrivate.h.

Referenced by addValue(), clusterName(), connect(), contexts(), createContext(), createTable(), disconnect(), dropContext(), dropTable(), getCellCount(), getColumnSlice(), getCounter(), getRowSlices(), getValue(), insertValue(), isConnected(), partitioner(), protocolVersion(), remove(), setContext(), snitch(), synchronizeSchemaVersions(), truncateTable(), updateContext(), and updateTable().

This variable member holds the QCassandra object pointer. This QCassandra object owns the QCassandraPrivate object (it's a 1 to 1.) This is why this pointer is a bare pointer. When the QCassandra goes, so does the QCassandraPriavet. And if the QCassandraPrivate goes, that's because the QCassandra is going.

Definition at line 100 of file QCassandraPrivate.h.

Referenced by addValue(), contexts(), dropContext(), getCellCount(), getColumnSlice(), getCounter(), getRowSlices(), getValue(), insertValue(), and remove().

This object defines the protocol. In other words, it knows how to send and receive messages (i.e. header, footer, etc.)

Definition at line 103 of file QCassandraPrivate.h.

Referenced by connect(), and disconnect().

This pointer holds a Thrift socket used to communicate with the Cassandra server.

At our level we just provide the socket to the framed transport. How it is being used is Thrift responsibility.

It is setup with the IP address and port that one can use to access the Cassandra server.

Definition at line 101 of file QCassandraPrivate.h.

Referenced by connect(), and disconnect().

The transport object of the Thrift system to manage the data being send and received from the Cassandra server.

The socket is attached to the transport system.

Definition at line 102 of file QCassandraPrivate.h.

Referenced by connect(), and disconnect().


The documentation for this class was generated from the following files:

This document is part of the Snap! Websites Project.

Copyright © 2011-2013 by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly