tagged 0.6.0-beta2

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/tags/cassandra-0.6.0-beta2@915498 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eric Evans 2010-02-23 19:04:39 +00:00
parent 12cb7efc36
commit 60fa998afd
71 changed files with 3575 additions and 2155 deletions

View File

@ -17,7 +17,7 @@
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<project basedir="." default="build" name="apache-cassandra-incubating" <project basedir="." default="build" name="apache-cassandra"
xmlns:ivy="antlib:org.apache.ivy.ant"> xmlns:ivy="antlib:org.apache.ivy.ant">
<property environment="env"/> <property environment="env"/>
<property file="build.properties" /> <property file="build.properties" />
@ -42,7 +42,7 @@
<property name="test.name" value="*Test"/> <property name="test.name" value="*Test"/>
<property name="test.unit.src" value="${test.dir}/unit"/> <property name="test.unit.src" value="${test.dir}/unit"/>
<property name="dist.dir" value="${build.dir}/dist"/> <property name="dist.dir" value="${build.dir}/dist"/>
<property name="version" value="0.5.0"/> <property name="version" value="0.6.0-beta1"/>
<property name="final.name" value="${ant.project.name}-${version}"/> <property name="final.name" value="${ant.project.name}-${version}"/>
<property name="ivy.version" value="2.1.0" /> <property name="ivy.version" value="2.1.0" />
<property name="ivy.url" <property name="ivy.url"
@ -314,6 +314,7 @@
<include name="**"/> <include name="**"/>
<exclude name="build/**" /> <exclude name="build/**" />
<exclude name="src/gen-java/**" /> <exclude name="src/gen-java/**" />
<exclude name="interface/avro/**" />
</tarfileset> </tarfileset>
</tar> </tar>
</target> </target>

View File

@ -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.
-->
<Storage> <Storage>
<!-- ZooKeeper options --> <!-- ZooKeeper options -->

View File

@ -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.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.SortedMap; import java.util.SortedMap;
@ -117,4 +135,4 @@ public class WordCount extends Configured implements Tool
} }
return 0; return 0;
} }
} }

View File

@ -1,61 +1,79 @@
import java.util.Arrays; /**
* Licensed to the Apache Software Foundation (ASF) under one
import org.apache.log4j.Logger; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
import org.apache.cassandra.db.*; * regarding copyright ownership. The ASF licenses this file
import org.apache.cassandra.service.StorageProxy; * to you under the Apache License, Version 2.0 (the
import org.apache.cassandra.service.StorageService; * "License"); you may not use this file except in compliance
import org.apache.cassandra.thrift.ConsistencyLevel; * with the License. You may obtain a copy of the License at
*
public class WordCountSetup * http://www.apache.org/licenses/LICENSE-2.0
{ *
private static final Logger logger = Logger.getLogger(WordCountSetup.class); * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
public static final int TEST_COUNT = 4; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
public static void main(String[] args) throws Exception * limitations under the License.
{ */
StorageService.instance.initClient();
logger.info("Sleeping " + WordCount.RING_DELAY); import java.util.Arrays;
Thread.sleep(WordCount.RING_DELAY);
assert !StorageService.instance.getLiveNodes().isEmpty(); import org.apache.log4j.Logger;
RowMutation rm; import org.apache.cassandra.db.*;
ColumnFamily cf; import org.apache.cassandra.service.StorageProxy;
byte[] columnName; import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.ConsistencyLevel;
// text0: no rows
public class WordCountSetup
// text1: 1 row, 1 word {
columnName = "text1".getBytes(); private static final Logger logger = Logger.getLogger(WordCountSetup.class);
rm = new RowMutation(WordCount.KEYSPACE, "Key0");
cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); public static final int TEST_COUNT = 4;
cf.addColumn(new Column(columnName, "word1".getBytes(), 0));
rm.add(cf); public static void main(String[] args) throws Exception
StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE); {
logger.info("added text1"); StorageService.instance.initClient();
logger.info("Sleeping " + WordCount.RING_DELAY);
// text2: 1 row, 2 words Thread.sleep(WordCount.RING_DELAY);
columnName = "text2".getBytes(); assert !StorageService.instance.getLiveNodes().isEmpty();
rm = new RowMutation(WordCount.KEYSPACE, "Key0");
cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); RowMutation rm;
cf.addColumn(new Column(columnName, "word1 word2".getBytes(), 0)); ColumnFamily cf;
rm.add(cf); byte[] columnName;
StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE);
logger.info("added text2"); // text0: no rows
// text3: 1000 rows, 1 word // text1: 1 row, 1 word
columnName = "text3".getBytes(); columnName = "text1".getBytes();
for (int i = 0; i < 1000; i++) rm = new RowMutation(WordCount.KEYSPACE, "Key0");
{ cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY);
rm = new RowMutation(WordCount.KEYSPACE, "Key" + i); cf.addColumn(new Column(columnName, "word1".getBytes(), 0));
cf = ColumnFamily.create(WordCount.KEYSPACE, WordCount.COLUMN_FAMILY); rm.add(cf);
cf.addColumn(new Column(columnName, "word1".getBytes(), 0)); StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE);
rm.add(cf); logger.info("added text1");
StorageProxy.mutateBlocking(Arrays.asList(rm), ConsistencyLevel.ONE);
} // text2: 1 row, 2 words
logger.info("added text3"); columnName = "text2".getBytes();
rm = new RowMutation(WordCount.KEYSPACE, "Key0");
System.exit(0); 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);
}
}

2
debian/init vendored
View File

@ -22,7 +22,7 @@ JSVC=/usr/bin/jsvc
JVM_MAX_MEM="1G" JVM_MAX_MEM="1G"
JVM_START_MEM="128M" JVM_START_MEM="128M"
[ -e /usr/share/cassandra/apache-cassandra-incubating.jar ] || exit 0 [ -e /usr/share/cassandra/apache-cassandra.jar ] || exit 0
[ -e /etc/cassandra/storage-conf.xml ] || exit 0 [ -e /etc/cassandra/storage-conf.xml ] || exit 0
# Read configuration variable file if it is present # Read configuration variable file if it is present

6
debian/rules vendored
View File

@ -36,10 +36,10 @@ install: build
dh_install dh_install
# Copy in the jar and symlink to something stable # Copy in the jar and symlink to something stable
dh_install build/apache-cassandra-incubating-$(VERSION).jar \ dh_install build/apache-cassandra-$(VERSION).jar \
usr/share/cassandra usr/share/cassandra
dh_link usr/share/cassandra/apache-cassandra-incubating-$(VERSION).jar \ dh_link usr/share/cassandra/apache-cassandra-$(VERSION).jar \
usr/share/cassandra/apache-cassandra-incubating.jar usr/share/cassandra/apache-cassandra.jar
# Build architecture-independent files here. # Build architecture-independent files here.
binary-indep: build install binary-indep: build install

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.Map; import java.util.Map;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -4,6 +4,27 @@
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/ */
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.auth; 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.AuthenticationException;
import org.apache.cassandra.thrift.AuthenticationRequest; import org.apache.cassandra.thrift.AuthenticationRequest;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.auth; 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.AuthenticationException;
import org.apache.cassandra.thrift.AuthenticationRequest; import org.apache.cassandra.thrift.AuthenticationRequest;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.auth; 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.io.*;
import java.security.MessageDigest; import java.security.MessageDigest;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.avro; 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 java.util.Arrays;
import org.apache.avro.util.Utf8; import org.apache.avro.util.Utf8;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.avro; 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.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.avro; 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; import org.apache.avro.util.Utf8;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.avro; 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 java.nio.ByteBuffer;
import org.apache.avro.generic.GenericArray; import org.apache.avro.generic.GenericArray;
@ -105,4 +126,4 @@ class ErrorFactory
{ {
return newUnavailableException(new Utf8(why)); return newUnavailableException(new Utf8(why));
} }
} }

View File

@ -1,22 +1,43 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
import java.lang.management.ManagementFactory; *
import javax.management.MBeanServer; * Licensed to the Apache Software Foundation (ASF) under one
import javax.management.ObjectName; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
public class AbstractCache * regarding copyright ownership. The ASF licenses this file
{ * to you under the Apache License, Version 2.0 (the
static void registerMBean(Object cache, String table, String name) * "License"); you may not use this file except in compliance
{ * with the License. You may obtain a copy of the License at
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); *
try * http://www.apache.org/licenses/LICENSE-2.0
{ *
String mbeanName = "org.apache.cassandra.db:type=Caches,keyspace=" + table + ",cache=" + name; * Unless required by applicable law or agreed to in writing,
mbs.registerMBean(cache, new ObjectName(mbeanName)); * software distributed under the License is distributed on an
} * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
catch (Exception e) * KIND, either express or implied. See the License for the
{ * specific language governing permissions and limitations
throw new RuntimeException(e); * 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);
}
}
}

View File

@ -1,7 +1,28 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
public interface IAggregatableCacheProvider<K, V> *
{ * Licensed to the Apache Software Foundation (ASF) under one
public InstrumentedCache<K, V> getCache(); * or more contributor license agreements. See the NOTICE file
public long getObjectCount(); * 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<K, V>
{
public InstrumentedCache<K, V> getCache();
public long getObjectCount();
}

View File

@ -1,85 +1,106 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
import java.util.concurrent.atomic.AtomicLong; *
* Licensed to the Apache Software Foundation (ASF) under one
import com.reardencommerce.kernel.collections.shared.evictable.ConcurrentLinkedHashMap; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
public class InstrumentedCache<K, V> * regarding copyright ownership. The ASF licenses this file
{ * to you under the Apache License, Version 2.0 (the
private int capacity; * "License"); you may not use this file except in compliance
private final ConcurrentLinkedHashMap<K, V> map; * with the License. You may obtain a copy of the License at
private final AtomicLong requests = new AtomicLong(0); *
private final AtomicLong hits = new AtomicLong(0); * http://www.apache.org/licenses/LICENSE-2.0
long lastRequests, lastHits; *
* Unless required by applicable law or agreed to in writing,
public InstrumentedCache(int capacity) * software distributed under the License is distributed on an
{ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
this.capacity = capacity; * KIND, either express or implied. See the License for the
map = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.SECOND_CHANCE, capacity); * specific language governing permissions and limitations
} * under the License.
*
public void put(K key, V value) */
{
map.put(key, value);
} import java.util.concurrent.atomic.AtomicLong;
public V get(K key) import com.reardencommerce.kernel.collections.shared.evictable.ConcurrentLinkedHashMap;
{
V v = map.get(key); public class InstrumentedCache<K, V>
requests.incrementAndGet(); {
if (v != null) private int capacity;
hits.incrementAndGet(); private final ConcurrentLinkedHashMap<K, V> map;
return v; private final AtomicLong requests = new AtomicLong(0);
} private final AtomicLong hits = new AtomicLong(0);
long lastRequests, lastHits;
public V getInternal(K key)
{ public InstrumentedCache(int capacity)
return map.get(key); {
} this.capacity = capacity;
map = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.SECOND_CHANCE, capacity);
public void remove(K key) }
{
map.remove(key); public void put(K key, V value)
} {
map.put(key, value);
public int getCapacity() }
{
return capacity; public V get(K key)
} {
V v = map.get(key);
public void setCapacity(int capacity) requests.incrementAndGet();
{ if (v != null)
map.setCapacity(capacity); hits.incrementAndGet();
this.capacity = capacity; return v;
} }
public int getSize() public V getInternal(K key)
{ {
return map.size(); return map.get(key);
} }
public long getHits() public void remove(K key)
{ {
return hits.get(); map.remove(key);
} }
public long getRequests() public int getCapacity()
{ {
return requests.get(); return capacity;
} }
public double getRecentHitRate() public void setCapacity(int capacity)
{ {
long r = requests.get(); map.setCapacity(capacity);
long h = hits.get(); this.capacity = capacity;
try }
{
return ((double)(h - lastHits)) / (r - lastRequests); public int getSize()
} {
finally return map.size();
{ }
lastRequests = r;
lastHits = h; 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;
}
}
}

View File

@ -1,78 +1,99 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
public class JMXAggregatingCache implements JMXAggregatingCacheMBean *
{ * Licensed to the Apache Software Foundation (ASF) under one
private final Iterable<IAggregatableCacheProvider> cacheProviders; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
public JMXAggregatingCache(Iterable<IAggregatableCacheProvider> caches, String table, String name) * regarding copyright ownership. The ASF licenses this file
{ * to you under the Apache License, Version 2.0 (the
this.cacheProviders = caches; * "License"); you may not use this file except in compliance
AbstractCache.registerMBean(this, table, name); * with the License. You may obtain a copy of the License at
} *
* http://www.apache.org/licenses/LICENSE-2.0
public int getCapacity() *
{ * Unless required by applicable law or agreed to in writing,
int capacity = 0; * software distributed under the License is distributed on an
for (IAggregatableCacheProvider cacheProvider : cacheProviders) * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
{ * KIND, either express or implied. See the License for the
capacity += cacheProvider.getCache().getCapacity(); * specific language governing permissions and limitations
} * under the License.
return capacity; *
} */
public void setCapacity(int capacity)
{ public class JMXAggregatingCache implements JMXAggregatingCacheMBean
long totalObjects = 0; {
for (IAggregatableCacheProvider cacheProvider : cacheProviders) private final Iterable<IAggregatableCacheProvider> cacheProviders;
{
totalObjects += cacheProvider.getObjectCount(); public JMXAggregatingCache(Iterable<IAggregatableCacheProvider> caches, String table, String name)
} {
for (IAggregatableCacheProvider cacheProvider : cacheProviders) this.cacheProviders = caches;
{ AbstractCache.registerMBean(this, table, name);
double ratio = ((double)cacheProvider.getObjectCount()) / totalObjects; }
cacheProvider.getCache().setCapacity((int)(capacity * ratio));
} public int getCapacity()
} {
int capacity = 0;
public int getSize() for (IAggregatableCacheProvider cacheProvider : cacheProviders)
{ {
int size = 0; capacity += cacheProvider.getCache().getCapacity();
for (IAggregatableCacheProvider cacheProvider : cacheProviders) }
{ return capacity;
size += cacheProvider.getCache().getSize(); }
}
return size; public void setCapacity(int capacity)
} {
long totalObjects = 0;
public long getRequests() for (IAggregatableCacheProvider cacheProvider : cacheProviders)
{ {
long requests = 0; totalObjects += cacheProvider.getObjectCount();
for (IAggregatableCacheProvider cacheProvider : cacheProviders) }
{ for (IAggregatableCacheProvider cacheProvider : cacheProviders)
requests += cacheProvider.getCache().getRequests(); {
} double ratio = ((double)cacheProvider.getObjectCount()) / totalObjects;
return requests; cacheProvider.getCache().setCapacity((int)(capacity * ratio));
} }
}
public long getHits()
{ public int getSize()
long hits = 0; {
for (IAggregatableCacheProvider cacheProvider : cacheProviders) int size = 0;
{ for (IAggregatableCacheProvider cacheProvider : cacheProviders)
hits += cacheProvider.getCache().getHits(); {
} size += cacheProvider.getCache().getSize();
return hits; }
} return size;
}
public double getRecentHitRate()
{ public long getRequests()
int n = 0; {
double rate = 0; long requests = 0;
for (IAggregatableCacheProvider cacheProvider : cacheProviders) for (IAggregatableCacheProvider cacheProvider : cacheProviders)
{ {
rate += cacheProvider.getCache().getRecentHitRate(); requests += cacheProvider.getCache().getRequests();
n++; }
} return requests;
return rate / n; }
}
} 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;
}
}

