Return-Path: Delivered-To: apmail-incubator-cassandra-commits-archive@minotaur.apache.org Received: (qmail 89527 invoked from network); 23 Feb 2010 18:13:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Feb 2010 18:13:49 -0000 Received: (qmail 36077 invoked by uid 500); 23 Feb 2010 18:13:45 -0000 Delivered-To: apmail-incubator-cassandra-commits-archive@incubator.apache.org Received: (qmail 36040 invoked by uid 500); 23 Feb 2010 18:13:45 -0000 Mailing-List: contact cassandra-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-dev@incubator.apache.org Delivered-To: mailing list cassandra-commits@incubator.apache.org Received: (qmail 35962 invoked by uid 99); 23 Feb 2010 18:13:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Feb 2010 18:13:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Feb 2010 18:13:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B56F823888DD; Tue, 23 Feb 2010 18:13:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r915463 [1/3] - in /incubator/cassandra/branches/cassandra-0.6: contrib/mutex/ contrib/word_count/src/ src/java/org/apache/cassandra/auth/ src/java/org/apache/cassandra/avro/ src/java/org/apache/cassandra/cache/ src/java/org/apache/cassandr... Date: Tue, 23 Feb 2010 18:13:09 -0000 To: cassandra-commits@incubator.apache.org From: eevans@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100223181310.B56F823888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: eevans Date: Tue Feb 23 18:13:07 2010 New Revision: 915463 URL: http://svn.apache.org/viewvc?rev=915463&view=rev Log: updated for licensing information (RAT automated) Modified: incubator/cassandra/branches/cassandra-0.6/contrib/mutex/storage-conf.xml incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCount.java incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCountSetup.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/AllowAllAuthenticator.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/IAuthenticator.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/AvroValidation.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/CassandraServer.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/KeyspaceNotDefinedException.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/RecordFactory.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/AbstractCache.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/IAggregatableCacheProvider.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCache.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCacheMBean.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCache.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCacheMBean.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/concurrent/DebuggableThreadPoolExecutor.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/AbstractBounds.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/Bounds.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/hadoop/ColumnFamilySplit.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/DeletionService.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/SSTableDeletingReference.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/FileDataInput.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/net/IncomingTcpConnection.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/net/OutboundTcpConnection.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/service/EmbeddedCassandraService.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/CompletedFileStatus.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/PendingFile.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamCompletionHandler.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamFinishedVerbHandler.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamIn.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamInitiateDoneVerbHandler.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamInitiateVerbHandler.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamRequestMessage.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/streaming/StreamRequestMetadata.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/thrift/ThriftGlue.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/tools/NodeCmd.java incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/utils/LatencyTracker.java incubator/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/dht/BoundsTest.java incubator/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/dht/RangeIntersectionTest.java Modified: incubator/cassandra/branches/cassandra-0.6/contrib/mutex/storage-conf.xml URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/contrib/mutex/storage-conf.xml?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/contrib/mutex/storage-conf.xml (original) +++ incubator/cassandra/branches/cassandra-0.6/contrib/mutex/storage-conf.xml Tue Feb 23 18:13:07 2010 @@ -1,3 +1,21 @@ + Modified: incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCount.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCount.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCount.java (original) +++ incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCount.java Tue Feb 23 18:13:07 2010 @@ -1,3 +1,21 @@ +/** + * 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. + */ + import java.io.IOException; import java.util.Arrays; import java.util.SortedMap; @@ -117,4 +135,4 @@ } return 0; } -} \ No newline at end of file +} Modified: incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCountSetup.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCountSetup.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCountSetup.java (original) +++ incubator/cassandra/branches/cassandra-0.6/contrib/word_count/src/WordCountSetup.java Tue Feb 23 18:13:07 2010 @@ -1,61 +1,79 @@ -import java.util.Arrays; - -import org.apache.log4j.Logger; - -import org.apache.cassandra.db.*; -import org.apache.cassandra.service.StorageProxy; -import org.apache.cassandra.service.StorageService; -import org.apache.cassandra.thrift.ConsistencyLevel; - -public class WordCountSetup -{ - private static final Logger logger = Logger.getLogger(WordCountSetup.class); - - public static final int TEST_COUNT = 4; - - public static void main(String[] args) throws Exception - { - StorageService.instance.initClient(); - logger.info("Sleeping " + WordCount.RING_DELAY); - Thread.sleep(WordCount.RING_DELAY); - assert !StorageService.instance.getLiveNodes().isEmpty(); - - RowMutation rm; - ColumnFamily cf; - byte[] columnName; - - // text0: no rows - - // text1: 1 row, 1 word - columnName = "text1".getBytes(); - rm = new RowMutation(WordCount.KEYSPACE, "Key0"); - cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); - cf.addColumn(new Column(columnName, "word1".getBytes(), 0)); - rm.add(cf); - StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); - logger.info("added text1"); - - // text2: 1 row, 2 words - columnName = "text2".getBytes(); - rm = new RowMutation(WordCount.KEYSPACE, "Key0"); - cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); - cf.addColumn(new Column(columnName, "word1 word2".getBytes(), 0)); - rm.add(cf); - StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); - logger.info("added text2"); - - // text3: 1000 rows, 1 word - columnName = "text3".getBytes(); - for (int i = 0; i < 1000; i++) - { - rm = new RowMutation(WordCount.KEYSPACE, "Key" + i); - cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); - cf.addColumn(new Column(columnName, "word1".getBytes(), 0)); - rm.add(cf); - StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); - } - logger.info("added text3"); - - System.exit(0); - } -} +/** + * 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. + */ + +import java.util.Arrays; + +import org.apache.log4j.Logger; + +import org.apache.cassandra.db.*; +import org.apache.cassandra.service.StorageProxy; +import org.apache.cassandra.service.StorageService; +import org.apache.cassandra.thrift.ConsistencyLevel; + +public class WordCountSetup +{ + private static final Logger logger = Logger.getLogger(WordCountSetup.class); + + public static final int TEST_COUNT = 4; + + public static void main(String[] args) throws Exception + { + StorageService.instance.initClient(); + logger.info("Sleeping " + WordCount.RING_DELAY); + Thread.sleep(WordCount.RING_DELAY); + assert !StorageService.instance.getLiveNodes().isEmpty(); + + RowMutation rm; + ColumnFamily cf; + byte[] columnName; + + // text0: no rows + + // text1: 1 row, 1 word + columnName = "text1".getBytes(); + rm = new RowMutation(WordCount.KEYSPACE, "Key0"); + cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); + cf.addColumn(new Column(columnName, "word1".getBytes(), 0)); + rm.add(cf); + StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); + logger.info("added text1"); + + // text2: 1 row, 2 words + columnName = "text2".getBytes(); + rm = new RowMutation(WordCount.KEYSPACE, "Key0"); + cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); + cf.addColumn(new Column(columnName, "word1 word2".getBytes(), 0)); + rm.add(cf); + StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); + logger.info("added text2"); + + // text3: 1000 rows, 1 word + columnName = "text3".getBytes(); + for (int i = 0; i < 1000; i++) + { + rm = new RowMutation(WordCount.KEYSPACE, "Key" + i); + cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); + cf.addColumn(new Column(columnName, "word1".getBytes(), 0)); + rm.add(cf); + StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); + } + logger.info("added text3"); + + System.exit(0); + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/AllowAllAuthenticator.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/AllowAllAuthenticator.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/AllowAllAuthenticator.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/AllowAllAuthenticator.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.auth; +/* + * + * 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. + * + */ + import org.apache.cassandra.thrift.AuthenticationException; import org.apache.cassandra.thrift.AuthenticationRequest; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/IAuthenticator.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/IAuthenticator.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/IAuthenticator.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/IAuthenticator.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.auth; +/* + * + * 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. + * + */ + import org.apache.cassandra.thrift.AuthenticationException; import org.apache.cassandra.thrift.AuthenticationRequest; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.auth; +/* + * + * 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. + * + */ + import java.io.*; import java.security.MessageDigest; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/AvroValidation.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/AvroValidation.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/AvroValidation.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/AvroValidation.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.avro; +/* + * + * 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. + * + */ + import java.util.Arrays; import org.apache.avro.util.Utf8; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/CassandraServer.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/CassandraServer.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/CassandraServer.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.avro; +/* + * + * 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. + * + */ + import java.io.IOException; import java.nio.ByteBuffer; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/KeyspaceNotDefinedException.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/KeyspaceNotDefinedException.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/KeyspaceNotDefinedException.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/KeyspaceNotDefinedException.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.avro; +/* + * + * 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. + * + */ + import org.apache.avro.util.Utf8; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/RecordFactory.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/RecordFactory.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/RecordFactory.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/avro/RecordFactory.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.avro; +/* + * + * 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. + * + */ + import java.nio.ByteBuffer; import org.apache.avro.generic.GenericArray; @@ -105,4 +126,4 @@ { return newUnavailableException(new Utf8(why)); } -} \ No newline at end of file +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/AbstractCache.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/AbstractCache.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/AbstractCache.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/AbstractCache.java Tue Feb 23 18:13:07 2010 @@ -1,22 +1,43 @@ -package org.apache.cassandra.cache; - -import java.lang.management.ManagementFactory; -import javax.management.MBeanServer; -import javax.management.ObjectName; - -public class AbstractCache -{ - static void registerMBean(Object cache, String table, String name) - { - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - try - { - String mbeanName = "org.apache.cassandra.db:type=Caches,keyspace=" + table + ",cache=" + name; - mbs.registerMBean(cache, new ObjectName(mbeanName)); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } -} +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +import java.lang.management.ManagementFactory; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +public class AbstractCache +{ + static void registerMBean(Object cache, String table, String name) + { + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + try + { + String mbeanName = "org.apache.cassandra.db:type=Caches,keyspace=" + table + ",cache=" + name; + mbs.registerMBean(cache, new ObjectName(mbeanName)); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/IAggregatableCacheProvider.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/IAggregatableCacheProvider.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/IAggregatableCacheProvider.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/IAggregatableCacheProvider.java Tue Feb 23 18:13:07 2010 @@ -1,7 +1,28 @@ -package org.apache.cassandra.cache; - -public interface IAggregatableCacheProvider -{ - public InstrumentedCache getCache(); - public long getObjectCount(); -} +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +public interface IAggregatableCacheProvider +{ + public InstrumentedCache getCache(); + public long getObjectCount(); +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/InstrumentedCache.java Tue Feb 23 18:13:07 2010 @@ -1,85 +1,106 @@ -package org.apache.cassandra.cache; - -import java.util.concurrent.atomic.AtomicLong; - -import com.reardencommerce.kernel.collections.shared.evictable.ConcurrentLinkedHashMap; - -public class InstrumentedCache -{ - private int capacity; - private final ConcurrentLinkedHashMap map; - private final AtomicLong requests = new AtomicLong(0); - private final AtomicLong hits = new AtomicLong(0); - long lastRequests, lastHits; - - public InstrumentedCache(int capacity) - { - this.capacity = capacity; - map = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.SECOND_CHANCE, capacity); - } - - public void put(K key, V value) - { - map.put(key, value); - } - - public V get(K key) - { - V v = map.get(key); - requests.incrementAndGet(); - if (v != null) - hits.incrementAndGet(); - return v; - } - - public V getInternal(K key) - { - return map.get(key); - } - - public void remove(K key) - { - map.remove(key); - } - - public int getCapacity() - { - return capacity; - } - - public void setCapacity(int capacity) - { - map.setCapacity(capacity); - this.capacity = capacity; - } - - public int getSize() - { - return map.size(); - } - - public long getHits() - { - return hits.get(); - } - - public long getRequests() - { - return requests.get(); - } - - public double getRecentHitRate() - { - long r = requests.get(); - long h = hits.get(); - try - { - return ((double)(h - lastHits)) / (r - lastRequests); - } - finally - { - lastRequests = r; - lastHits = h; - } - } -} +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +import java.util.concurrent.atomic.AtomicLong; + +import com.reardencommerce.kernel.collections.shared.evictable.ConcurrentLinkedHashMap; + +public class InstrumentedCache +{ + private int capacity; + private final ConcurrentLinkedHashMap map; + private final AtomicLong requests = new AtomicLong(0); + private final AtomicLong hits = new AtomicLong(0); + long lastRequests, lastHits; + + public InstrumentedCache(int capacity) + { + this.capacity = capacity; + map = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.SECOND_CHANCE, capacity); + } + + public void put(K key, V value) + { + map.put(key, value); + } + + public V get(K key) + { + V v = map.get(key); + requests.incrementAndGet(); + if (v != null) + hits.incrementAndGet(); + return v; + } + + public V getInternal(K key) + { + return map.get(key); + } + + public void remove(K key) + { + map.remove(key); + } + + public int getCapacity() + { + return capacity; + } + + public void setCapacity(int capacity) + { + map.setCapacity(capacity); + this.capacity = capacity; + } + + public int getSize() + { + return map.size(); + } + + public long getHits() + { + return hits.get(); + } + + public long getRequests() + { + return requests.get(); + } + + public double getRecentHitRate() + { + long r = requests.get(); + long h = hits.get(); + try + { + return ((double)(h - lastHits)) / (r - lastRequests); + } + finally + { + lastRequests = r; + lastHits = h; + } + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCache.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCache.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCache.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCache.java Tue Feb 23 18:13:07 2010 @@ -1,78 +1,99 @@ -package org.apache.cassandra.cache; - -public class JMXAggregatingCache implements JMXAggregatingCacheMBean -{ - private final Iterable cacheProviders; - - public JMXAggregatingCache(Iterable caches, String table, String name) - { - this.cacheProviders = caches; - AbstractCache.registerMBean(this, table, name); - } - - public int getCapacity() - { - int capacity = 0; - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - capacity += cacheProvider.getCache().getCapacity(); - } - return capacity; - } - - public void setCapacity(int capacity) - { - long totalObjects = 0; - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - totalObjects += cacheProvider.getObjectCount(); - } - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - double ratio = ((double)cacheProvider.getObjectCount()) / totalObjects; - cacheProvider.getCache().setCapacity((int)(capacity * ratio)); - } - } - - public int getSize() - { - int size = 0; - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - size += cacheProvider.getCache().getSize(); - } - return size; - } - - public long getRequests() - { - long requests = 0; - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - requests += cacheProvider.getCache().getRequests(); - } - return requests; - } - - public long getHits() - { - long hits = 0; - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - hits += cacheProvider.getCache().getHits(); - } - return hits; - } - - public double getRecentHitRate() - { - int n = 0; - double rate = 0; - for (IAggregatableCacheProvider cacheProvider : cacheProviders) - { - rate += cacheProvider.getCache().getRecentHitRate(); - n++; - } - return rate / n; - } -} +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +public class JMXAggregatingCache implements JMXAggregatingCacheMBean +{ + private final Iterable cacheProviders; + + public JMXAggregatingCache(Iterable caches, String table, String name) + { + this.cacheProviders = caches; + AbstractCache.registerMBean(this, table, name); + } + + public int getCapacity() + { + int capacity = 0; + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + capacity += cacheProvider.getCache().getCapacity(); + } + return capacity; + } + + public void setCapacity(int capacity) + { + long totalObjects = 0; + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + totalObjects += cacheProvider.getObjectCount(); + } + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + double ratio = ((double)cacheProvider.getObjectCount()) / totalObjects; + cacheProvider.getCache().setCapacity((int)(capacity * ratio)); + } + } + + public int getSize() + { + int size = 0; + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + size += cacheProvider.getCache().getSize(); + } + return size; + } + + public long getRequests() + { + long requests = 0; + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + requests += cacheProvider.getCache().getRequests(); + } + return requests; + } + + public long getHits() + { + long hits = 0; + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + hits += cacheProvider.getCache().getHits(); + } + return hits; + } + + public double getRecentHitRate() + { + int n = 0; + double rate = 0; + for (IAggregatableCacheProvider cacheProvider : cacheProviders) + { + rate += cacheProvider.getCache().getRecentHitRate(); + n++; + } + return rate / n; + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCacheMBean.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCacheMBean.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCacheMBean.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXAggregatingCacheMBean.java Tue Feb 23 18:13:07 2010 @@ -1,12 +1,33 @@ -package org.apache.cassandra.cache; - -public interface JMXAggregatingCacheMBean -{ - public int getCapacity(); - public void setCapacity(int capacity); - public int getSize(); - - public long getRequests(); - public long getHits(); - public double getRecentHitRate(); -} \ No newline at end of file +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +public interface JMXAggregatingCacheMBean +{ + public int getCapacity(); + public void setCapacity(int capacity); + public int getSize(); + + public long getRequests(); + public long getHits(); + public double getRecentHitRate(); +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCache.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCache.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCache.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCache.java Tue Feb 23 18:13:07 2010 @@ -1,10 +1,31 @@ -package org.apache.cassandra.cache; - -public class JMXInstrumentedCache extends InstrumentedCache implements JMXInstrumentedCacheMBean -{ - public JMXInstrumentedCache(String table, String name, int capacity) - { - super(capacity); - AbstractCache.registerMBean(this, table, name); - } -} \ No newline at end of file +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +public class JMXInstrumentedCache extends InstrumentedCache implements JMXInstrumentedCacheMBean +{ + public JMXInstrumentedCache(String table, String name, int capacity) + { + super(capacity); + AbstractCache.registerMBean(this, table, name); + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCacheMBean.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCacheMBean.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCacheMBean.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/cache/JMXInstrumentedCacheMBean.java Tue Feb 23 18:13:07 2010 @@ -1,21 +1,42 @@ -package org.apache.cassandra.cache; - -public interface JMXInstrumentedCacheMBean -{ - public int getCapacity(); - public void setCapacity(int capacity); - public int getSize(); - - /** total request count since cache creation */ - public long getRequests(); - - /** total cache hit count since cache creation */ - public long getHits(); - - /** - * hits / requests since the last time getHitRate was called. serious telemetry apps should not use this, - * and should instead track the deltas from getHits / getRequests themselves, since those will not be - * affected by multiple users calling it. Provided for convenience only. - */ - public double getRecentHitRate(); -} +package org.apache.cassandra.cache; +/* + * + * 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. + * + */ + + +public interface JMXInstrumentedCacheMBean +{ + public int getCapacity(); + public void setCapacity(int capacity); + public int getSize(); + + /** total request count since cache creation */ + public long getRequests(); + + /** total cache hit count since cache creation */ + public long getHits(); + + /** + * hits / requests since the last time getHitRate was called. serious telemetry apps should not use this, + * and should instead track the deltas from getHits / getRequests themselves, since those will not be + * affected by multiple users calling it. Provided for convenience only. + */ + public double getRecentHitRate(); +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/concurrent/DebuggableThreadPoolExecutor.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/concurrent/DebuggableThreadPoolExecutor.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/concurrent/DebuggableThreadPoolExecutor.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/concurrent/DebuggableThreadPoolExecutor.java Tue Feb 23 18:13:07 2010 @@ -1,4 +1,25 @@ package org.apache.cassandra.concurrent; +/* + * + * 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. + * + */ + import java.util.concurrent.*; Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogExecutorService.java Tue Feb 23 18:13:07 2010 @@ -1,213 +1,234 @@ -package org.apache.cassandra.db.commitlog; - -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; -import javax.management.MBeanServer; -import javax.management.ObjectName; - -import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.utils.WrappedRunnable; - -class CommitLogExecutorService extends AbstractExecutorService implements CommitLogExecutorServiceMBean -{ - private final BlockingQueue queue; - - private volatile long completedTaskCount = 0; - - public CommitLogExecutorService() - { - this(DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch - ? DatabaseDescriptor.getConcurrentWriters() - : 1024 * Runtime.getRuntime().availableProcessors()); - } - - public CommitLogExecutorService(int queueSize) - { - queue = new LinkedBlockingQueue(queueSize); - Runnable runnable = new WrappedRunnable() - { - public void runMayThrow() throws Exception - { - if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch) - { - while (true) - { - processWithSyncBatch(); - completedTaskCount++; - } - } - else - { - while (true) - { - process(); - completedTaskCount++; - } - } - } - }; - new Thread(runnable, "COMMIT-LOG-WRITER").start(); - - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - try - { - mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=Commitlog")); - } - catch (Exception e) - { - throw new RuntimeException(e); - } - } - - - /** - * Get the current number of running tasks - */ - public int getActiveCount() - { - return 1; - } - - /** - * Get the number of completed tasks - */ - public long getCompletedTasks() - { - return completedTaskCount; - } - - /** - * Get the number of tasks waiting to be executed - */ - public long getPendingTasks() - { - return queue.size(); - } - - private void process() throws InterruptedException - { - queue.take().run(); - } - - private final ArrayList incompleteTasks = new ArrayList(); - private final ArrayList taskValues = new ArrayList(); // TODO not sure how to generify this - private void processWithSyncBatch() throws Exception - { - CheaterFutureTask firstTask = queue.take(); - if (!(firstTask.getRawCallable() instanceof CommitLog.LogRecordAdder)) - { - firstTask.run(); - return; - } - - // attempt to do a bunch of LogRecordAdder ops before syncing - // (this is a little clunky since there is no blocking peek method, - // so we have to break it into firstTask / extra tasks) - incompleteTasks.clear(); - taskValues.clear(); - long end = System.nanoTime() + (long)(1000000 * DatabaseDescriptor.getCommitLogSyncBatchWindow()); - - // it doesn't seem worth bothering future-izing the exception - // since if a commitlog op throws, we're probably screwed anyway - incompleteTasks.add(firstTask); - taskValues.add(firstTask.getRawCallable().call()); - while (!queue.isEmpty() - && queue.peek().getRawCallable() instanceof CommitLog.LogRecordAdder - && System.nanoTime() < end) - { - CheaterFutureTask task = queue.remove(); - incompleteTasks.add(task); - taskValues.add(task.getRawCallable().call()); - } - - // now sync and set the tasks' values (which allows thread calling get() to proceed) - try - { - CommitLog.instance().sync(); - } - catch (IOException e) - { - throw new RuntimeException(e); - } - for (int i = 0; i < incompleteTasks.size(); i++) - { - incompleteTasks.get(i).set(taskValues.get(i)); - } - } - - - @Override - protected RunnableFuture newTaskFor(Runnable runnable, T value) - { - return newTaskFor(Executors.callable(runnable, value)); - } - - @Override - protected RunnableFuture newTaskFor(Callable callable) - { - return new CheaterFutureTask(callable); - } - - public void execute(Runnable command) - { - try - { - queue.put((CheaterFutureTask)command); - } - catch (InterruptedException e) - { - throw new RuntimeException(e); - } - } - - public boolean isShutdown() - { - return false; - } - - public boolean isTerminated() - { - return false; - } - - // cassandra is crash-only so there's no need to implement the shutdown methods - public void shutdown() - { - throw new UnsupportedOperationException(); - } - - public List shutdownNow() - { - throw new UnsupportedOperationException(); - } - - public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException - { - throw new UnsupportedOperationException(); - } - - private static class CheaterFutureTask extends FutureTask - { - private final Callable rawCallable; - - public CheaterFutureTask(Callable callable) - { - super(callable); - rawCallable = callable; - } - - public Callable getRawCallable() - { - return rawCallable; - } - - @Override - public void set(V v) - { - super.set(v); - } - } -} +package org.apache.cassandra.db.commitlog; +/* + * + * 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. + * + */ + + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.*; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.utils.WrappedRunnable; + +class CommitLogExecutorService extends AbstractExecutorService implements CommitLogExecutorServiceMBean +{ + private final BlockingQueue queue; + + private volatile long completedTaskCount = 0; + + public CommitLogExecutorService() + { + this(DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch + ? DatabaseDescriptor.getConcurrentWriters() + : 1024 * Runtime.getRuntime().availableProcessors()); + } + + public CommitLogExecutorService(int queueSize) + { + queue = new LinkedBlockingQueue(queueSize); + Runnable runnable = new WrappedRunnable() + { + public void runMayThrow() throws Exception + { + if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch) + { + while (true) + { + processWithSyncBatch(); + completedTaskCount++; + } + } + else + { + while (true) + { + process(); + completedTaskCount++; + } + } + } + }; + new Thread(runnable, "COMMIT-LOG-WRITER").start(); + + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + try + { + mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=Commitlog")); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + + /** + * Get the current number of running tasks + */ + public int getActiveCount() + { + return 1; + } + + /** + * Get the number of completed tasks + */ + public long getCompletedTasks() + { + return completedTaskCount; + } + + /** + * Get the number of tasks waiting to be executed + */ + public long getPendingTasks() + { + return queue.size(); + } + + private void process() throws InterruptedException + { + queue.take().run(); + } + + private final ArrayList incompleteTasks = new ArrayList(); + private final ArrayList taskValues = new ArrayList(); // TODO not sure how to generify this + private void processWithSyncBatch() throws Exception + { + CheaterFutureTask firstTask = queue.take(); + if (!(firstTask.getRawCallable() instanceof CommitLog.LogRecordAdder)) + { + firstTask.run(); + return; + } + + // attempt to do a bunch of LogRecordAdder ops before syncing + // (this is a little clunky since there is no blocking peek method, + // so we have to break it into firstTask / extra tasks) + incompleteTasks.clear(); + taskValues.clear(); + long end = System.nanoTime() + (long)(1000000 * DatabaseDescriptor.getCommitLogSyncBatchWindow()); + + // it doesn't seem worth bothering future-izing the exception + // since if a commitlog op throws, we're probably screwed anyway + incompleteTasks.add(firstTask); + taskValues.add(firstTask.getRawCallable().call()); + while (!queue.isEmpty() + && queue.peek().getRawCallable() instanceof CommitLog.LogRecordAdder + && System.nanoTime() < end) + { + CheaterFutureTask task = queue.remove(); + incompleteTasks.add(task); + taskValues.add(task.getRawCallable().call()); + } + + // now sync and set the tasks' values (which allows thread calling get() to proceed) + try + { + CommitLog.instance().sync(); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + for (int i = 0; i < incompleteTasks.size(); i++) + { + incompleteTasks.get(i).set(taskValues.get(i)); + } + } + + + @Override + protected RunnableFuture newTaskFor(Runnable runnable, T value) + { + return newTaskFor(Executors.callable(runnable, value)); + } + + @Override + protected RunnableFuture newTaskFor(Callable callable) + { + return new CheaterFutureTask(callable); + } + + public void execute(Runnable command) + { + try + { + queue.put((CheaterFutureTask)command); + } + catch (InterruptedException e) + { + throw new RuntimeException(e); + } + } + + public boolean isShutdown() + { + return false; + } + + public boolean isTerminated() + { + return false; + } + + // cassandra is crash-only so there's no need to implement the shutdown methods + public void shutdown() + { + throw new UnsupportedOperationException(); + } + + public List shutdownNow() + { + throw new UnsupportedOperationException(); + } + + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + private static class CheaterFutureTask extends FutureTask + { + private final Callable rawCallable; + + public CheaterFutureTask(Callable callable) + { + super(callable); + rawCallable = callable; + } + + public Callable getRawCallable() + { + return rawCallable; + } + + @Override + public void set(V v) + { + super.set(v); + } + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLogSegment.java Tue Feb 23 18:13:07 2010 @@ -1,193 +1,214 @@ -package org.apache.cassandra.db.commitlog; - -import java.io.File; -import java.io.IOError; -import java.io.IOException; -import java.util.zip.CRC32; -import java.util.zip.Checksum; - -import org.apache.log4j.Logger; - -import org.apache.cassandra.config.DatabaseDescriptor; -import org.apache.cassandra.db.ColumnFamily; -import org.apache.cassandra.db.RowMutation; -import org.apache.cassandra.db.Table; -import org.apache.cassandra.io.util.BufferedRandomAccessFile; -import org.apache.cassandra.io.util.DataOutputBuffer; - -public class CommitLogSegment -{ - private static final Logger logger = Logger.getLogger(CommitLogSegment.class); - - private final BufferedRandomAccessFile logWriter; - private final CommitLogHeader header; - - public CommitLogSegment(int cfCount) - { - this.header = new CommitLogHeader(cfCount); - String logFile = DatabaseDescriptor.getLogFileLocation() + File.separator + "CommitLog-" + System.currentTimeMillis() + ".log"; - logger.info("Creating new commitlog segment " + logFile); - - try - { - logWriter = createWriter(logFile); - writeCommitLogHeader(header.toByteArray()); - } - catch (IOException e) - { - throw new IOError(e); - } - } - - public void writeHeader() throws IOException - { - seekAndWriteCommitLogHeader(header.toByteArray()); - } - - /** writes header at the beginning of the file, then seeks back to current position */ - void seekAndWriteCommitLogHeader(byte[] bytes) throws IOException - { - long currentPos = logWriter.getFilePointer(); - logWriter.seek(0); - - writeCommitLogHeader(bytes); - - logWriter.seek(currentPos); - } - - private void writeCommitLogHeader(byte[] bytes) throws IOException - { - logWriter.writeLong(bytes.length); - logWriter.write(bytes); - logWriter.sync(); - } - - private static BufferedRandomAccessFile createWriter(String file) throws IOException - { - return new BufferedRandomAccessFile(file, "rw", 128 * 1024); - } - - public CommitLogSegment.CommitLogContext write(RowMutation rowMutation, Object serializedRow) throws IOException - { - long currentPosition = -1L; - try - { - currentPosition = logWriter.getFilePointer(); - CommitLogSegment.CommitLogContext cLogCtx = new CommitLogSegment.CommitLogContext(currentPosition); - Table table = Table.open(rowMutation.getTable()); - - // update header - for (ColumnFamily columnFamily : rowMutation.getColumnFamilies()) - { - int id = table.getColumnFamilyId(columnFamily.name()); - if (!header.isDirty(id)) - { - header.turnOn(id, logWriter.getFilePointer()); - seekAndWriteCommitLogHeader(header.toByteArray()); - } - } - - // write mutation, w/ checksum - Checksum checkum = new CRC32(); - if (serializedRow instanceof DataOutputBuffer) - { - DataOutputBuffer buffer = (DataOutputBuffer) serializedRow; - logWriter.writeLong(buffer.getLength()); - logWriter.write(buffer.getData(), 0, buffer.getLength()); - checkum.update(buffer.getData(), 0, buffer.getLength()); - } - else - { - assert serializedRow instanceof byte[]; - byte[] bytes = (byte[]) serializedRow; - logWriter.writeLong(bytes.length); - logWriter.write(bytes); - checkum.update(bytes, 0, bytes.length); - } - logWriter.writeLong(checkum.getValue()); - - return cLogCtx; - } - catch (IOException e) - { - if (currentPosition != -1) - logWriter.seek(currentPosition); - throw e; - } - } - - public void sync() throws IOException - { - logWriter.sync(); - } - - public CommitLogContext getContext() - { - return new CommitLogContext(logWriter.getFilePointer()); - } - - public CommitLogHeader getHeader() - { - return header; - } - - public String getPath() - { - return logWriter.getPath(); - } - - public long length() - { - try - { - return logWriter.length(); - } - catch (IOException e) - { - throw new IOError(e); - } - } - - public void close() - { - try - { - logWriter.close(); - } - catch (IOException e) - { - throw new IOError(e); - } - } - - @Override - public String toString() - { - return "CommitLogSegment(" + logWriter.getPath() + ')'; - } - - public class CommitLogContext - { - public final long position; - - public CommitLogContext(long position) - { - assert position >= 0; - this.position = position; - } - - public CommitLogSegment getSegment() - { - return CommitLogSegment.this; - } - - @Override - public String toString() - { - return "CommitLogContext(" + - "file='" + logWriter.getPath() + '\'' + - ", position=" + position + - ')'; - } - } -} +package org.apache.cassandra.db.commitlog; +/* + * + * 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. + * + */ + + +import java.io.File; +import java.io.IOError; +import java.io.IOException; +import java.util.zip.CRC32; +import java.util.zip.Checksum; + +import org.apache.log4j.Logger; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.ColumnFamily; +import org.apache.cassandra.db.RowMutation; +import org.apache.cassandra.db.Table; +import org.apache.cassandra.io.util.BufferedRandomAccessFile; +import org.apache.cassandra.io.util.DataOutputBuffer; + +public class CommitLogSegment +{ + private static final Logger logger = Logger.getLogger(CommitLogSegment.class); + + private final BufferedRandomAccessFile logWriter; + private final CommitLogHeader header; + + public CommitLogSegment(int cfCount) + { + this.header = new CommitLogHeader(cfCount); + String logFile = DatabaseDescriptor.getLogFileLocation() + File.separator + "CommitLog-" + System.currentTimeMillis() + ".log"; + logger.info("Creating new commitlog segment " + logFile); + + try + { + logWriter = createWriter(logFile); + writeCommitLogHeader(header.toByteArray()); + } + catch (IOException e) + { + throw new IOError(e); + } + } + + public void writeHeader() throws IOException + { + seekAndWriteCommitLogHeader(header.toByteArray()); + } + + /** writes header at the beginning of the file, then seeks back to current position */ + void seekAndWriteCommitLogHeader(byte[] bytes) throws IOException + { + long currentPos = logWriter.getFilePointer(); + logWriter.seek(0); + + writeCommitLogHeader(bytes); + + logWriter.seek(currentPos); + } + + private void writeCommitLogHeader(byte[] bytes) throws IOException + { + logWriter.writeLong(bytes.length); + logWriter.write(bytes); + logWriter.sync(); + } + + private static BufferedRandomAccessFile createWriter(String file) throws IOException + { + return new BufferedRandomAccessFile(file, "rw", 128 * 1024); + } + + public CommitLogSegment.CommitLogContext write(RowMutation rowMutation, Object serializedRow) throws IOException + { + long currentPosition = -1L; + try + { + currentPosition = logWriter.getFilePointer(); + CommitLogSegment.CommitLogContext cLogCtx = new CommitLogSegment.CommitLogContext(currentPosition); + Table table = Table.open(rowMutation.getTable()); + + // update header + for (ColumnFamily columnFamily : rowMutation.getColumnFamilies()) + { + int id = table.getColumnFamilyId(columnFamily.name()); + if (!header.isDirty(id)) + { + header.turnOn(id, logWriter.getFilePointer()); + seekAndWriteCommitLogHeader(header.toByteArray()); + } + } + + // write mutation, w/ checksum + Checksum checkum = new CRC32(); + if (serializedRow instanceof DataOutputBuffer) + { + DataOutputBuffer buffer = (DataOutputBuffer) serializedRow; + logWriter.writeLong(buffer.getLength()); + logWriter.write(buffer.getData(), 0, buffer.getLength()); + checkum.update(buffer.getData(), 0, buffer.getLength()); + } + else + { + assert serializedRow instanceof byte[]; + byte[] bytes = (byte[]) serializedRow; + logWriter.writeLong(bytes.length); + logWriter.write(bytes); + checkum.update(bytes, 0, bytes.length); + } + logWriter.writeLong(checkum.getValue()); + + return cLogCtx; + } + catch (IOException e) + { + if (currentPosition != -1) + logWriter.seek(currentPosition); + throw e; + } + } + + public void sync() throws IOException + { + logWriter.sync(); + } + + public CommitLogContext getContext() + { + return new CommitLogContext(logWriter.getFilePointer()); + } + + public CommitLogHeader getHeader() + { + return header; + } + + public String getPath() + { + return logWriter.getPath(); + } + + public long length() + { + try + { + return logWriter.length(); + } + catch (IOException e) + { + throw new IOError(e); + } + } + + public void close() + { + try + { + logWriter.close(); + } + catch (IOException e) + { + throw new IOError(e); + } + } + + @Override + public String toString() + { + return "CommitLogSegment(" + logWriter.getPath() + ')'; + } + + public class CommitLogContext + { + public final long position; + + public CommitLogContext(long position) + { + assert position >= 0; + this.position = position; + } + + public CommitLogSegment getSegment() + { + return CommitLogSegment.this; + } + + @Override + public String toString() + { + return "CommitLogContext(" + + "file='" + logWriter.getPath() + '\'' + + ", position=" + position + + ')'; + } + } +} Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/AbstractBounds.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/AbstractBounds.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/AbstractBounds.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/AbstractBounds.java Tue Feb 23 18:13:07 2010 @@ -1,71 +1,92 @@ -package org.apache.cassandra.dht; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.Serializable; -import java.util.List; -import java.util.Set; - -import org.apache.cassandra.io.ICompactSerializer2; - -public abstract class AbstractBounds implements Serializable -{ - private static AbstractBoundsSerializer serializer = new AbstractBoundsSerializer(); - - public static ICompactSerializer2 serializer() - { - return serializer; - } - - private enum Type - { - RANGE, - BOUNDS - } - - public final Token left; - public final Token right; - - protected transient final IPartitioner partitioner; - - public AbstractBounds(Token left, Token right, IPartitioner partitioner) - { - this.left = left; - this.right = right; - this.partitioner = partitioner; - } - - @Override - public int hashCode() - { - return toString().hashCode(); - } - - @Override - public abstract boolean equals(Object obj); - - public abstract boolean contains(Token start); - - public abstract Set restrictTo(Range range); - - public abstract List unwrap(); - - private static class AbstractBoundsSerializer implements ICompactSerializer2 - { - public void serialize(AbstractBounds range, DataOutput out) throws IOException - { - out.writeInt(range instanceof Range ? Type.RANGE.ordinal() : Type.BOUNDS.ordinal()); - Token.serializer().serialize(range.left, out); - Token.serializer().serialize(range.right, out); - } - - public AbstractBounds deserialize(DataInput in) throws IOException - { - if (in.readInt() == Type.RANGE.ordinal()) - return new Range(Token.serializer().deserialize(in), Token.serializer().deserialize(in)); - return new Bounds(Token.serializer().deserialize(in), Token.serializer().deserialize(in)); - } - } -} - +package org.apache.cassandra.dht; +/* + * + * 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. + * + */ + + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.Serializable; +import java.util.List; +import java.util.Set; + +import org.apache.cassandra.io.ICompactSerializer2; + +public abstract class AbstractBounds implements Serializable +{ + private static AbstractBoundsSerializer serializer = new AbstractBoundsSerializer(); + + public static ICompactSerializer2 serializer() + { + return serializer; + } + + private enum Type + { + RANGE, + BOUNDS + } + + public final Token left; + public final Token right; + + protected transient final IPartitioner partitioner; + + public AbstractBounds(Token left, Token right, IPartitioner partitioner) + { + this.left = left; + this.right = right; + this.partitioner = partitioner; + } + + @Override + public int hashCode() + { + return toString().hashCode(); + } + + @Override + public abstract boolean equals(Object obj); + + public abstract boolean contains(Token start); + + public abstract Set restrictTo(Range range); + + public abstract List unwrap(); + + private static class AbstractBoundsSerializer implements ICompactSerializer2 + { + public void serialize(AbstractBounds range, DataOutput out) throws IOException + { + out.writeInt(range instanceof Range ? Type.RANGE.ordinal() : Type.BOUNDS.ordinal()); + Token.serializer().serialize(range.left, out); + Token.serializer().serialize(range.right, out); + } + + public AbstractBounds deserialize(DataInput in) throws IOException + { + if (in.readInt() == Type.RANGE.ordinal()) + return new Range(Token.serializer().deserialize(in), Token.serializer().deserialize(in)); + return new Bounds(Token.serializer().deserialize(in), Token.serializer().deserialize(in)); + } + } +} + Modified: incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/Bounds.java URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/Bounds.java?rev=915463&r1=915462&r2=915463&view=diff ============================================================================== --- incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/Bounds.java (original) +++ incubator/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/dht/Bounds.java Tue Feb 23 18:13:07 2010 @@ -1,73 +1,94 @@ -package org.apache.cassandra.dht; - -import java.util.*; - -import org.apache.cassandra.service.StorageService; - -public class Bounds extends AbstractBounds -{ - public Bounds(Token left, Token right) - { - this(left, right, StorageService.getPartitioner()); - } - - Bounds(Token left, Token right, IPartitioner partitioner) - { - super(left, right, partitioner); - // unlike a Range, a Bounds may not wrap - assert left.compareTo(right) <= 0 || right.equals(partitioner.getMinimumToken()) : "[" + left + "," + right + "]"; - } - - @Override - public boolean contains(Token token) - { - return Range.contains(left, right, token) || left.equals(token); - } - - public Set restrictTo(Range range) - { - Token min = partitioner.getMinimumToken(); - - // special case Bounds where left=right (single Token) - if (this.left.equals(this.right) && !this.right.equals(min)) - return range.contains(this.left) - ? Collections.unmodifiableSet(new HashSet(Arrays.asList(this))) - : Collections.emptySet(); - - // get the intersection of a Range w/ same left & right - Set ranges = range.intersectionWith(new Range(this.left, this.right)); - // if range doesn't contain left token anyway, that's the correct answer - if (!range.contains(this.left)) - return (Set) ranges; - // otherwise, add back in the left token - Set S = new HashSet(ranges.size()); - for (Range restricted : ranges) - { - if (restricted.left.equals(this.left)) - S.add(new Bounds(restricted.left, restricted.right)); - else - S.add(restricted); - } - return Collections.unmodifiableSet(S); - } - - public List unwrap() - { - // Bounds objects never wrap - return (List)Arrays.asList(this); - } - - @Override - public boolean equals(Object o) - { - if (!(o instanceof Bounds)) - return false; - Bounds rhs = (Bounds)o; - return left.equals(rhs.left) && right.equals(rhs.right); - } - - public String toString() - { - return "[" + left + "," + right + "]"; - } -} +package org.apache.cassandra.dht; +/* + * + * 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. + * + */ + + +import java.util.*; + +import org.apache.cassandra.service.StorageService; + +public class Bounds extends AbstractBounds +{ + public Bounds(Token left, Token right) + { + this(left, right, StorageService.getPartitioner()); + } + + Bounds(Token left, Token right, IPartitioner partitioner) + { + super(left, right, partitioner); + // unlike a Range, a Bounds may not wrap + assert left.compareTo(right) <= 0 || right.equals(partitioner.getMinimumToken()) : "[" + left + "," + right + "]"; + } + + @Override + public boolean contains(Token token) + { + return Range.contains(left, right, token) || left.equals(token); + } + + public Set restrictTo(Range range) + { + Token min = partitioner.getMinimumToken(); + + // special case Bounds where left=right (single Token) + if (this.left.equals(this.right) && !this.right.equals(min)) + return range.contains(this.left) + ? Collections.unmodifiableSet(new HashSet(Arrays.asList(this))) + : Collections.emptySet(); + + // get the intersection of a Range w/ same left & right + Set ranges = range.intersectionWith(new Range(this.left, this.right)); + // if range doesn't contain left token anyway, that's the correct answer + if (!range.contains(this.left)) + return (Set) ranges; + // otherwise, add back in the left token + Set S = new HashSet(ranges.size()); + for (Range restricted : ranges) + { + if (restricted.left.equals(this.left)) + S.add(new Bounds(restricted.left, restricted.right)); + else + S.add(restricted); + } + return Collections.unmodifiableSet(S); + } + + public List unwrap() + { + // Bounds objects never wrap + return (List)Arrays.asList(this); + } + + @Override + public boolean equals(Object o) + { + if (!(o instanceof Bounds)) + return false; + Bounds rhs = (Bounds)o; + return left.equals(rhs.left) && right.equals(rhs.right); + } + + public String toString() + { + return "[" + left + "," + right + "]"; + } +}