r66355 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66354‎ | r66355 | r66356 >
Date:15:37, 13 May 2010
Author:maxsem
Status:deferred
Tags:
Comment:
Cassie: renamed $wgThriftPort --> $wgCassandraPort, error handling, comments
Modified paths:
  • /trunk/extensions/Cassandra/Cassandra.php (modified) (history)
  • /trunk/extensions/Cassandra/Cassandra_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Cassandra/Cassandra_body.php
@@ -31,22 +31,27 @@
3232
3333 public function store( $cluster, $data ) {
3434 global $wgCassandraKeyPrefix, $wgCassandraWriteConsistency, $wgCassandraColumnFamily;
35 - $this->connect( $cluster );
36 - $key = 'ES:' . $wgCassandraKeyPrefix . sha1( $data );
3735
38 - $columnPath = new cassandra_ColumnPath();
39 - $columnPath->column = 'data';
40 - $columnPath->super_column = null;
41 - $columnPath->column_family = $wgCassandraColumnFamily;
 36+ try {
 37+ $this->connect( $cluster );
 38+ $key = $wgCassandraKeyPrefix . sha1( $data );
4239
43 - $this->client->insert( $this->keyspace, $key, $columnPath, $data, time(), $wgCassandraWriteConsistency );
44 - return "cassandra://$cluster/$key";
 40+ $columnPath = new cassandra_ColumnPath();
 41+ $columnPath->column = 'data';
 42+ $columnPath->super_column = null;
 43+ $columnPath->column_family = $wgCassandraColumnFamily;
 44+
 45+ $this->client->insert( $this->keyspace, $key, $columnPath, $data, time(), $wgCassandraWriteConsistency );
 46+ return "cassandra://$cluster/$key";
 47+ } catch ( TException $e ) {
 48+ throw new MWCassandraException( $e );
 49+ }
4550 }
4651
4752 function fetchFromURL( $url ) {
4853 global $wgCassandraReadConsistency, $wgCassandraColumnFamily;
4954
50 - try{
 55+ try {
5156 $this->connect( $url );
5257 $splitted = explode( '/', $url );
5358 $key = end( $splitted );
@@ -61,7 +66,7 @@
6267 $predicate = new cassandra_SlicePredicate();
6368 $predicate->slice_range = $sliceRange;
6469
65 - $result = $this->client->get_slice($this->keyspace, $key, $columnParent, $predicate, $wgCassandraReadConsistency);
 70+ $result = $this->client->get_slice( $this->keyspace, $key, $columnParent, $predicate, $wgCassandraReadConsistency );
6671
6772 return $result[0]->column->value;
6873 } catch ( TException $e ) {
@@ -72,25 +77,32 @@
7378 }
7479
7580 private function connect( $cluster ) {
76 - global $wgThriftPort;
 81+ global $wgCassandraPort;
7782
7883 $cluster = str_replace( 'cassandra://', '', $cluster );
7984 list( $host, $this->keyspace ) = explode( '/', $cluster );
8085
81 - $this->socket = new TSocket( $host, $wgThriftPort);
82 - $this->transport = new TBufferedTransport( $this->socket, 1024, 1024 );
83 - $this->protocol = new TBinaryProtocolAccelerated( $this->transport );
84 - $this->client = new CassandraClient( $this->protocol );
85 - $this->transport->open();
 86+ try {
 87+ $this->socket = new TSocket( $host, $wgCassandraPort );
 88+ $this->transport = new TBufferedTransport( $this->socket, 1024, 1024 );
 89+ $this->protocol = new TBinaryProtocolAccelerated( $this->transport );
 90+ $this->client = new CassandraClient( $this->protocol );
 91+ $this->transport->open();
 92+ } catch ( TException $e ) {
 93+ throw new MWCassandraException( $e );
 94+ }
8695 }
8796 }
8897
 98+/**
 99+ * Wrapper exception for better handling in MW
 100+ */
89101 class MWCassandraException extends MWException {
90102 public $innerException;
91103
92104 public function __construct( TException $e ) {
93105 $this->innerException = $e;
94 - parent::__construct( 'Cassandra error ' . get_class( $e ) . ': ' . $e->__toString()
 106+ parent::__construct( 'Cassandra error ' . get_class( $e ) . ': ' . $e->why
95107 . "\n\nStack trace: " . $e->getTraceAsString()
96108 );
97109 }
Index: trunk/extensions/Cassandra/Cassandra.php
@@ -10,11 +10,12 @@
1111 'version' => 0.1,
1212 'author' => 'Max Semenik',
1313 'url' => 'http://www.mediawiki.org/wiki/Extension:Cassandra',
14 - 'description' => 'Allows to store revision text in [http://incubator.apache.org/cassandra/ Apache Cassandra] database.',
 14+ 'description' => 'Allows to store revision text in [http://cassandra.apache.org/ Apache Cassandra] database.',
1515 //'descriptionmsg' => 'cassandra-desc',
1616 );
1717
18 -$wgAutoloadClasses['ExternalStoreCassandra'] = dirname( __FILE__ ) . '/Cassandra_body.php';
 18+$wgAutoloadClasses['ExternalStoreCassandra'] = $wgAutoloadClasses['MWCassandraException']
 19+ = dirname( __FILE__ ) . '/Cassandra_body.php';
1920
2021 if ( is_array( $wgExternalStores ) ) {
2122 $wgExternalStores[] = 'cassandra';
@@ -26,19 +27,26 @@
2728 * Extension settings
2829 */
2930
30 -// Directory where Thrift for PHP resides.
 31+// Directory where Thrift bindings for PHP reside
3132 $wgThriftRoot = '/usr/share/php/Thrift';
32 -$wgThriftPort = 9160;
33 -$wgCassandraKeyPrefix = '';
3433
 34+// Port used for communicating with Cassandra. Must match <ThriftPort>
 35+// in Cassandra's storage-conf.xml
 36+$wgCassandraPort = 9160;
 37+
 38+// String prepended to saved key names, can be used to distinct between
 39+// different wikis, etc. Does not affect the already saved revisions.
 40+$wgCassandraKeyPrefix = $wgDBname;
 41+
3542 /**
3643 * Read and write consistencies, see http://wiki.apache.org/cassandra/API#ConsistencyLevel
3744 * for details.
3845 * Avoid using cassandra_ConsistencyLevel here to prevent large parts
3946 * of Cassandra and Thrift from being loaded on every request. Shouldn't
40 - * matter for real-world setups with byte code cache though.
 47+ * matter much for real-world setups with byte code cache though.
4148 */
4249 $wgCassandraReadConsistency = 1; // cassandra_ConsistencyLevel::ONE
4350 $wgCassandraWriteConsistency = 1; // cassandra_ConsistencyLevel::ONE
4451
 52+// Column family to be used for storing data
4553 $wgCassandraColumnFamily = 'Standard1';
\ No newline at end of file

Status & tagging log