View File

@ -1,12 +1,33 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
public interface JMXAggregatingCacheMBean *
{ * Licensed to the Apache Software Foundation (ASF) under one
public int getCapacity(); * or more contributor license agreements. See the NOTICE file
public void setCapacity(int capacity); * distributed with this work for additional information
public int getSize(); * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
public long getRequests(); * "License"); you may not use this file except in compliance
public long getHits(); * with the License. You may obtain a copy of the License at
public double getRecentHitRate(); *
} * 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();
}

View File

@ -1,10 +1,31 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
public class JMXInstrumentedCache<K, V> extends InstrumentedCache<K, V> implements JMXInstrumentedCacheMBean *
{ * Licensed to the Apache Software Foundation (ASF) under one
public JMXInstrumentedCache(String table, String name, int capacity) * or more contributor license agreements. See the NOTICE file
{ * distributed with this work for additional information
super(capacity); * regarding copyright ownership. The ASF licenses this file
AbstractCache.registerMBean(this, table, name); * 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<K, V> extends InstrumentedCache<K, V> implements JMXInstrumentedCacheMBean
{
public JMXInstrumentedCache(String table, String name, int capacity)
{
super(capacity);
AbstractCache.registerMBean(this, table, name);
}
}

View File

@ -1,21 +1,42 @@
package org.apache.cassandra.cache; package org.apache.cassandra.cache;
/*
public interface JMXInstrumentedCacheMBean *
{ * Licensed to the Apache Software Foundation (ASF) under one
public int getCapacity(); * or more contributor license agreements. See the NOTICE file
public void setCapacity(int capacity); * distributed with this work for additional information
public int getSize(); * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
/** total request count since cache creation */ * "License"); you may not use this file except in compliance
public long getRequests(); * with the License. You may obtain a copy of the License at
*
/** total cache hit count since cache creation */ * http://www.apache.org/licenses/LICENSE-2.0
public long getHits(); *
* Unless required by applicable law or agreed to in writing,
/** * software distributed under the License is distributed on an
* hits / requests since the last time getHitRate was called. serious telemetry apps should not use this, * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* and should instead track the deltas from getHits / getRequests themselves, since those will not be * KIND, either express or implied. See the License for the
* affected by multiple users calling it. Provided for convenience only. * specific language governing permissions and limitations
*/ * under the License.
public double getRecentHitRate(); *
} */
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();
}

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.concurrent; 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.*; import java.util.concurrent.*;

View File

@ -1,213 +1,234 @@
package org.apache.cassandra.db.commitlog; package org.apache.cassandra.db.commitlog;
/*
import java.io.IOException; *
import java.lang.management.ManagementFactory; * Licensed to the Apache Software Foundation (ASF) under one
import java.util.ArrayList; * or more contributor license agreements. See the NOTICE file
import java.util.List; * distributed with this work for additional information
import java.util.concurrent.*; * regarding copyright ownership. The ASF licenses this file
import javax.management.MBeanServer; * to you under the Apache License, Version 2.0 (the
import javax.management.ObjectName; * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
import org.apache.cassandra.config.DatabaseDescriptor; *
import org.apache.cassandra.utils.WrappedRunnable; * http://www.apache.org/licenses/LICENSE-2.0
*
class CommitLogExecutorService extends AbstractExecutorService implements CommitLogExecutorServiceMBean * Unless required by applicable law or agreed to in writing,
{ * software distributed under the License is distributed on an
private final BlockingQueue<CheaterFutureTask> queue; * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
private volatile long completedTaskCount = 0; * specific language governing permissions and limitations
* under the License.
public CommitLogExecutorService() *
{ */
this(DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch
? DatabaseDescriptor.getConcurrentWriters()
: 1024 * Runtime.getRuntime().availableProcessors()); import java.io.IOException;
} import java.lang.management.ManagementFactory;
import java.util.ArrayList;
public CommitLogExecutorService(int queueSize) import java.util.List;
{ import java.util.concurrent.*;
queue = new LinkedBlockingQueue<CheaterFutureTask>(queueSize); import javax.management.MBeanServer;
Runnable runnable = new WrappedRunnable() import javax.management.ObjectName;
{
public void runMayThrow() throws Exception import org.apache.cassandra.config.DatabaseDescriptor;
{ import org.apache.cassandra.utils.WrappedRunnable;
if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch)
{ class CommitLogExecutorService extends AbstractExecutorService implements CommitLogExecutorServiceMBean
while (true) {
{ private final BlockingQueue<CheaterFutureTask> queue;
processWithSyncBatch();
completedTaskCount++; private volatile long completedTaskCount = 0;
}
} public CommitLogExecutorService()
else {
{ this(DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch
while (true) ? DatabaseDescriptor.getConcurrentWriters()
{ : 1024 * Runtime.getRuntime().availableProcessors());
process(); }
completedTaskCount++;
} public CommitLogExecutorService(int queueSize)
} {
} queue = new LinkedBlockingQueue<CheaterFutureTask>(queueSize);
}; Runnable runnable = new WrappedRunnable()
new Thread(runnable, "COMMIT-LOG-WRITER").start(); {
public void runMayThrow() throws Exception
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); {
try if (DatabaseDescriptor.getCommitLogSync() == DatabaseDescriptor.CommitLogSync.batch)
{ {
mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=Commitlog")); while (true)
} {
catch (Exception e) processWithSyncBatch();
{ completedTaskCount++;
throw new RuntimeException(e); }
} }
} else
{
while (true)
/** {
* Get the current number of running tasks process();
*/ completedTaskCount++;
public int getActiveCount() }
{ }
return 1; }
} };
new Thread(runnable, "COMMIT-LOG-WRITER").start();
/**
* Get the number of completed tasks MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
*/ try
public long getCompletedTasks() {
{ mbs.registerMBean(this, new ObjectName("org.apache.cassandra.db:type=Commitlog"));
return completedTaskCount; }
} catch (Exception e)
{
/** throw new RuntimeException(e);
* Get the number of tasks waiting to be executed }
*/ }
public long getPendingTasks()
{
return queue.size(); /**
} * Get the current number of running tasks
*/
private void process() throws InterruptedException public int getActiveCount()
{ {
queue.take().run(); return 1;
} }
private final ArrayList<CheaterFutureTask> incompleteTasks = new ArrayList<CheaterFutureTask>(); /**
private final ArrayList taskValues = new ArrayList(); // TODO not sure how to generify this * Get the number of completed tasks
private void processWithSyncBatch() throws Exception */
{ public long getCompletedTasks()
CheaterFutureTask firstTask = queue.take(); {
if (!(firstTask.getRawCallable() instanceof CommitLog.LogRecordAdder)) return completedTaskCount;
{ }
firstTask.run();
return; /**
} * Get the number of tasks waiting to be executed
*/
// attempt to do a bunch of LogRecordAdder ops before syncing public long getPendingTasks()
// (this is a little clunky since there is no blocking peek method, {
// so we have to break it into firstTask / extra tasks) return queue.size();
incompleteTasks.clear(); }
taskValues.clear();
long end = System.nanoTime() + (long)(1000000 * DatabaseDescriptor.getCommitLogSyncBatchWindow()); private void process() throws InterruptedException
{
// it doesn't seem worth bothering future-izing the exception queue.take().run();
// since if a commitlog op throws, we're probably screwed anyway }
incompleteTasks.add(firstTask);
taskValues.add(firstTask.getRawCallable().call()); private final ArrayList<CheaterFutureTask> incompleteTasks = new ArrayList<CheaterFutureTask>();
while (!queue.isEmpty() private final ArrayList taskValues = new ArrayList(); // TODO not sure how to generify this
&& queue.peek().getRawCallable() instanceof CommitLog.LogRecordAdder private void processWithSyncBatch() throws Exception
&& System.nanoTime() < end) {
{ CheaterFutureTask firstTask = queue.take();
CheaterFutureTask task = queue.remove(); if (!(firstTask.getRawCallable() instanceof CommitLog.LogRecordAdder))
incompleteTasks.add(task); {
taskValues.add(task.getRawCallable().call()); firstTask.run();
} return;
}
// now sync and set the tasks' values (which allows thread calling get() to proceed)
try // attempt to do a bunch of LogRecordAdder ops before syncing
{ // (this is a little clunky since there is no blocking peek method,
CommitLog.instance().sync(); // so we have to break it into firstTask / extra tasks)
} incompleteTasks.clear();
catch (IOException e) taskValues.clear();
{ long end = System.nanoTime() + (long)(1000000 * DatabaseDescriptor.getCommitLogSyncBatchWindow());
throw new RuntimeException(e);
} // it doesn't seem worth bothering future-izing the exception
for (int i = 0; i < incompleteTasks.size(); i++) // since if a commitlog op throws, we're probably screwed anyway
{ incompleteTasks.add(firstTask);
incompleteTasks.get(i).set(taskValues.get(i)); taskValues.add(firstTask.getRawCallable().call());
} while (!queue.isEmpty()
} && queue.peek().getRawCallable() instanceof CommitLog.LogRecordAdder
&& System.nanoTime() < end)
{
@Override CheaterFutureTask task = queue.remove();
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) incompleteTasks.add(task);
{ taskValues.add(task.getRawCallable().call());
return newTaskFor(Executors.callable(runnable, value)); }
}
// now sync and set the tasks' values (which allows thread calling get() to proceed)
@Override try
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
{ CommitLog.instance().sync();
return new CheaterFutureTask(callable); }
} catch (IOException e)
{
public void execute(Runnable command) throw new RuntimeException(e);
{ }
try for (int i = 0; i < incompleteTasks.size(); i++)
{ {
queue.put((CheaterFutureTask)command); incompleteTasks.get(i).set(taskValues.get(i));
} }
catch (InterruptedException e) }
{
throw new RuntimeException(e);
} @Override
} protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value)
{
public boolean isShutdown() return newTaskFor(Executors.callable(runnable, value));
{ }
return false;
} @Override
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
public boolean isTerminated() {
{ return new CheaterFutureTask(callable);
return false; }
}
public void execute(Runnable command)
// cassandra is crash-only so there's no need to implement the shutdown methods {
public void shutdown() try
{ {
throw new UnsupportedOperationException(); queue.put((CheaterFutureTask)command);
} }
catch (InterruptedException e)
public List<Runnable> shutdownNow() {
{ throw new RuntimeException(e);
throw new UnsupportedOperationException(); }
} }
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException public boolean isShutdown()
{ {
throw new UnsupportedOperationException(); return false;
} }
private static class CheaterFutureTask<V> extends FutureTask<V> public boolean isTerminated()
{ {
private final Callable rawCallable; return false;
}
public CheaterFutureTask(Callable<V> callable)
{ // cassandra is crash-only so there's no need to implement the shutdown methods
super(callable); public void shutdown()
rawCallable = callable; {
} throw new UnsupportedOperationException();
}
public Callable getRawCallable()
{ public List<Runnable> shutdownNow()
return rawCallable; {
} throw new UnsupportedOperationException();
}
@Override
public void set(V v) public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
{ {
super.set(v); throw new UnsupportedOperationException();
} }
}
} private static class CheaterFutureTask<V> extends FutureTask<V>
{
private final Callable rawCallable;
public CheaterFutureTask(Callable<V> callable)
{
super(callable);
rawCallable = callable;
}
public Callable getRawCallable()
{
return rawCallable;
}
@Override
public void set(V v)
{
super.set(v);
}
}
}

View File

@ -1,193 +1,214 @@
package org.apache.cassandra.db.commitlog; package org.apache.cassandra.db.commitlog;
/*
import java.io.File; *
import java.io.IOError; * Licensed to the Apache Software Foundation (ASF) under one
import java.io.IOException; * or more contributor license agreements. See the NOTICE file
import java.util.zip.CRC32; * distributed with this work for additional information
import java.util.zip.Checksum; * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
import org.apache.log4j.Logger; * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
import org.apache.cassandra.config.DatabaseDescriptor; *
import org.apache.cassandra.db.ColumnFamily; * http://www.apache.org/licenses/LICENSE-2.0
import org.apache.cassandra.db.RowMutation; *
import org.apache.cassandra.db.Table; * Unless required by applicable law or agreed to in writing,
import org.apache.cassandra.io.util.BufferedRandomAccessFile; * software distributed under the License is distributed on an
import org.apache.cassandra.io.util.DataOutputBuffer; * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
public class CommitLogSegment * specific language governing permissions and limitations
{ * under the License.
private static final Logger logger = Logger.getLogger(CommitLogSegment.class); *
*/
private final BufferedRandomAccessFile logWriter;
private final CommitLogHeader header;
import java.io.File;
public CommitLogSegment(int cfCount) import java.io.IOError;
{ import java.io.IOException;
this.header = new CommitLogHeader(cfCount); import java.util.zip.CRC32;
String logFile = DatabaseDescriptor.getLogFileLocation() + File.separator + "CommitLog-" + System.currentTimeMillis() + ".log"; import java.util.zip.Checksum;
logger.info("Creating new commitlog segment " + logFile);
import org.apache.log4j.Logger;
try
{ import org.apache.cassandra.config.DatabaseDescriptor;
logWriter = createWriter(logFile); import org.apache.cassandra.db.ColumnFamily;
writeCommitLogHeader(header.toByteArray()); import org.apache.cassandra.db.RowMutation;
} import org.apache.cassandra.db.Table;
catch (IOException e) import org.apache.cassandra.io.util.BufferedRandomAccessFile;
{ import org.apache.cassandra.io.util.DataOutputBuffer;
throw new IOError(e);
} public class CommitLogSegment
} {
private static final Logger logger = Logger.getLogger(CommitLogSegment.class);
public void writeHeader() throws IOException
{ private final BufferedRandomAccessFile logWriter;
seekAndWriteCommitLogHeader(header.toByteArray()); private final CommitLogHeader header;
}
public CommitLogSegment(int cfCount)
/** writes header at the beginning of the file, then seeks back to current position */ {
void seekAndWriteCommitLogHeader(byte[] bytes) throws IOException this.header = new CommitLogHeader(cfCount);
{ String logFile = DatabaseDescriptor.getLogFileLocation() + File.separator + "CommitLog-" + System.currentTimeMillis() + ".log";
long currentPos = logWriter.getFilePointer(); logger.info("Creating new commitlog segment " + logFile);
logWriter.seek(0);
try
writeCommitLogHeader(bytes); {
logWriter = createWriter(logFile);
logWriter.seek(currentPos); writeCommitLogHeader(header.toByteArray());
} }
catch (IOException e)
private void writeCommitLogHeader(byte[] bytes) throws IOException {
{ throw new IOError(e);
logWriter.writeLong(bytes.length); }
logWriter.write(bytes); }
logWriter.sync();
} public void writeHeader() throws IOException
{
private static BufferedRandomAccessFile createWriter(String file) throws IOException seekAndWriteCommitLogHeader(header.toByteArray());
{ }
return new BufferedRandomAccessFile(file, "rw", 128 * 1024);
} /** writes header at the beginning of the file, then seeks back to current position */
void seekAndWriteCommitLogHeader(byte[] bytes) throws IOException
public CommitLogSegment.CommitLogContext write(RowMutation rowMutation, Object serializedRow) throws IOException {
{ long currentPos = logWriter.getFilePointer();
long currentPosition = -1L; logWriter.seek(0);
try
{ writeCommitLogHeader(bytes);
currentPosition = logWriter.getFilePointer();
CommitLogSegment.CommitLogContext cLogCtx = new CommitLogSegment.CommitLogContext(currentPosition); logWriter.seek(currentPos);
Table table = Table.open(rowMutation.getTable()); }
// update header private void writeCommitLogHeader(byte[] bytes) throws IOException
for (ColumnFamily columnFamily : rowMutation.getColumnFamilies()) {
{ logWriter.writeLong(bytes.length);
int id = table.getColumnFamilyId(columnFamily.name()); logWriter.write(bytes);
if (!header.isDirty(id)) logWriter.sync();
{ }
header.turnOn(id, logWriter.getFilePointer());
seekAndWriteCommitLogHeader(header.toByteArray()); private static BufferedRandomAccessFile createWriter(String file) throws IOException
} {
} return new BufferedRandomAccessFile(file, "rw", 128 * 1024);
}
// write mutation, w/ checksum
Checksum checkum = new CRC32(); public CommitLogSegment.CommitLogContext write(RowMutation rowMutation, Object serializedRow) throws IOException
if (serializedRow instanceof DataOutputBuffer) {
{ long currentPosition = -1L;
DataOutputBuffer buffer = (DataOutputBuffer) serializedRow; try
logWriter.writeLong(buffer.getLength()); {
logWriter.write(buffer.getData(), 0, buffer.getLength()); currentPosition = logWriter.getFilePointer();
checkum.update(buffer.getData(), 0, buffer.getLength()); CommitLogSegment.CommitLogContext cLogCtx = new CommitLogSegment.CommitLogContext(currentPosition);
} Table table = Table.open(rowMutation.getTable());
else
{ // update header
assert serializedRow instanceof byte[]; for (ColumnFamily columnFamily : rowMutation.getColumnFamilies())
byte[] bytes = (byte[]) serializedRow; {
logWriter.writeLong(bytes.length); int id = table.getColumnFamilyId(columnFamily.name());
logWriter.write(bytes); if (!header.isDirty(id))
checkum.update(bytes, 0, bytes.length); {
} header.turnOn(id, logWriter.getFilePointer());
logWriter.writeLong(checkum.getValue()); seekAndWriteCommitLogHeader(header.toByteArray());
}
return cLogCtx; }
}
catch (IOException e) // write mutation, w/ checksum
{ Checksum checkum = new CRC32();
if (currentPosition != -1) if (serializedRow instanceof DataOutputBuffer)
logWriter.seek(currentPosition); {
throw e; DataOutputBuffer buffer = (DataOutputBuffer) serializedRow;
} logWriter.writeLong(buffer.getLength());
} logWriter.write(buffer.getData(), 0, buffer.getLength());
checkum.update(buffer.getData(), 0, buffer.getLength());
public void sync() throws IOException }
{ else
logWriter.sync(); {
} assert serializedRow instanceof byte[];
byte[] bytes = (byte[]) serializedRow;
public CommitLogContext getContext() logWriter.writeLong(bytes.length);
{ logWriter.write(bytes);
return new CommitLogContext(logWriter.getFilePointer()); checkum.update(bytes, 0, bytes.length);
} }
logWriter.writeLong(checkum.getValue());
public CommitLogHeader getHeader()
{ return cLogCtx;
return header; }
} catch (IOException e)
{
public String getPath() if (currentPosition != -1)
{ logWriter.seek(currentPosition);
return logWriter.getPath(); throw e;
} }
}
public long length()
{ public void sync() throws IOException
try {
{ logWriter.sync();
return logWriter.length(); }
}
catch (IOException e) public CommitLogContext getContext()
{ {
throw new IOError(e); return new CommitLogContext(logWriter.getFilePointer());
} }
}
public CommitLogHeader getHeader()
public void close() {
{ return header;
try }
{
logWriter.close(); public String getPath()
} {
catch (IOException e) return logWriter.getPath();
{ }
throw new IOError(e);
} public long length()
} {
try
@Override {
public String toString() return logWriter.length();
{ }
return "CommitLogSegment(" + logWriter.getPath() + ')'; catch (IOException e)
} {
throw new IOError(e);
public class CommitLogContext }
{ }
public final long position;
public void close()
public CommitLogContext(long position) {
{ try
assert position >= 0; {
this.position = position; logWriter.close();
} }
catch (IOException e)
public CommitLogSegment getSegment() {
{ throw new IOError(e);
return CommitLogSegment.this; }
} }
@Override @Override
public String toString() public String toString()
{ {
return "CommitLogContext(" + return "CommitLogSegment(" + logWriter.getPath() + ')';
"file='" + logWriter.getPath() + '\'' + }
", position=" + position +
')'; 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 +
')';
}
}
}

View File

@ -1,71 +1,92 @@
package org.apache.cassandra.dht; package org.apache.cassandra.dht;
/*
import java.io.DataInput; *
import java.io.DataOutput; * Licensed to the Apache Software Foundation (ASF) under one
import java.io.IOException; * or more contributor license agreements. See the NOTICE file
import java.io.Serializable; * distributed with this work for additional information
import java.util.List; * regarding copyright ownership. The ASF licenses this file
import java.util.Set; * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
import org.apache.cassandra.io.ICompactSerializer2; * with the License. You may obtain a copy of the License at
*
public abstract class AbstractBounds implements Serializable * http://www.apache.org/licenses/LICENSE-2.0
{ *
private static AbstractBoundsSerializer serializer = new AbstractBoundsSerializer(); * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
public static ICompactSerializer2<AbstractBounds> serializer() * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
{ * KIND, either express or implied. See the License for the
return serializer; * specific language governing permissions and limitations
} * under the License.
*
private enum Type */
{
RANGE,
BOUNDS import java.io.DataInput;
} import java.io.DataOutput;
import java.io.IOException;
public final Token left; import java.io.Serializable;
public final Token right; import java.util.List;
import java.util.Set;
protected transient final IPartitioner partitioner;
import org.apache.cassandra.io.ICompactSerializer2;
public AbstractBounds(Token left, Token right, IPartitioner partitioner)
{ public abstract class AbstractBounds implements Serializable
this.left = left; {
this.right = right; private static AbstractBoundsSerializer serializer = new AbstractBoundsSerializer();
this.partitioner = partitioner;
} public static ICompactSerializer2<AbstractBounds> serializer()
{
@Override return serializer;
public int hashCode() }
{
return toString().hashCode(); private enum Type
} {
RANGE,
@Override BOUNDS
public abstract boolean equals(Object obj); }
public abstract boolean contains(Token start); public final Token left;
public final Token right;
public abstract Set<AbstractBounds> restrictTo(Range range);
protected transient final IPartitioner partitioner;
public abstract List<AbstractBounds> unwrap();
public AbstractBounds(Token left, Token right, IPartitioner partitioner)
private static class AbstractBoundsSerializer implements ICompactSerializer2<AbstractBounds> {
{ this.left = left;
public void serialize(AbstractBounds range, DataOutput out) throws IOException this.right = right;
{ this.partitioner = partitioner;
out.writeInt(range instanceof Range ? Type.RANGE.ordinal() : Type.BOUNDS.ordinal()); }
Token.serializer().serialize(range.left, out);
Token.serializer().serialize(range.right, out); @Override
} public int hashCode()
{
public AbstractBounds deserialize(DataInput in) throws IOException return toString().hashCode();
{ }
if (in.readInt() == Type.RANGE.ordinal())
return new Range(Token.serializer().deserialize(in), Token.serializer().deserialize(in)); @Override
return new Bounds(Token.serializer().deserialize(in), Token.serializer().deserialize(in)); public abstract boolean equals(Object obj);
}
} public abstract boolean contains(Token start);
}
public abstract Set<AbstractBounds> restrictTo(Range range);
public abstract List<AbstractBounds> unwrap();
private static class AbstractBoundsSerializer implements ICompactSerializer2<AbstractBounds>
{
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));
}
}
}

View File

@ -1,73 +1,94 @@
package org.apache.cassandra.dht; package org.apache.cassandra.dht;
/*
import java.util.*; *
* Licensed to the Apache Software Foundation (ASF) under one
import org.apache.cassandra.service.StorageService; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
public class Bounds extends AbstractBounds * regarding copyright ownership. The ASF licenses this file
{ * to you under the Apache License, Version 2.0 (the
public Bounds(Token left, Token right) * "License"); you may not use this file except in compliance
{ * with the License. You may obtain a copy of the License at
this(left, right, StorageService.getPartitioner()); *
} * http://www.apache.org/licenses/LICENSE-2.0
*
Bounds(Token left, Token right, IPartitioner partitioner) * Unless required by applicable law or agreed to in writing,
{ * software distributed under the License is distributed on an
super(left, right, partitioner); * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// unlike a Range, a Bounds may not wrap * KIND, either express or implied. See the License for the
assert left.compareTo(right) <= 0 || right.equals(partitioner.getMinimumToken()) : "[" + left + "," + right + "]"; * specific language governing permissions and limitations
} * under the License.
*
@Override */
public boolean contains(Token token)
{
return Range.contains(left, right, token) || left.equals(token); import java.util.*;
}
import org.apache.cassandra.service.StorageService;
public Set<AbstractBounds> restrictTo(Range range)
{ public class Bounds extends AbstractBounds
Token min = partitioner.getMinimumToken(); {
public Bounds(Token left, Token right)
// special case Bounds where left=right (single Token) {
if (this.left.equals(this.right) && !this.right.equals(min)) this(left, right, StorageService.getPartitioner());
return range.contains(this.left) }
? Collections.unmodifiableSet(new HashSet<AbstractBounds>(Arrays.asList(this)))
: Collections.<AbstractBounds>emptySet(); Bounds(Token left, Token right, IPartitioner partitioner)
{
// get the intersection of a Range w/ same left & right super(left, right, partitioner);
Set<Range> ranges = range.intersectionWith(new Range(this.left, this.right)); // unlike a Range, a Bounds may not wrap
// if range doesn't contain left token anyway, that's the correct answer assert left.compareTo(right) <= 0 || right.equals(partitioner.getMinimumToken()) : "[" + left + "," + right + "]";
if (!range.contains(this.left)) }
return (Set) ranges;
// otherwise, add back in the left token @Override
Set<AbstractBounds> S = new HashSet<AbstractBounds>(ranges.size()); public boolean contains(Token token)
for (Range restricted : ranges) {
{ return Range.contains(left, right, token) || left.equals(token);
if (restricted.left.equals(this.left)) }
S.add(new Bounds(restricted.left, restricted.right));
else public Set<AbstractBounds> restrictTo(Range range)
S.add(restricted); {
} Token min = partitioner.getMinimumToken();
return Collections.unmodifiableSet(S);
} // special case Bounds where left=right (single Token)
if (this.left.equals(this.right) && !this.right.equals(min))
public List<AbstractBounds> unwrap() return range.contains(this.left)
{ ? Collections.unmodifiableSet(new HashSet<AbstractBounds>(Arrays.asList(this)))
// Bounds objects never wrap : Collections.<AbstractBounds>emptySet();
return (List)Arrays.asList(this);
} // get the intersection of a Range w/ same left & right
Set<Range> ranges = range.intersectionWith(new Range(this.left, this.right));
@Override // if range doesn't contain left token anyway, that's the correct answer
public boolean equals(Object o) if (!range.contains(this.left))
{ return (Set) ranges;
if (!(o instanceof Bounds)) // otherwise, add back in the left token
return false; Set<AbstractBounds> S = new HashSet<AbstractBounds>(ranges.size());
Bounds rhs = (Bounds)o; for (Range restricted : ranges)
return left.equals(rhs.left) && right.equals(rhs.right); {
} if (restricted.left.equals(this.left))
S.add(new Bounds(restricted.left, restricted.right));
public String toString() else
{ S.add(restricted);
return "[" + left + "," + right + "]"; }
} return Collections.unmodifiableSet(S);
} }
public List<AbstractBounds> 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 + "]";
}
}

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.hadoop; package org.apache.cassandra.hadoop;
/*
*
* 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.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
@ -226,4 +247,4 @@ public class ColumnFamilyInputFormat extends InputFormat<String, SortedMap<byte[
{ {
return new ColumnFamilyRecordReader(); return new ColumnFamilyRecordReader();
} }
} }

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.hadoop; package org.apache.cassandra.hadoop;
/*
*
* 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.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
@ -188,4 +209,4 @@ public class ColumnFamilyRecordReader extends RecordReader<String, SortedMap<byt
{ {
return new org.apache.cassandra.db.Column(column.name, column.value, column.timestamp); return new org.apache.cassandra.db.Column(column.name, column.value, column.timestamp);
} }
} }

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.hadoop; package org.apache.cassandra.hadoop;
/*
*
* 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.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
@ -132,4 +153,4 @@ public class ColumnFamilySplit extends InputSplit implements Writable
w.readFields(in); w.readFields(in);
return w; return w;
} }
} }

View File

@ -1,67 +1,88 @@
package org.apache.cassandra.io; package org.apache.cassandra.io;
/*
import java.io.File; *
import java.io.IOException; * Licensed to the Apache Software Foundation (ASF) under one
import java.util.concurrent.ExecutorService; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor; * regarding copyright ownership. The ASF licenses this file
import org.apache.cassandra.concurrent.NamedThreadFactory; * to you under the Apache License, Version 2.0 (the
import org.apache.cassandra.io.util.FileUtils; * "License"); you may not use this file except in compliance
import org.apache.cassandra.utils.WrappedRunnable; * with the License. You may obtain a copy of the License at
*
public class DeletionService * http://www.apache.org/licenses/LICENSE-2.0
{ *
public static final int MAX_RETRIES = 10; * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
public static final ExecutorService executor = new JMXEnabledThreadPoolExecutor("FILEUTILS-DELETE-POOL"); * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
public static void submitDelete(final String file) * specific language governing permissions and limitations
{ * under the License.
Runnable deleter = new WrappedRunnable() *
{ */
@Override
protected void runMayThrow() throws IOException
{ import java.io.File;
FileUtils.deleteWithConfirm(new File(file)); import java.io.IOException;
} import java.util.concurrent.ExecutorService;
};
executor.submit(deleter); import org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor;
} import org.apache.cassandra.concurrent.NamedThreadFactory;
import org.apache.cassandra.io.util.FileUtils;
public static void submitDeleteWithRetry(String file) import org.apache.cassandra.utils.WrappedRunnable;
{
submitDeleteWithRetry(file, 0); public class DeletionService
} {
public static final int MAX_RETRIES = 10;
private static void submitDeleteWithRetry(final String file, final int retryCount)
{ public static final ExecutorService executor = new JMXEnabledThreadPoolExecutor("FILEUTILS-DELETE-POOL");
Runnable deleter = new WrappedRunnable()
{ public static void submitDelete(final String file)
@Override {
protected void runMayThrow() throws IOException Runnable deleter = new WrappedRunnable()
{ {
if (!new File(file).delete()) @Override
{ protected void runMayThrow() throws IOException
if (retryCount > MAX_RETRIES) {
throw new IOException("Unable to delete " + file + " after " + MAX_RETRIES + " tries"); FileUtils.deleteWithConfirm(new File(file));
new Thread(new Runnable() }
{ };
public void run() executor.submit(deleter);
{ }
try
{ public static void submitDeleteWithRetry(String file)
Thread.sleep(10000); {
} submitDeleteWithRetry(file, 0);
catch (InterruptedException e) }
{
throw new AssertionError(e); private static void submitDeleteWithRetry(final String file, final int retryCount)
} {
submitDeleteWithRetry(file, retryCount + 1); Runnable deleter = new WrappedRunnable()
} {
}, "Delete submission: " + file).start(); @Override
} protected void runMayThrow() throws IOException
} {
}; if (!new File(file).delete())
executor.submit(deleter); {
} if (retryCount > MAX_RETRIES)
} throw new IOException("Unable to delete " + file + " after " + MAX_RETRIES + " tries");
new Thread(new Runnable()
{
public void run()
{
try
{
Thread.sleep(10000);
}
catch (InterruptedException e)
{
throw new AssertionError(e);
}
submitDeleteWithRetry(file, retryCount + 1);
}
}, "Delete submission: " + file).start();
}
}
};
executor.submit(deleter);
}
}

View File

@ -1,86 +1,107 @@
package org.apache.cassandra.io; package org.apache.cassandra.io;
/*
import java.io.File; *
import java.io.IOError; * Licensed to the Apache Software Foundation (ASF) under one
import java.io.IOException; * or more contributor license agreements. See the NOTICE file
import java.lang.ref.PhantomReference; * distributed with this work for additional information
import java.lang.ref.ReferenceQueue; * regarding copyright ownership. The ASF licenses this file
import java.util.Timer; * to you under the Apache License, Version 2.0 (the
import java.util.TimerTask; * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
import org.apache.log4j.Logger; *
* http://www.apache.org/licenses/LICENSE-2.0
import org.apache.cassandra.io.util.FileUtils; *
* Unless required by applicable law or agreed to in writing,
public class SSTableDeletingReference extends PhantomReference<SSTableReader> * software distributed under the License is distributed on an
{ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
private static final Logger logger = Logger.getLogger(SSTableDeletingReference.class); * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
private static final Timer timer = new Timer("SSTABLE-CLEANUP-TIMER"); * under the License.
public static final int RETRY_DELAY = 10000; *
*/
private final SSTableTracker tracker;
public final String path;
private final long size; import java.io.File;
private boolean deleteOnCleanup; import java.io.IOError;
import java.io.IOException;
SSTableDeletingReference(SSTableTracker tracker, SSTableReader referent, ReferenceQueue<? super SSTableReader> q) import java.lang.ref.PhantomReference;
{ import java.lang.ref.ReferenceQueue;
super(referent, q); import java.util.Timer;
this.tracker = tracker; import java.util.TimerTask;
this.path = referent.path;
this.size = referent.bytesOnDisk(); import org.apache.log4j.Logger;
}
import org.apache.cassandra.io.util.FileUtils;
public void deleteOnCleanup()
{ public class SSTableDeletingReference extends PhantomReference<SSTableReader>
deleteOnCleanup = true; {
} private static final Logger logger = Logger.getLogger(SSTableDeletingReference.class);
public void cleanup() throws IOException private static final Timer timer = new Timer("SSTABLE-CLEANUP-TIMER");
{ public static final int RETRY_DELAY = 10000;
if (deleteOnCleanup)
{ private final SSTableTracker tracker;
// this is tricky because the mmapping might not have been finalized yet, public final String path;
// and delete will fail until it is. additionally, we need to make sure to private final long size;
// delete the data file first, so on restart the others will be recognized as GCable private boolean deleteOnCleanup;
// even if the compaction marker gets deleted next.
timer.schedule(new CleanupTask(), RETRY_DELAY); SSTableDeletingReference(SSTableTracker tracker, SSTableReader referent, ReferenceQueue<? super SSTableReader> q)
} {
} super(referent, q);
this.tracker = tracker;
private class CleanupTask extends TimerTask this.path = referent.path;
{ this.size = referent.bytesOnDisk();
int attempts = 0; }
@Override public void deleteOnCleanup()
public void run() {
{ deleteOnCleanup = true;
File datafile = new File(path); }
if (!datafile.delete())
{ public void cleanup() throws IOException
if (attempts++ < DeletionService.MAX_RETRIES) {
{ if (deleteOnCleanup)
timer.schedule(this, RETRY_DELAY); {
return; // this is tricky because the mmapping might not have been finalized yet,
} // and delete will fail until it is. additionally, we need to make sure to
else // delete the data file first, so on restart the others will be recognized as GCable
{ // even if the compaction marker gets deleted next.
throw new RuntimeException("Unable to delete " + path); timer.schedule(new CleanupTask(), RETRY_DELAY);
} }
} }
try
{ private class CleanupTask extends TimerTask
FileUtils.deleteWithConfirm(new File(SSTable.indexFilename(path))); {
FileUtils.deleteWithConfirm(new File(SSTable.filterFilename(path))); int attempts = 0;
FileUtils.deleteWithConfirm(new File(SSTable.compactedFilename(path)));
} @Override
catch (IOException e) public void run()
{ {
throw new IOError(e); File datafile = new File(path);
} if (!datafile.delete())
tracker.spaceReclaimed(size); {
logger.info("Deleted " + path); if (attempts++ < DeletionService.MAX_RETRIES)
} {
} timer.schedule(this, RETRY_DELAY);
} return;
}
else
{
throw new RuntimeException("Unable to delete " + path);
}
}
try
{
FileUtils.deleteWithConfirm(new File(SSTable.indexFilename(path)));
FileUtils.deleteWithConfirm(new File(SSTable.filterFilename(path)));
FileUtils.deleteWithConfirm(new File(SSTable.compactedFilename(path)));
}
catch (IOException e)
{
throw new IOError(e);
}
tracker.spaceReclaimed(size);
logger.info("Deleted " + path);
}
}
}

View File

@ -1,18 +1,39 @@
package org.apache.cassandra.io.util; package org.apache.cassandra.io.util;
/*
import java.io.DataInput; *
import java.io.IOException; * Licensed to the Apache Software Foundation (ASF) under one
import java.io.Closeable; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
public interface FileDataInput extends DataInput, Closeable * regarding copyright ownership. The ASF licenses this file
{ * to you under the Apache License, Version 2.0 (the
public String getPath(); * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
public boolean isEOF() throws IOException; *
* http://www.apache.org/licenses/LICENSE-2.0
public void mark(); *
* Unless required by applicable law or agreed to in writing,
public void reset() throws IOException; * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
public int bytesPastMark(); * 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.IOException;
import java.io.Closeable;
public interface FileDataInput extends DataInput, Closeable
{
public String getPath();
public boolean isEOF() throws IOException;
public void mark();
public void reset() throws IOException;
public int bytesPastMark();
}

View File

@ -1,404 +1,425 @@
package org.apache.cassandra.io.util; package org.apache.cassandra.io.util;
/*
import java.nio.MappedByteBuffer; *
import java.io.*; * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
public class MappedFileDataInput extends InputStream implements FileDataInput * distributed with this work for additional information
{ * regarding copyright ownership. The ASF licenses this file
private final MappedByteBuffer buffer; * to you under the Apache License, Version 2.0 (the
private final String filename; * "License"); you may not use this file except in compliance
private int position; * with the License. You may obtain a copy of the License at
private int markedPosition; *
* http://www.apache.org/licenses/LICENSE-2.0
public MappedFileDataInput(MappedByteBuffer buffer, String filename) *
{ * Unless required by applicable law or agreed to in writing,
this(buffer, filename, 0); * 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
public MappedFileDataInput(MappedByteBuffer buffer, String filename, int position) * specific language governing permissions and limitations
{ * under the License.
assert buffer != null; *
this.buffer = buffer; */
this.filename = filename;
this.position = position;
} import java.nio.MappedByteBuffer;
import java.io.*;
// don't make this public, this is only for seeking WITHIN the current mapped segment
private void seekInternal(int pos) throws IOException public class MappedFileDataInput extends InputStream implements FileDataInput
{ {
position = pos; private final MappedByteBuffer buffer;
} private final String filename;
private int position;
@Override private int markedPosition;
public boolean markSupported()
{ public MappedFileDataInput(MappedByteBuffer buffer, String filename)
return true; {
} this(buffer, filename, 0);
}
@Override
public void mark(int ignored) public MappedFileDataInput(MappedByteBuffer buffer, String filename, int position)
{ {
markedPosition = position; assert buffer != null;
} this.buffer = buffer;
this.filename = filename;
@Override this.position = position;
public void reset() throws IOException }
{
seekInternal(markedPosition); // don't make this public, this is only for seeking WITHIN the current mapped segment
} private void seekInternal(int pos) throws IOException
{
public void mark() position = pos;
{ }
mark(-1);
} @Override
public boolean markSupported()
public int bytesPastMark() {
{ return true;
assert position >= markedPosition; }
return position - markedPosition;
} @Override
public void mark(int ignored)
public boolean isEOF() throws IOException {
{ markedPosition = position;
return position == buffer.capacity(); }
}
@Override
public String getPath() public void reset() throws IOException
{ {
return filename; seekInternal(markedPosition);
} }
public int read() throws IOException public void mark()
{ {
if (isEOF()) mark(-1);
return -1; }
return buffer.get(position++) & 0xFF;
} public int bytesPastMark()
{
public int skipBytes(int n) throws IOException assert position >= markedPosition;
{ return position - markedPosition;
if (n <= 0) }
return 0;
int oldPosition = position; public boolean isEOF() throws IOException
assert ((long)oldPosition) + n <= Integer.MAX_VALUE; {
position = Math.min(buffer.capacity(), position + n); return position == buffer.capacity();
return position - oldPosition; }
}
public String getPath()
/* {
!! DataInput methods below are copied from the implementation in Apache Harmony RandomAccessFile. return filename;
*/ }
/** public int read() throws IOException
* Reads a boolean from the current position in this file. Blocks until one {
* byte has been read, the end of the file is reached or an exception is if (isEOF())
* thrown. return -1;
* return buffer.get(position++) & 0xFF;
* @return the next boolean value from this file. }
* @throws EOFException
* if the end of this file is detected. public int skipBytes(int n) throws IOException
* @throws IOException {
* if this file is closed or another I/O error occurs. if (n <= 0)
*/ return 0;
public final boolean readBoolean() throws IOException { int oldPosition = position;
int temp = this.read(); assert ((long)oldPosition) + n <= Integer.MAX_VALUE;
if (temp < 0) { position = Math.min(buffer.capacity(), position + n);
throw new EOFException(); return position - oldPosition;
} }
return temp != 0;
} /*
!! DataInput methods below are copied from the implementation in Apache Harmony RandomAccessFile.
/** */
* Reads an 8-bit byte from the current position in this file. Blocks until
* one byte has been read, the end of the file is reached or an exception is /**
* thrown. * Reads a boolean from the current position in this file. Blocks until one
* * byte has been read, the end of the file is reached or an exception is
* @return the next signed 8-bit byte value from this file. * thrown.
* @throws EOFException *
* if the end of this file is detected. * @return the next boolean value from this file.
* @throws IOException * @throws EOFException
* if this file is closed or another I/O error occurs. * if the end of this file is detected.
*/ * @throws IOException
public final byte readByte() throws IOException { * if this file is closed or another I/O error occurs.
int temp = this.read(); */
if (temp < 0) { public final boolean readBoolean() throws IOException {
throw new EOFException(); int temp = this.read();
} if (temp < 0) {
return (byte) temp; throw new EOFException();
} }
return temp != 0;
/** }
* Reads a 16-bit character from the current position in this file. Blocks until
* two bytes have been read, the end of the file is reached or an exception is /**
* thrown. * Reads an 8-bit byte from the current position in this file. Blocks until
* * one byte has been read, the end of the file is reached or an exception is
* @return the next char value from this file. * thrown.
* @throws EOFException *
* if the end of this file is detected. * @return the next signed 8-bit byte value from this file.
* @throws IOException * @throws EOFException
* if this file is closed or another I/O error occurs. * if the end of this file is detected.
*/ * @throws IOException
public final char readChar() throws IOException { * if this file is closed or another I/O error occurs.
byte[] buffer = new byte[2]; */
if (read(buffer, 0, buffer.length) != buffer.length) { public final byte readByte() throws IOException {
throw new EOFException(); int temp = this.read();
} if (temp < 0) {
return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff)); throw new EOFException();
} }
return (byte) temp;
/** }
* Reads a 64-bit double from the current position in this file. Blocks
* until eight bytes have been read, the end of the file is reached or an /**
* exception is thrown. * Reads a 16-bit character from the current position in this file. Blocks until
* * two bytes have been read, the end of the file is reached or an exception is
* @return the next double value from this file. * thrown.
* @throws EOFException *
* if the end of this file is detected. * @return the next char value from this file.
* @throws IOException * @throws EOFException
* if this file is closed or another I/O error occurs. * if the end of this file is detected.
*/ * @throws IOException
public final double readDouble() throws IOException { * if this file is closed or another I/O error occurs.
return Double.longBitsToDouble(readLong()); */
} public final char readChar() throws IOException {
byte[] buffer = new byte[2];
/** if (read(buffer, 0, buffer.length) != buffer.length) {
* Reads a 32-bit float from the current position in this file. Blocks throw new EOFException();
* until four bytes have been read, the end of the file is reached or an }
* exception is thrown. return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
* }
* @return the next float value from this file.
* @throws EOFException /**
* if the end of this file is detected. * Reads a 64-bit double from the current position in this file. Blocks
* @throws IOException * until eight bytes have been read, the end of the file is reached or an
* if this file is closed or another I/O error occurs. * exception is thrown.
*/ *
public final float readFloat() throws IOException { * @return the next double value from this file.
return Float.intBitsToFloat(readInt()); * @throws EOFException
} * if the end of this file is detected.
* @throws IOException
/** * if this file is closed or another I/O error occurs.
* Reads bytes from this file into {@code buffer}. Blocks until {@code */
* buffer.length} number of bytes have been read, the end of the file is public final double readDouble() throws IOException {
* reached or an exception is thrown. return Double.longBitsToDouble(readLong());
* }
* @param buffer
* the buffer to read bytes into. /**
* @throws EOFException * Reads a 32-bit float from the current position in this file. Blocks
* if the end of this file is detected. * until four bytes have been read, the end of the file is reached or an
* @throws IOException * exception is thrown.
* if this file is closed or another I/O error occurs. *
* @throws NullPointerException * @return the next float value from this file.
* if {@code buffer} is {@code null}. * @throws EOFException
*/ * if the end of this file is detected.
public final void readFully(byte[] buffer) throws IOException { * @throws IOException
readFully(buffer, 0, buffer.length); * if this file is closed or another I/O error occurs.
} */
public final float readFloat() throws IOException {
/** return Float.intBitsToFloat(readInt());
* Read bytes from this file into {@code buffer} starting at offset {@code }
* offset}. This method blocks until {@code count} number of bytes have been
* read. /**
* * Reads bytes from this file into {@code buffer}. Blocks until {@code
* @param buffer * buffer.length} number of bytes have been read, the end of the file is
* the buffer to read bytes into. * reached or an exception is thrown.
* @param offset *
* the initial position in {@code buffer} to store the bytes read * @param buffer
* from this file. * the buffer to read bytes into.
* @param count * @throws EOFException
* the maximum number of bytes to store in {@code buffer}. * if the end of this file is detected.
* @throws EOFException * @throws IOException
* if the end of this file is detected. * if this file is closed or another I/O error occurs.
* @throws IndexOutOfBoundsException * @throws NullPointerException
* if {@code offset < 0} or {@code count < 0}, or if {@code * if {@code buffer} is {@code null}.
* offset + count} is greater than the length of {@code buffer}. */
* @throws IOException public final void readFully(byte[] buffer) throws IOException {
* if this file is closed or another I/O error occurs. readFully(buffer, 0, buffer.length);
* @throws NullPointerException }
* if {@code buffer} is {@code null}.
*/ /**
public final void readFully(byte[] buffer, int offset, int count) * Read bytes from this file into {@code buffer} starting at offset {@code
throws IOException { * offset}. This method blocks until {@code count} number of bytes have been
if (buffer == null) { * read.
throw new NullPointerException(); *
} * @param buffer
// avoid int overflow * the buffer to read bytes into.
if (offset < 0 || offset > buffer.length || count < 0 * @param offset
|| count > buffer.length - offset) { * the initial position in {@code buffer} to store the bytes read
throw new IndexOutOfBoundsException(); * from this file.
} * @param count
while (count > 0) { * the maximum number of bytes to store in {@code buffer}.
int result = read(buffer, offset, count); * @throws EOFException
if (result < 0) { * if the end of this file is detected.
throw new EOFException(); * @throws IndexOutOfBoundsException
} * if {@code offset < 0} or {@code count < 0}, or if {@code
offset += result; * offset + count} is greater than the length of {@code buffer}.
count -= result; * @throws IOException
} * if this file is closed or another I/O error occurs.
} * @throws NullPointerException
* if {@code buffer} is {@code null}.
/** */
* Reads a 32-bit integer from the current position in this file. Blocks public final void readFully(byte[] buffer, int offset, int count)
* until four bytes have been read, the end of the file is reached or an throws IOException {
* exception is thrown. if (buffer == null) {
* throw new NullPointerException();
* @return the next int value from this file. }
* @throws EOFException // avoid int overflow
* if the end of this file is detected. if (offset < 0 || offset > buffer.length || count < 0
* @throws IOException || count > buffer.length - offset) {
* if this file is closed or another I/O error occurs. throw new IndexOutOfBoundsException();
*/ }
public final int readInt() throws IOException { while (count > 0) {
byte[] buffer = new byte[4]; int result = read(buffer, offset, count);
if (read(buffer, 0, buffer.length) != buffer.length) { if (result < 0) {
throw new EOFException(); throw new EOFException();
} }
return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16) offset += result;
+ ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff); count -= result;
} }
}
/**
* Reads a line of text form the current position in this file. A line is /**
* represented by zero or more characters followed by {@code '\n'}, {@code * Reads a 32-bit integer from the current position in this file. Blocks
* '\r'}, {@code "\r\n"} or the end of file marker. The string does not * until four bytes have been read, the end of the file is reached or an
* include the line terminating sequence. * exception is thrown.
* <p> *
* Blocks until a line terminating sequence has been read, the end of the * @return the next int value from this file.
* file is reached or an exception is thrown. * @throws EOFException
* * if the end of this file is detected.
* @return the contents of the line or {@code null} if no characters have * @throws IOException
* been read before the end of the file has been reached. * if this file is closed or another I/O error occurs.
* @throws IOException */
* if this file is closed or another I/O error occurs. public final int readInt() throws IOException {
*/ byte[] buffer = new byte[4];
public final String readLine() throws IOException { if (read(buffer, 0, buffer.length) != buffer.length) {
StringBuilder line = new StringBuilder(80); // Typical line length throw new EOFException();
boolean foundTerminator = false; }
int unreadPosition = 0; return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
while (true) { + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
int nextByte = read(); }
switch (nextByte) {
case -1: /**
return line.length() != 0 ? line.toString() : null; * Reads a line of text form the current position in this file. A line is
case (byte) '\r': * represented by zero or more characters followed by {@code '\n'}, {@code
if (foundTerminator) { * '\r'}, {@code "\r\n"} or the end of file marker. The string does not
seekInternal(unreadPosition); * include the line terminating sequence.
return line.toString(); * <p>
} * Blocks until a line terminating sequence has been read, the end of the
foundTerminator = true; * file is reached or an exception is thrown.
/* Have to be able to peek ahead one byte */ *
unreadPosition = position; * @return the contents of the line or {@code null} if no characters have
break; * been read before the end of the file has been reached.
case (byte) '\n': * @throws IOException
return line.toString(); * if this file is closed or another I/O error occurs.
default: */
if (foundTerminator) { public final String readLine() throws IOException {
seekInternal(unreadPosition); StringBuilder line = new StringBuilder(80); // Typical line length
return line.toString(); boolean foundTerminator = false;
} int unreadPosition = 0;
line.append((char) nextByte); while (true) {
} int nextByte = read();
} switch (nextByte) {
} case -1:
return line.length() != 0 ? line.toString() : null;
/** case (byte) '\r':
* Reads a 64-bit long from the current position in this file. Blocks until if (foundTerminator) {
* eight bytes have been read, the end of the file is reached or an seekInternal(unreadPosition);
* exception is thrown. return line.toString();
* }
* @return the next long value from this file. foundTerminator = true;
* @throws EOFException /* Have to be able to peek ahead one byte */
* if the end of this file is detected. unreadPosition = position;
* @throws IOException break;
* if this file is closed or another I/O error occurs. case (byte) '\n':
*/ return line.toString();
public final long readLong() throws IOException { default:
byte[] buffer = new byte[8]; if (foundTerminator) {
int n = read(buffer, 0, buffer.length); seekInternal(unreadPosition);
if (n != buffer.length) { return line.toString();
throw new EOFException("expected 8 bytes; read " + n + " at final position " + position); }
} line.append((char) nextByte);
return ((long) (((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16) }
+ ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32) }
+ ((long) (buffer[4] & 0xff) << 24) }
+ ((buffer[5] & 0xff) << 16)
+ ((buffer[6] & 0xff) << 8) /**
+ (buffer[7] & 0xff); * Reads a 64-bit long from the current position in this file. Blocks until
} * eight bytes have been read, the end of the file is reached or an
* exception is thrown.
/** *
* Reads a 16-bit short from the current position in this file. Blocks until * @return the next long value from this file.
* two bytes have been read, the end of the file is reached or an exception * @throws EOFException
* is thrown. * if the end of this file is detected.
* * @throws IOException
* @return the next short value from this file. * if this file is closed or another I/O error occurs.
* @throws EOFException */
* if the end of this file is detected. public final long readLong() throws IOException {
* @throws IOException byte[] buffer = new byte[8];
* if this file is closed or another I/O error occurs. int n = read(buffer, 0, buffer.length);
*/ if (n != buffer.length) {
public final short readShort() throws IOException { throw new EOFException("expected 8 bytes; read " + n + " at final position " + position);
byte[] buffer = new byte[2]; }
if (read(buffer, 0, buffer.length) != buffer.length) { return ((long) (((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
throw new EOFException(); + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32)
} + ((long) (buffer[4] & 0xff) << 24)
return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff)); + ((buffer[5] & 0xff) << 16)
} + ((buffer[6] & 0xff) << 8)
+ (buffer[7] & 0xff);
/** }
* Reads an unsigned 8-bit byte from the current position in this file and
* returns it as an integer. Blocks until one byte has been read, the end of /**
* the file is reached or an exception is thrown. * Reads a 16-bit short from the current position in this file. Blocks until
* * two bytes have been read, the end of the file is reached or an exception
* @return the next unsigned byte value from this file as an int. * is thrown.
* @throws EOFException *
* if the end of this file is detected. * @return the next short value from this file.
* @throws IOException * @throws EOFException
* if this file is closed or another I/O error occurs. * if the end of this file is detected.
*/ * @throws IOException
public final int readUnsignedByte() throws IOException { * if this file is closed or another I/O error occurs.
int temp = this.read(); */
if (temp < 0) { public final short readShort() throws IOException {
throw new EOFException(); byte[] buffer = new byte[2];
} if (read(buffer, 0, buffer.length) != buffer.length) {
return temp; throw new EOFException();
} }
return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
/** }
* Reads an unsigned 16-bit short from the current position in this file and
* returns it as an integer. Blocks until two bytes have been read, the end of /**
* the file is reached or an exception is thrown. * Reads an unsigned 8-bit byte from the current position in this file and
* * returns it as an integer. Blocks until one byte has been read, the end of
* @return the next unsigned short value from this file as an int. * the file is reached or an exception is thrown.
* @throws EOFException *
* if the end of this file is detected. * @return the next unsigned byte value from this file as an int.
* @throws IOException * @throws EOFException
* if this file is closed or another I/O error occurs. * if the end of this file is detected.
*/ * @throws IOException
public final int readUnsignedShort() throws IOException { * if this file is closed or another I/O error occurs.
byte[] buffer = new byte[2]; */
if (read(buffer, 0, buffer.length) != buffer.length) { public final int readUnsignedByte() throws IOException {
throw new EOFException(); int temp = this.read();
} if (temp < 0) {
return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff); throw new EOFException();
} }
return temp;
/** }
* Reads a string that is encoded in {@link DataInput modified UTF-8} from
* this file. The number of bytes that must be read for the complete string /**
* is determined by the first two bytes read from the file. Blocks until all * Reads an unsigned 16-bit short from the current position in this file and
* required bytes have been read, the end of the file is reached or an * returns it as an integer. Blocks until two bytes have been read, the end of
* exception is thrown. * the file is reached or an exception is thrown.
* *
* @return the next string encoded in {@link DataInput modified UTF-8} from * @return the next unsigned short value from this file as an int.
* this file. * @throws EOFException
* @throws EOFException * if the end of this file is detected.
* if the end of this file is detected. * @throws IOException
* @throws IOException * if this file is closed or another I/O error occurs.
* if this file is closed or another I/O error occurs. */
* @throws UTFDataFormatException public final int readUnsignedShort() throws IOException {
* if the bytes read cannot be decoded into a character string. byte[] buffer = new byte[2];
*/ if (read(buffer, 0, buffer.length) != buffer.length) {
public final String readUTF() throws IOException { throw new EOFException();
return DataInputStream.readUTF(this); }
} return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff);
} }
/**
* Reads a string that is encoded in {@link DataInput modified UTF-8} from
* this file. The number of bytes that must be read for the complete string
* is determined by the first two bytes read from the file. Blocks until all
* required bytes have been read, the end of the file is reached or an
* exception is thrown.
*
* @return the next string encoded in {@link DataInput modified UTF-8} from
* this file.
* @throws EOFException
* if the end of this file is detected.
* @throws IOException
* if this file is closed or another I/O error occurs.
* @throws UTFDataFormatException
* if the bytes read cannot be decoded into a character string.
*/
public final String readUTF() throws IOException {
return DataInputStream.readUTF(this);
}
}

View File

@ -1,69 +1,90 @@
package org.apache.cassandra.net; package org.apache.cassandra.net;
/*
import java.io.*; *
import java.net.Socket; * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
import org.apache.log4j.Logger; * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
import org.apache.cassandra.streaming.IncomingStreamReader; * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
public class IncomingTcpConnection extends Thread * with the License. You may obtain a copy of the License at
{ *
private static Logger logger = Logger.getLogger(IncomingTcpConnection.class); * http://www.apache.org/licenses/LICENSE-2.0
*
private final DataInputStream input; * Unless required by applicable law or agreed to in writing,
private Socket socket; * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
public IncomingTcpConnection(Socket socket) * KIND, either express or implied. See the License for the
{ * specific language governing permissions and limitations
this.socket = socket; * under the License.
try *
{ */
input = new DataInputStream(socket.getInputStream());
}
catch (IOException e) import java.io.*;
{ import java.net.Socket;
throw new IOError(e);
} import org.apache.log4j.Logger;
}
import org.apache.cassandra.streaming.IncomingStreamReader;
@Override
public void run() public class IncomingTcpConnection extends Thread
{ {
while (true) private static Logger logger = Logger.getLogger(IncomingTcpConnection.class);
{
try private final DataInputStream input;
{ private Socket socket;
MessagingService.validateMagic(input.readInt());
int header = input.readInt(); public IncomingTcpConnection(Socket socket)
int type = MessagingService.getBits(header, 1, 2); {
boolean isStream = MessagingService.getBits(header, 3, 1) == 1; this.socket = socket;
int version = MessagingService.getBits(header, 15, 8); try
{
if (isStream) input = new DataInputStream(socket.getInputStream());
{ }
new IncomingStreamReader(socket.getChannel()).read(); catch (IOException e)
} {
else throw new IOError(e);
{ }
int size = input.readInt(); }
byte[] contentBytes = new byte[size];
input.readFully(contentBytes); @Override
MessagingService.getDeserializationExecutor().submit(new MessageDeserializationTask(new ByteArrayInputStream(contentBytes))); public void run()
} {
} while (true)
catch (EOFException e) {
{ try
if (logger.isTraceEnabled()) {
logger.trace("eof reading from socket; closing", e); MessagingService.validateMagic(input.readInt());
break; int header = input.readInt();
} int type = MessagingService.getBits(header, 1, 2);
catch (IOException e) boolean isStream = MessagingService.getBits(header, 3, 1) == 1;
{ int version = MessagingService.getBits(header, 15, 8);
if (logger.isDebugEnabled())
logger.debug("error reading from socket; closing", e); if (isStream)
break; {
} new IncomingStreamReader(socket.getChannel()).read();
} }
} else
} {
int size = input.readInt();
byte[] contentBytes = new byte[size];
input.readFully(contentBytes);
MessagingService.getDeserializationExecutor().submit(new MessageDeserializationTask(new ByteArrayInputStream(contentBytes)));
}
}
catch (EOFException e)
{
if (logger.isTraceEnabled())
logger.trace("eof reading from socket; closing", e);
break;
}
catch (IOException e)
{
if (logger.isDebugEnabled())
logger.debug("error reading from socket; closing", e);
break;
}
}
}
}

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.net; package org.apache.cassandra.net;
/*
*
* 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.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.service; package org.apache.cassandra.service;
/*
*
* 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.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;

View File

@ -1,100 +1,121 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
import java.io.ByteArrayOutputStream; *
import java.io.DataInputStream; * Licensed to the Apache Software Foundation (ASF) under one
import java.io.DataOutputStream; * or more contributor license agreements. See the NOTICE file
import java.io.IOException; * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
import org.apache.cassandra.io.ICompactSerializer; * to you under the Apache License, Version 2.0 (the
import org.apache.cassandra.net.Message; * "License"); you may not use this file except in compliance
import org.apache.cassandra.service.StorageService; * with the License. You may obtain a copy of the License at
import org.apache.cassandra.utils.FBUtilities; *
* http://www.apache.org/licenses/LICENSE-2.0
class CompletedFileStatus *
{ * Unless required by applicable law or agreed to in writing,
private static ICompactSerializer<CompletedFileStatus> serializer_; * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
public static enum StreamCompletionAction * KIND, either express or implied. See the License for the
{ * specific language governing permissions and limitations
DELETE, * under the License.
STREAM *
} */
static
{ import java.io.ByteArrayOutputStream;
serializer_ = new CompletedFileStatusSerializer(); import java.io.DataInputStream;
} import java.io.DataOutputStream;
import java.io.IOException;
public static ICompactSerializer<CompletedFileStatus> serializer()
{ import org.apache.cassandra.io.ICompactSerializer;
return serializer_; import org.apache.cassandra.net.Message;
} import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.utils.FBUtilities;
private String file_;
private long expectedBytes_; class CompletedFileStatus
private StreamCompletionAction action_; {
private static ICompactSerializer<CompletedFileStatus> serializer_;
public CompletedFileStatus(String file, long expectedBytes)
{ public static enum StreamCompletionAction
file_ = file; {
expectedBytes_ = expectedBytes; DELETE,
action_ = StreamCompletionAction.DELETE; STREAM
} }
public String getFile() static
{ {
return file_; serializer_ = new CompletedFileStatusSerializer();
} }
public long getExpectedBytes() public static ICompactSerializer<CompletedFileStatus> serializer()
{ {
return expectedBytes_; return serializer_;
} }
public void setAction(StreamCompletionAction action) private String file_;
{ private long expectedBytes_;
action_ = action; private StreamCompletionAction action_;
}
public CompletedFileStatus(String file, long expectedBytes)
public StreamCompletionAction getAction() {
{ file_ = file;
return action_; expectedBytes_ = expectedBytes;
} action_ = StreamCompletionAction.DELETE;
}
public Message makeStreamStatusMessage() throws IOException
{ public String getFile()
ByteArrayOutputStream bos = new ByteArrayOutputStream(); {
DataOutputStream dos = new DataOutputStream( bos ); return file_;
CompletedFileStatus.serializer().serialize(this, dos); }
return new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_FINISHED, bos.toByteArray());
} public long getExpectedBytes()
{
private static class CompletedFileStatusSerializer implements ICompactSerializer<CompletedFileStatus> return expectedBytes_;
{ }
public void serialize(CompletedFileStatus streamStatus, DataOutputStream dos) throws IOException
{ public void setAction(StreamCompletionAction action)
dos.writeUTF(streamStatus.getFile()); {
dos.writeLong(streamStatus.getExpectedBytes()); action_ = action;
dos.writeInt(streamStatus.getAction().ordinal()); }
}
public StreamCompletionAction getAction()
public CompletedFileStatus deserialize(DataInputStream dis) throws IOException {
{ return action_;
String targetFile = dis.readUTF(); }
long expectedBytes = dis.readLong();
CompletedFileStatus streamStatus = new CompletedFileStatus(targetFile, expectedBytes); public Message makeStreamStatusMessage() throws IOException
{
int ordinal = dis.readInt(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
if ( ordinal == StreamCompletionAction.DELETE.ordinal() ) DataOutputStream dos = new DataOutputStream( bos );
{ CompletedFileStatus.serializer().serialize(this, dos);
streamStatus.setAction(StreamCompletionAction.DELETE); return new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_FINISHED, bos.toByteArray());
} }
else if ( ordinal == StreamCompletionAction.STREAM.ordinal() )
{ private static class CompletedFileStatusSerializer implements ICompactSerializer<CompletedFileStatus>
streamStatus.setAction(StreamCompletionAction.STREAM); {
} public void serialize(CompletedFileStatus streamStatus, DataOutputStream dos) throws IOException
{
return streamStatus; dos.writeUTF(streamStatus.getFile());
} dos.writeLong(streamStatus.getExpectedBytes());
} dos.writeInt(streamStatus.getAction().ordinal());
} }
public CompletedFileStatus deserialize(DataInputStream dis) throws IOException
{
String targetFile = dis.readUTF();
long expectedBytes = dis.readLong();
CompletedFileStatus streamStatus = new CompletedFileStatus(targetFile, expectedBytes);
int ordinal = dis.readInt();
if ( ordinal == StreamCompletionAction.DELETE.ordinal() )
{
streamStatus.setAction(StreamCompletionAction.DELETE);
}
else if ( ordinal == StreamCompletionAction.STREAM.ordinal() )
{
streamStatus.setAction(StreamCompletionAction.STREAM);
}
return streamStatus;
}
}
}

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
*
* 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.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;

View File

@ -1,62 +1,83 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
import java.io.File; *
import java.io.IOException; * Licensed to the Apache Software Foundation (ASF) under one
import java.net.InetAddress; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
import org.apache.log4j.Logger; * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
import org.apache.cassandra.db.Table; * "License"); you may not use this file except in compliance
import org.apache.cassandra.io.SSTableReader; * with the License. You may obtain a copy of the License at
import org.apache.cassandra.io.SSTableWriter; *
import org.apache.cassandra.net.MessagingService; * http://www.apache.org/licenses/LICENSE-2.0
import org.apache.cassandra.streaming.IStreamComplete; *
import org.apache.cassandra.streaming.StreamInManager; * Unless required by applicable law or agreed to in writing,
import org.apache.cassandra.service.StorageService; * 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
* This is the callback handler that is invoked when we have * specific language governing permissions and limitations
* completely received a single file from a remote host. * under the License.
* *
* TODO if we move this into CFS we could make addSSTables private, improving encapsulation. */
*/
class StreamCompletionHandler implements IStreamComplete
{ import java.io.File;
private static Logger logger = Logger.getLogger(StreamCompletionHandler.class); import java.io.IOException;
import java.net.InetAddress;
public void onStreamCompletion(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus) throws IOException
{ import org.apache.log4j.Logger;
/* Parse the stream context and the file to the list of SSTables in the associated Column Family Store. */
if (pendingFile.getTargetFile().contains("-Data.db")) import org.apache.cassandra.db.Table;
{ import org.apache.cassandra.io.SSTableReader;
String tableName = pendingFile.getTable(); import org.apache.cassandra.io.SSTableWriter;
File file = new File( pendingFile.getTargetFile() ); import org.apache.cassandra.net.MessagingService;
String fileName = file.getName(); import org.apache.cassandra.streaming.IStreamComplete;
String [] temp = fileName.split("-"); import org.apache.cassandra.streaming.StreamInManager;
import org.apache.cassandra.service.StorageService;
//Open the file to see if all parts are now here
try /**
{ * This is the callback handler that is invoked when we have
SSTableReader sstable = SSTableWriter.renameAndOpen(pendingFile.getTargetFile()); * completely received a single file from a remote host.
//TODO add a sanity check that this sstable has all its parts and is ok *
Table.open(tableName).getColumnFamilyStore(temp[0]).addSSTable(sstable); * TODO if we move this into CFS we could make addSSTables private, improving encapsulation.
logger.info("Streaming added " + sstable.getFilename()); */
} class StreamCompletionHandler implements IStreamComplete
catch (IOException e) {
{ private static Logger logger = Logger.getLogger(StreamCompletionHandler.class);
throw new RuntimeException("Not able to add streamed file " + pendingFile.getTargetFile(), e);
} public void onStreamCompletion(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus) throws IOException
} {
/* Parse the stream context and the file to the list of SSTables in the associated Column Family Store. */
if (logger.isDebugEnabled()) if (pendingFile.getTargetFile().contains("-Data.db"))
logger.debug("Sending a streaming finished message with " + streamStatus + " to " + host); {
/* Send a StreamStatus message which may require the source node to re-stream certain files. */ String tableName = pendingFile.getTable();
MessagingService.instance.sendOneWay(streamStatus.makeStreamStatusMessage(), host); File file = new File( pendingFile.getTargetFile() );
String fileName = file.getName();
/* If we're done with everything for this host, remove from bootstrap sources */ String [] temp = fileName.split("-");
if (StreamInManager.isDone(host) && StorageService.instance.isBootstrapMode())
{ //Open the file to see if all parts are now here
StorageService.instance.removeBootstrapSource(host, pendingFile.getTable()); try
} {
} SSTableReader sstable = SSTableWriter.renameAndOpen(pendingFile.getTargetFile());
} //TODO add a sanity check that this sstable has all its parts and is ok
Table.open(tableName).getColumnFamilyStore(temp[0]).addSSTable(sstable);
logger.info("Streaming added " + sstable.getFilename());
}
catch (IOException e)
{
throw new RuntimeException("Not able to add streamed file " + pendingFile.getTargetFile(), e);
}
}
if (logger.isDebugEnabled())
logger.debug("Sending a streaming finished message with " + streamStatus + " to " + host);
/* Send a StreamStatus message which may require the source node to re-stream certain files. */
MessagingService.instance.sendOneWay(streamStatus.makeStreamStatusMessage(), host);
/* If we're done with everything for this host, remove from bootstrap sources */
if (StreamInManager.isDone(host) && StorageService.instance.isBootstrapMode())
{
StorageService.instance.removeBootstrapSource(host, pendingFile.getTable());
}
}
}

View File

@ -1,48 +1,69 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
import java.io.ByteArrayInputStream; *
import java.io.DataInputStream; * Licensed to the Apache Software Foundation (ASF) under one
import java.io.IOError; * or more contributor license agreements. See the NOTICE file
import java.io.IOException; * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
import org.apache.log4j.Logger; * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
import org.apache.cassandra.net.IVerbHandler; * with the License. You may obtain a copy of the License at
import org.apache.cassandra.net.Message; *
import org.apache.cassandra.streaming.StreamOutManager; * http://www.apache.org/licenses/LICENSE-2.0
*
public class StreamFinishedVerbHandler implements IVerbHandler * Unless required by applicable law or agreed to in writing,
{ * software distributed under the License is distributed on an
private static Logger logger = Logger.getLogger(StreamFinishedVerbHandler.class); * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
public void doVerb(Message message) * specific language governing permissions and limitations
{ * under the License.
byte[] body = message.getMessageBody(); *
ByteArrayInputStream bufIn = new ByteArrayInputStream(body); */
try
{ import java.io.ByteArrayInputStream;
CompletedFileStatus streamStatus = CompletedFileStatus.serializer().deserialize(new DataInputStream(bufIn)); import java.io.DataInputStream;
import java.io.IOError;
switch (streamStatus.getAction()) import java.io.IOException;
{
case DELETE: import org.apache.log4j.Logger;
StreamOutManager.get(message.getFrom()).finishAndStartNext(streamStatus.getFile());
break; import org.apache.cassandra.net.IVerbHandler;
import org.apache.cassandra.net.Message;
case STREAM: import org.apache.cassandra.streaming.StreamOutManager;
if (logger.isDebugEnabled())
logger.debug("Need to re-stream file " + streamStatus.getFile()); public class StreamFinishedVerbHandler implements IVerbHandler
StreamOutManager.get(message.getFrom()).startNext(); {
break; private static Logger logger = Logger.getLogger(StreamFinishedVerbHandler.class);
default: public void doVerb(Message message)
break; {
} byte[] body = message.getMessageBody();
} ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
catch (IOException ex)
{ try
throw new IOError(ex); {
} CompletedFileStatus streamStatus = CompletedFileStatus.serializer().deserialize(new DataInputStream(bufIn));
}
} switch (streamStatus.getAction())
{
case DELETE:
StreamOutManager.get(message.getFrom()).finishAndStartNext(streamStatus.getFile());
break;
case STREAM:
if (logger.isDebugEnabled())
logger.debug("Need to re-stream file " + streamStatus.getFile());
StreamOutManager.get(message.getFrom()).startNext();
break;
default:
break;
}
}
catch (IOException ex)
{
throw new IOError(ex);
}
}
}

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
*
* 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.net.InetAddress; import java.net.InetAddress;
import java.util.Collection; import java.util.Collection;

View File

@ -1,19 +1,40 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
import org.apache.log4j.Logger; *
* Licensed to the Apache Software Foundation (ASF) under one
import org.apache.cassandra.net.IVerbHandler; * or more contributor license agreements. See the NOTICE file
import org.apache.cassandra.net.Message; * distributed with this work for additional information
import org.apache.cassandra.streaming.StreamOutManager; * regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
public class StreamInitiateDoneVerbHandler implements IVerbHandler * "License"); you may not use this file except in compliance
{ * with the License. You may obtain a copy of the License at
private static Logger logger = Logger.getLogger(StreamInitiateDoneVerbHandler.class); *
* http://www.apache.org/licenses/LICENSE-2.0
public void doVerb(Message message) *
{ * Unless required by applicable law or agreed to in writing,
if (logger.isDebugEnabled()) * software distributed under the License is distributed on an
logger.debug("Received a stream initiate done message ..."); * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
StreamOutManager.get(message.getFrom()).startNext(); * KIND, either express or implied. See the License for the
} * specific language governing permissions and limitations
} * under the License.
*
*/
import org.apache.log4j.Logger;
import org.apache.cassandra.net.IVerbHandler;
import org.apache.cassandra.net.Message;
import org.apache.cassandra.streaming.StreamOutManager;
public class StreamInitiateDoneVerbHandler implements IVerbHandler
{
private static Logger logger = Logger.getLogger(StreamInitiateDoneVerbHandler.class);
public void doVerb(Message message)
{
if (logger.isDebugEnabled())
logger.debug("Received a stream initiate done message ...");
StreamOutManager.get(message.getFrom()).startNext();
}
}

View File

@ -1,145 +1,166 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
import java.io.*; *
import java.net.InetAddress; * Licensed to the Apache Software Foundation (ASF) under one
import java.util.HashMap; * or more contributor license agreements. See the NOTICE file
import java.util.HashSet; * distributed with this work for additional information
import java.util.Map; * regarding copyright ownership. The ASF licenses this file
import java.util.Set; * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
import org.apache.log4j.Logger; * with the License. You may obtain a copy of the License at
*
import org.apache.cassandra.config.DatabaseDescriptor; * http://www.apache.org/licenses/LICENSE-2.0
import org.apache.cassandra.db.ColumnFamilyStore; *
import org.apache.cassandra.db.Table; * Unless required by applicable law or agreed to in writing,
import org.apache.cassandra.streaming.StreamInitiateMessage; * software distributed under the License is distributed on an
import org.apache.cassandra.net.IVerbHandler; * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
import org.apache.cassandra.net.Message; * KIND, either express or implied. See the License for the
import org.apache.cassandra.net.MessagingService; * specific language governing permissions and limitations
import org.apache.cassandra.streaming.StreamInManager; * under the License.
import org.apache.cassandra.service.StorageService; *
import org.apache.cassandra.utils.FBUtilities; */
public class StreamInitiateVerbHandler implements IVerbHandler
{ import java.io.*;
private static Logger logger = Logger.getLogger(StreamInitiateVerbHandler.class); import java.net.InetAddress;
import java.util.HashMap;
/* import java.util.HashSet;
* Here we handle the StreamInitiateMessage. Here we get the import java.util.Map;
* array of StreamContexts. We get file names for the column import java.util.Set;
* families associated with the files and replace them with the
* file names as obtained from the column family store on the import org.apache.log4j.Logger;
* receiving end.
*/ import org.apache.cassandra.config.DatabaseDescriptor;
public void doVerb(Message message) import org.apache.cassandra.db.ColumnFamilyStore;
{ import org.apache.cassandra.db.Table;
byte[] body = message.getMessageBody(); import org.apache.cassandra.streaming.StreamInitiateMessage;
ByteArrayInputStream bufIn = new ByteArrayInputStream(body); import org.apache.cassandra.net.IVerbHandler;
if (logger.isDebugEnabled()) import org.apache.cassandra.net.Message;
logger.debug(String.format("StreamInitiateVerbeHandler.doVerb %s %s %s", message.getVerb(), message.getMessageId(), message.getMessageType())); import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.streaming.StreamInManager;
try import org.apache.cassandra.service.StorageService;
{ import org.apache.cassandra.utils.FBUtilities;
StreamInitiateMessage biMsg = StreamInitiateMessage.serializer().deserialize(new DataInputStream(bufIn));
PendingFile[] pendingFiles = biMsg.getStreamContext(); public class StreamInitiateVerbHandler implements IVerbHandler
{
if (pendingFiles.length == 0) private static Logger logger = Logger.getLogger(StreamInitiateVerbHandler.class);
{
if (logger.isDebugEnabled()) /*
logger.debug("no data needed from " + message.getFrom()); * Here we handle the StreamInitiateMessage. Here we get the
if (StorageService.instance.isBootstrapMode()) * array of StreamContexts. We get file names for the column
StorageService.instance.removeBootstrapSource(message.getFrom(), new String(message.getHeader(StreamOut.TABLE_NAME))); * families associated with the files and replace them with the
return; * file names as obtained from the column family store on the
} * receiving end.
*/
Map<String, String> fileNames = getNewNames(pendingFiles); public void doVerb(Message message)
Map<String, String> pathNames = new HashMap<String, String>(); {
for (String ssName : fileNames.keySet()) byte[] body = message.getMessageBody();
pathNames.put(ssName, DatabaseDescriptor.getNextAvailableDataLocation()); ByteArrayInputStream bufIn = new ByteArrayInputStream(body);
/* if (logger.isDebugEnabled())
* For each of stream context's in the incoming message logger.debug(String.format("StreamInitiateVerbeHandler.doVerb %s %s %s", message.getVerb(), message.getMessageId(), message.getMessageType()));
* generate the new file names and store the new file names
* in the StreamContextManager. try
*/ {
for (PendingFile pendingFile : pendingFiles) StreamInitiateMessage biMsg = StreamInitiateMessage.serializer().deserialize(new DataInputStream(bufIn));
{ PendingFile[] pendingFiles = biMsg.getStreamContext();
CompletedFileStatus streamStatus = new CompletedFileStatus(pendingFile.getTargetFile(), pendingFile.getExpectedBytes() );
String file = getNewFileNameFromOldContextAndNames(fileNames, pathNames, pendingFile); if (pendingFiles.length == 0)
{
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Received Data from : " + message.getFrom() + " " + pendingFile.getTargetFile() + " " + file); logger.debug("no data needed from " + message.getFrom());
pendingFile.setTargetFile(file); if (StorageService.instance.isBootstrapMode())
addStreamContext(message.getFrom(), pendingFile, streamStatus); StorageService.instance.removeBootstrapSource(message.getFrom(), new String(message.getHeader(StreamOut.TABLE_NAME)));
} return;
}
StreamInManager.registerStreamCompletionHandler(message.getFrom(), new StreamCompletionHandler());
if (logger.isDebugEnabled()) Map<String, String> fileNames = getNewNames(pendingFiles);
logger.debug("Sending a stream initiate done message ..."); Map<String, String> pathNames = new HashMap<String, String>();
Message doneMessage = new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_INITIATE_DONE, new byte[0] ); for (String ssName : fileNames.keySet())
MessagingService.instance.sendOneWay(doneMessage, message.getFrom()); pathNames.put(ssName, DatabaseDescriptor.getNextAvailableDataLocation());
} /*
catch (IOException ex) * For each of stream context's in the incoming message
{ * generate the new file names and store the new file names
throw new IOError(ex); * in the StreamContextManager.
} */
} for (PendingFile pendingFile : pendingFiles)
{
public String getNewFileNameFromOldContextAndNames(Map<String, String> fileNames, CompletedFileStatus streamStatus = new CompletedFileStatus(pendingFile.getTargetFile(), pendingFile.getExpectedBytes() );
Map<String, String> pathNames, String file = getNewFileNameFromOldContextAndNames(fileNames, pathNames, pendingFile);
PendingFile pendingFile)
{ if (logger.isDebugEnabled())
File sourceFile = new File( pendingFile.getTargetFile() ); logger.debug("Received Data from : " + message.getFrom() + " " + pendingFile.getTargetFile() + " " + file);
String[] piece = FBUtilities.strip(sourceFile.getName(), "-"); pendingFile.setTargetFile(file);
String cfName = piece[0]; addStreamContext(message.getFrom(), pendingFile, streamStatus);
String ssTableNum = piece[1]; }
String typeOfFile = piece[2];
StreamInManager.registerStreamCompletionHandler(message.getFrom(), new StreamCompletionHandler());
String newFileNameExpanded = fileNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum); if (logger.isDebugEnabled())
String path = pathNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum); logger.debug("Sending a stream initiate done message ...");
//Drop type (Data.db) from new FileName Message doneMessage = new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_INITIATE_DONE, new byte[0] );
String newFileName = newFileNameExpanded.replace("Data.db", typeOfFile); MessagingService.instance.sendOneWay(doneMessage, message.getFrom());
return path + File.separator + pendingFile.getTable() + File.separator + newFileName; }
} catch (IOException ex)
{
// todo: this method needs to be private, or package at the very least for easy unit testing. throw new IOError(ex);
public Map<String, String> getNewNames(PendingFile[] pendingFiles) throws IOException }
{ }
/*
* Mapping for each file with unique CF-i ---> new file name. For eg. public String getNewFileNameFromOldContextAndNames(Map<String, String> fileNames,
* for a file with name <CF>-<i>-Data.db there is a corresponding Map<String, String> pathNames,
* <CF>-<i>-Index.db. We maintain a mapping from <CF>-<i> to a newly PendingFile pendingFile)
* generated file name. {
*/ File sourceFile = new File( pendingFile.getTargetFile() );
Map<String, String> fileNames = new HashMap<String, String>(); String[] piece = FBUtilities.strip(sourceFile.getName(), "-");
/* Get the distinct entries from StreamContexts i.e have one entry per Data/Index/Filter file set */ String cfName = piece[0];
Set<String> distinctEntries = new HashSet<String>(); String ssTableNum = piece[1];
for ( PendingFile pendingFile : pendingFiles) String typeOfFile = piece[2];
{
String[] pieces = FBUtilities.strip(new File(pendingFile.getTargetFile()).getName(), "-"); String newFileNameExpanded = fileNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum);
distinctEntries.add(pendingFile.getTable() + "-" + pieces[0] + "-" + pieces[1] ); String path = pathNames.get(pendingFile.getTable() + "-" + cfName + "-" + ssTableNum);
} //Drop type (Data.db) from new FileName
String newFileName = newFileNameExpanded.replace("Data.db", typeOfFile);
/* Generate unique file names per entry */ return path + File.separator + pendingFile.getTable() + File.separator + newFileName;
for ( String distinctEntry : distinctEntries ) }
{
String tableName; // todo: this method needs to be private, or package at the very least for easy unit testing.
String[] pieces = FBUtilities.strip(distinctEntry, "-"); public Map<String, String> getNewNames(PendingFile[] pendingFiles) throws IOException
tableName = pieces[0]; {
Table table = Table.open( tableName ); /*
* Mapping for each file with unique CF-i ---> new file name. For eg.
ColumnFamilyStore cfStore = table.getColumnFamilyStore(pieces[1]); * for a file with name <CF>-<i>-Data.db there is a corresponding
if (logger.isDebugEnabled()) * <CF>-<i>-Index.db. We maintain a mapping from <CF>-<i> to a newly
logger.debug("Generating file name for " + distinctEntry + " ..."); * generated file name.
fileNames.put(distinctEntry, cfStore.getTempSSTableFileName()); */
} Map<String, String> fileNames = new HashMap<String, String>();
/* Get the distinct entries from StreamContexts i.e have one entry per Data/Index/Filter file set */
return fileNames; Set<String> distinctEntries = new HashSet<String>();
} for ( PendingFile pendingFile : pendingFiles)
{
private void addStreamContext(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus) String[] pieces = FBUtilities.strip(new File(pendingFile.getTargetFile()).getName(), "-");
{ distinctEntries.add(pendingFile.getTable() + "-" + pieces[0] + "-" + pieces[1] );
if (logger.isDebugEnabled()) }
logger.debug("Adding stream context " + pendingFile + " for " + host + " ...");
StreamInManager.addStreamContext(host, pendingFile, streamStatus); /* Generate unique file names per entry */
} for ( String distinctEntry : distinctEntries )
} {
String tableName;
String[] pieces = FBUtilities.strip(distinctEntry, "-");
tableName = pieces[0];
Table table = Table.open( tableName );
ColumnFamilyStore cfStore = table.getColumnFamilyStore(pieces[1]);
if (logger.isDebugEnabled())
logger.debug("Generating file name for " + distinctEntry + " ...");
fileNames.put(distinctEntry, cfStore.getTempSSTableFileName());
}
return fileNames;
}
private void addStreamContext(InetAddress host, PendingFile pendingFile, CompletedFileStatus streamStatus)
{
if (logger.isDebugEnabled())
logger.debug("Adding stream context " + pendingFile + " for " + host + " ...");
StreamInManager.addStreamContext(host, pendingFile, streamStatus);
}
}

View File

@ -1,76 +1,97 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
import java.io.*; *
* Licensed to the Apache Software Foundation (ASF) under one
import org.apache.cassandra.concurrent.StageManager; * or more contributor license agreements. See the NOTICE file
import org.apache.cassandra.io.ICompactSerializer; * distributed with this work for additional information
import org.apache.cassandra.net.Message; * regarding copyright ownership. The ASF licenses this file
import org.apache.cassandra.service.StorageService; * to you under the Apache License, Version 2.0 (the
import org.apache.cassandra.utils.FBUtilities; * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
/** *
* This class encapsulates the message that needs to be sent to nodes * http://www.apache.org/licenses/LICENSE-2.0
* that handoff data. The message contains information about ranges *
* that need to be transferred and the target node. * Unless required by applicable law or agreed to in writing,
*/ * software distributed under the License is distributed on an
class StreamRequestMessage * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
{ * KIND, either express or implied. See the License for the
private static ICompactSerializer<StreamRequestMessage> serializer_; * specific language governing permissions and limitations
static * under the License.
{ *
serializer_ = new StreamRequestMessageSerializer(); */
}
protected static ICompactSerializer<StreamRequestMessage> serializer() import java.io.*;
{
return serializer_; import org.apache.cassandra.concurrent.StageManager;
} import org.apache.cassandra.io.ICompactSerializer;
import org.apache.cassandra.net.Message;
protected static Message makeStreamRequestMessage(StreamRequestMessage streamRequestMessage) import org.apache.cassandra.service.StorageService;
{ import org.apache.cassandra.utils.FBUtilities;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos); /**
try * This class encapsulates the message that needs to be sent to nodes
{ * that handoff data. The message contains information about ranges
StreamRequestMessage.serializer().serialize(streamRequestMessage, dos); * that need to be transferred and the target node.
} */
catch (IOException e) class StreamRequestMessage
{ {
throw new IOError(e); private static ICompactSerializer<StreamRequestMessage> serializer_;
} static
return new Message(FBUtilities.getLocalAddress(), StageManager.STREAM_STAGE, StorageService.Verb.STREAM_REQUEST, bos.toByteArray() ); {
} serializer_ = new StreamRequestMessageSerializer();
}
protected StreamRequestMetadata[] streamRequestMetadata_ = new StreamRequestMetadata[0];
protected static ICompactSerializer<StreamRequestMessage> serializer()
// TODO only actually ever need one BM, not an array {
StreamRequestMessage(StreamRequestMetadata... streamRequestMetadata) return serializer_;
{ }
assert streamRequestMetadata != null;
streamRequestMetadata_ = streamRequestMetadata; protected static Message makeStreamRequestMessage(StreamRequestMessage streamRequestMessage)
} {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
private static class StreamRequestMessageSerializer implements ICompactSerializer<StreamRequestMessage> DataOutputStream dos = new DataOutputStream(bos);
{ try
public void serialize(StreamRequestMessage streamRequestMessage, DataOutputStream dos) throws IOException {
{ StreamRequestMessage.serializer().serialize(streamRequestMessage, dos);
StreamRequestMetadata[] streamRequestMetadata = streamRequestMessage.streamRequestMetadata_; }
dos.writeInt(streamRequestMetadata.length); catch (IOException e)
for (StreamRequestMetadata bsmd : streamRequestMetadata) {
{ throw new IOError(e);
StreamRequestMetadata.serializer().serialize(bsmd, dos); }
} return new Message(FBUtilities.getLocalAddress(), StageManager.STREAM_STAGE, StorageService.Verb.STREAM_REQUEST, bos.toByteArray() );
} }
public StreamRequestMessage deserialize(DataInputStream dis) throws IOException protected StreamRequestMetadata[] streamRequestMetadata_ = new StreamRequestMetadata[0];
{
int size = dis.readInt(); // TODO only actually ever need one BM, not an array
StreamRequestMetadata[] streamRequestMetadata = new StreamRequestMetadata[size]; StreamRequestMessage(StreamRequestMetadata... streamRequestMetadata)
for (int i = 0; i < size; ++i) {
{ assert streamRequestMetadata != null;
streamRequestMetadata[i] = StreamRequestMetadata.serializer().deserialize(dis); streamRequestMetadata_ = streamRequestMetadata;
} }
return new StreamRequestMessage(streamRequestMetadata);
} private static class StreamRequestMessageSerializer implements ICompactSerializer<StreamRequestMessage>
} {
} public void serialize(StreamRequestMessage streamRequestMessage, DataOutputStream dos) throws IOException
{
StreamRequestMetadata[] streamRequestMetadata = streamRequestMessage.streamRequestMetadata_;
dos.writeInt(streamRequestMetadata.length);
for (StreamRequestMetadata bsmd : streamRequestMetadata)
{
StreamRequestMetadata.serializer().serialize(bsmd, dos);
}
}
public StreamRequestMessage deserialize(DataInputStream dis) throws IOException
{
int size = dis.readInt();
StreamRequestMetadata[] streamRequestMetadata = new StreamRequestMetadata[size];
for (int i = 0; i < size; ++i)
{
streamRequestMetadata[i] = StreamRequestMetadata.serializer().deserialize(dis);
}
return new StreamRequestMessage(streamRequestMetadata);
}
}
}

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.streaming; package org.apache.cassandra.streaming;
/*
*
* 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.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.thrift; package org.apache.cassandra.thrift;
/*
*
* 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.List; import java.util.List;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.tools; package org.apache.cassandra.tools;
/*
*
* 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.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;

View File

@ -1,4 +1,25 @@
package org.apache.cassandra.utils; package org.apache.cassandra.utils;
/*
*
* 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 java.util.concurrent.atomic.AtomicLong;

View File

@ -1,73 +1,94 @@
package org.apache.cassandra.dht; package org.apache.cassandra.dht;
/*
import java.util.*; *
* Licensed to the Apache Software Foundation (ASF) under one
import junit.framework.TestCase; * or more contributor license agreements. See the NOTICE file
import org.apache.cassandra.utils.FBUtilities; * distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
public class BoundsTest extends TestCase * to you under the Apache License, Version 2.0 (the
{ * "License"); you may not use this file except in compliance
public void testRestrictTo() throws Exception * with the License. You may obtain a copy of the License at
{ *
IPartitioner p = new OrderPreservingPartitioner(); * http://www.apache.org/licenses/LICENSE-2.0
Token min = p.getMinimumToken(); *
Range wraps = new Range(new StringToken("m"), new StringToken("e")); * Unless required by applicable law or agreed to in writing,
Range normal = new Range(wraps.right, wraps.left); * software distributed under the License is distributed on an
Bounds all = new Bounds(min, min, p); * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Bounds almostAll = new Bounds(new StringToken("a"), min, p); * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
Set<AbstractBounds> S; * under the License.
Set<AbstractBounds> S2; *
*/
S = all.restrictTo(wraps);
assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(wraps)));
import java.util.*;
S = almostAll.restrictTo(wraps);
S2 = new HashSet<AbstractBounds>(Arrays.asList(new Bounds(new StringToken("a"), new StringToken("e"), p), import junit.framework.TestCase;
new Range(new StringToken("m"), min))); import org.apache.cassandra.utils.FBUtilities;
assert S.equals(S2);
public class BoundsTest extends TestCase
S = all.restrictTo(normal); {
assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(normal))); public void testRestrictTo() throws Exception
} {
IPartitioner p = new OrderPreservingPartitioner();
public void testNoIntersectionWrapped() Token min = p.getMinimumToken();
{ Range wraps = new Range(new StringToken("m"), new StringToken("e"));
IPartitioner p = new OrderPreservingPartitioner(); Range normal = new Range(wraps.right, wraps.left);
Range node = new Range(new StringToken("z"), new StringToken("a")); Bounds all = new Bounds(min, min, p);
Bounds bounds; Bounds almostAll = new Bounds(new StringToken("a"), min, p);
bounds = new Bounds(new StringToken("m"), new StringToken("n"), p); Set<AbstractBounds> S;
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet()); Set<AbstractBounds> S2;
bounds = new Bounds(new StringToken("b"), node.left, p); S = all.restrictTo(wraps);
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet()); assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(wraps)));
}
S = almostAll.restrictTo(wraps);
public void testSmallBoundsFullRange() S2 = new HashSet<AbstractBounds>(Arrays.asList(new Bounds(new StringToken("a"), new StringToken("e"), p),
{ new Range(new StringToken("m"), min)));
IPartitioner p = new OrderPreservingPartitioner(); assert S.equals(S2);
Range node;
Bounds bounds = new Bounds(new StringToken("b"), new StringToken("c"), p); S = all.restrictTo(normal);
assert S.equals(new HashSet<AbstractBounds>(Arrays.asList(normal)));
node = new Range(new StringToken("d"), new StringToken("d")); }
assert bounds.restrictTo(node).equals(new HashSet(Arrays.asList(bounds)));
} public void testNoIntersectionWrapped()
{
public void testNoIntersectionUnwrapped() IPartitioner p = new OrderPreservingPartitioner();
{ Range node = new Range(new StringToken("z"), new StringToken("a"));
IPartitioner p = new OrderPreservingPartitioner(); Bounds bounds;
Token min = p.getMinimumToken();
Range node = new Range(new StringToken("m"), new StringToken("n")); bounds = new Bounds(new StringToken("m"), new StringToken("n"), p);
Bounds bounds; assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
bounds = new Bounds(new StringToken("z"), min, p); bounds = new Bounds(new StringToken("b"), node.left, p);
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet()); assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
}
bounds = new Bounds(new StringToken("a"), node.left, p);
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet()); public void testSmallBoundsFullRange()
{
bounds = new Bounds(min, new StringToken("b"), p); IPartitioner p = new OrderPreservingPartitioner();
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet()); Range node;
} Bounds bounds = new Bounds(new StringToken("b"), new StringToken("c"), p);
}
node = new Range(new StringToken("d"), new StringToken("d"));
assert bounds.restrictTo(node).equals(new HashSet(Arrays.asList(bounds)));
}
public void testNoIntersectionUnwrapped()
{
IPartitioner p = new OrderPreservingPartitioner();
Token min = p.getMinimumToken();
Range node = new Range(new StringToken("m"), new StringToken("n"));
Bounds bounds;
bounds = new Bounds(new StringToken("z"), min, p);
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
bounds = new Bounds(new StringToken("a"), node.left, p);
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
bounds = new Bounds(min, new StringToken("b"), p);
assert bounds.restrictTo(node).equals(Collections.<AbstractBounds>emptySet());
}
}

View File

@ -1,131 +1,152 @@
package org.apache.cassandra.dht; package org.apache.cassandra.dht;
/*
import java.util.Arrays; *
import java.util.List; * Licensed to the Apache Software Foundation (ASF) under one
import java.util.Set; * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
import org.apache.commons.lang.StringUtils; * regarding copyright ownership. The ASF licenses this file
import org.junit.Test; * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
public class RangeIntersectionTest * with the License. You may obtain a copy of the License at
{ *
static void assertIntersection(Range one, Range two, Range ... ranges) * http://www.apache.org/licenses/LICENSE-2.0
{ *
Set<Range> correct = Range.rangeSet(ranges); * Unless required by applicable law or agreed to in writing,
Set<Range> result1 = one.intersectionWith(two); * software distributed under the License is distributed on an
assert result1.equals(correct) : String.format("%s != %s", * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
StringUtils.join(result1, ","), * KIND, either express or implied. See the License for the
StringUtils.join(correct, ",")); * specific language governing permissions and limitations
Set<Range> result2 = two.intersectionWith(one); * under the License.
assert result2.equals(correct) : String.format("%s != %s", *
StringUtils.join(result2, ","), */
StringUtils.join(correct, ","));
}
import java.util.Arrays;
private void assertNoIntersection(Range wraps1, Range nowrap3) import java.util.List;
{ import java.util.Set;
assertIntersection(wraps1, nowrap3);
} import org.apache.commons.lang.StringUtils;
import org.junit.Test;
@Test
public void testIntersectionWithAll() public class RangeIntersectionTest
{ {
Range all0 = new Range(new BigIntegerToken("0"), new BigIntegerToken("0")); static void assertIntersection(Range one, Range two, Range ... ranges)
Range all10 = new Range(new BigIntegerToken("10"), new BigIntegerToken("10")); {
Range all100 = new Range(new BigIntegerToken("100"), new BigIntegerToken("100")); Set<Range> correct = Range.rangeSet(ranges);
Range all1000 = new Range(new BigIntegerToken("1000"), new BigIntegerToken("1000")); Set<Range> result1 = one.intersectionWith(two);
Range wraps = new Range(new BigIntegerToken("100"), new BigIntegerToken("10")); assert result1.equals(correct) : String.format("%s != %s",
StringUtils.join(result1, ","),
assertIntersection(all0, wraps, wraps); StringUtils.join(correct, ","));
assertIntersection(all10, wraps, wraps); Set<Range> result2 = two.intersectionWith(one);
assertIntersection(all100, wraps, wraps); assert result2.equals(correct) : String.format("%s != %s",
assertIntersection(all1000, wraps, wraps); StringUtils.join(result2, ","),
} StringUtils.join(correct, ","));
}
@Test
public void testIntersectionContains() private void assertNoIntersection(Range wraps1, Range nowrap3)
{ {
Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10")); assertIntersection(wraps1, nowrap3);
Range wraps2 = new Range(new BigIntegerToken("90"), new BigIntegerToken("20")); }
Range wraps3 = new Range(new BigIntegerToken("90"), new BigIntegerToken("0"));
Range nowrap1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("110")); @Test
Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("10")); public void testIntersectionWithAll()
Range nowrap3 = new Range(new BigIntegerToken("0"), new BigIntegerToken("9")); {
Range all0 = new Range(new BigIntegerToken("0"), new BigIntegerToken("0"));
assertIntersection(wraps1, wraps2, wraps1); Range all10 = new Range(new BigIntegerToken("10"), new BigIntegerToken("10"));
assertIntersection(wraps3, wraps2, wraps3); Range all100 = new Range(new BigIntegerToken("100"), new BigIntegerToken("100"));
Range all1000 = new Range(new BigIntegerToken("1000"), new BigIntegerToken("1000"));
assertIntersection(wraps1, nowrap1, nowrap1); Range wraps = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
assertIntersection(wraps1, nowrap2, nowrap2);
assertIntersection(nowrap2, nowrap3, nowrap3); assertIntersection(all0, wraps, wraps);
assertIntersection(all10, wraps, wraps);
assertIntersection(wraps1, wraps1, wraps1); assertIntersection(all100, wraps, wraps);
assertIntersection(nowrap1, nowrap1, nowrap1); assertIntersection(all1000, wraps, wraps);
assertIntersection(nowrap2, nowrap2, nowrap2); }
assertIntersection(wraps3, wraps3, wraps3);
} @Test
public void testIntersectionContains()
@Test {
public void testNoIntersection() Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
{ Range wraps2 = new Range(new BigIntegerToken("90"), new BigIntegerToken("20"));
Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10")); Range wraps3 = new Range(new BigIntegerToken("90"), new BigIntegerToken("0"));
Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0")); Range nowrap1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("110"));
Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100")); Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("10"));
Range nowrap2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("200")); Range nowrap3 = new Range(new BigIntegerToken("0"), new BigIntegerToken("9"));
Range nowrap3 = new Range(new BigIntegerToken("10"), new BigIntegerToken("100"));
assertIntersection(wraps1, wraps2, wraps1);
assertNoIntersection(wraps1, nowrap3); assertIntersection(wraps3, wraps2, wraps3);
assertNoIntersection(wraps2, nowrap1);
assertNoIntersection(nowrap1, nowrap2); assertIntersection(wraps1, nowrap1, nowrap1);
} assertIntersection(wraps1, nowrap2, nowrap2);
assertIntersection(nowrap2, nowrap3, nowrap3);
@Test
public void testIntersectionOneWraps() assertIntersection(wraps1, wraps1, wraps1);
{ assertIntersection(nowrap1, nowrap1, nowrap1);
Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10")); assertIntersection(nowrap2, nowrap2, nowrap2);
Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0")); assertIntersection(wraps3, wraps3, wraps3);
Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("200")); }
Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
@Test
assertIntersection(wraps1, public void testNoIntersection()
nowrap1, {
new Range(new BigIntegerToken("0"), new BigIntegerToken("10")), Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
new Range(new BigIntegerToken("100"), new BigIntegerToken("200"))); Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
assertIntersection(wraps2, Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
nowrap1, Range nowrap2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("200"));
new Range(new BigIntegerToken("100"), new BigIntegerToken("200"))); Range nowrap3 = new Range(new BigIntegerToken("10"), new BigIntegerToken("100"));
assertIntersection(wraps1,
nowrap2, assertNoIntersection(wraps1, nowrap3);
new Range(new BigIntegerToken("0"), new BigIntegerToken("10"))); assertNoIntersection(wraps2, nowrap1);
} assertNoIntersection(nowrap1, nowrap2);
}
@Test
public void testIntersectionTwoWraps() @Test
{ public void testIntersectionOneWraps()
Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("20")); {
Range wraps2 = new Range(new BigIntegerToken("120"), new BigIntegerToken("90")); Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("10"));
Range wraps3 = new Range(new BigIntegerToken("120"), new BigIntegerToken("110")); Range wraps2 = new Range(new BigIntegerToken("100"), new BigIntegerToken("0"));
Range wraps4 = new Range(new BigIntegerToken("10"), new BigIntegerToken("0")); Range nowrap1 = new Range(new BigIntegerToken("0"), new BigIntegerToken("200"));
Range wraps5 = new Range(new BigIntegerToken("10"), new BigIntegerToken("1")); Range nowrap2 = new Range(new BigIntegerToken("0"), new BigIntegerToken("100"));
Range wraps6 = new Range(new BigIntegerToken("30"), new BigIntegerToken("10"));
assertIntersection(wraps1,
assertIntersection(wraps1, nowrap1,
wraps2, new Range(new BigIntegerToken("0"), new BigIntegerToken("10")),
new Range(new BigIntegerToken("120"), new BigIntegerToken("20"))); new Range(new BigIntegerToken("100"), new BigIntegerToken("200")));
assertIntersection(wraps1, assertIntersection(wraps2,
wraps3, nowrap1,
new Range(new BigIntegerToken("120"), new BigIntegerToken("20")), new Range(new BigIntegerToken("100"), new BigIntegerToken("200")));
new Range(new BigIntegerToken("100"), new BigIntegerToken("110"))); assertIntersection(wraps1,
assertIntersection(wraps1, nowrap2,
wraps4, new Range(new BigIntegerToken("0"), new BigIntegerToken("10")));
new Range(new BigIntegerToken("10"), new BigIntegerToken("20")), }
new Range(new BigIntegerToken("100"), new BigIntegerToken("0")));
assertIntersection(wraps1, @Test
wraps5, public void testIntersectionTwoWraps()
new Range(new BigIntegerToken("10"), new BigIntegerToken("20")), {
new Range(new BigIntegerToken("100"), new BigIntegerToken("1"))); Range wraps1 = new Range(new BigIntegerToken("100"), new BigIntegerToken("20"));
assertIntersection(wraps1, Range wraps2 = new Range(new BigIntegerToken("120"), new BigIntegerToken("90"));
wraps6, Range wraps3 = new Range(new BigIntegerToken("120"), new BigIntegerToken("110"));
new Range(new BigIntegerToken("100"), new BigIntegerToken("10"))); Range wraps4 = new Range(new BigIntegerToken("10"), new BigIntegerToken("0"));
} Range wraps5 = new Range(new BigIntegerToken("10"), new BigIntegerToken("1"));
} Range wraps6 = new Range(new BigIntegerToken("30"), new BigIntegerToken("10"));
assertIntersection(wraps1,
wraps2,
new Range(new BigIntegerToken("120"), new BigIntegerToken("20")));
assertIntersection(wraps1,
wraps3,
new Range(new BigIntegerToken("120"), new BigIntegerToken("20")),
new Range(new BigIntegerToken("100"), new BigIntegerToken("110")));
assertIntersection(wraps1,
wraps4,
new Range(new BigIntegerToken("10"), new BigIntegerToken("20")),
new Range(new BigIntegerToken("100"), new BigIntegerToken("0")));
assertIntersection(wraps1,
wraps5,
new Range(new BigIntegerToken("10"), new BigIntegerToken("20")),
new Range(new BigIntegerToken("100"), new BigIntegerToken("1")));
assertIntersection(wraps1,
wraps6,
new Range(new BigIntegerToken("100"), new BigIntegerToken("10")));
}
}