diff --git a/.build/cassandra-deps-template.xml b/.build/cassandra-deps-template.xml
index 44f9f35ab3..b1db0fd0b7 100644
--- a/.build/cassandra-deps-template.xml
+++ b/.build/cassandra-deps-template.xml
@@ -161,14 +161,6 @@
ch.qos.logbacklogback-classic
-
- org.apache.hadoop
- hadoop-core
-
-
- org.apache.hadoop
- hadoop-minicluster
- com.datastax.cassandracassandra-driver-core
diff --git a/.build/parent-pom-template.xml b/.build/parent-pom-template.xml
index 4edd92e65c..6809fcd74a 100644
--- a/.build/parent-pom-template.xml
+++ b/.build/parent-pom-template.xml
@@ -503,66 +503,6 @@
8.40test
-
- org.apache.hadoop
- hadoop-core
- 1.0.3
- provided
-
-
- servlet-api
- org.mortbay.jetty
-
-
- commons-logging
- commons-logging
-
-
- commons-lang
- commons-lang
-
-
- core
- org.eclipse.jdt
-
-
- ant
- ant
-
-
- junit
- junit
-
-
- jackson-mapper-asl
- org.codehaus.jackson
-
-
- slf4j-api
- org.slf4j
-
-
-
-
- org.apache.hadoop
- hadoop-minicluster
- 1.0.3
- provided
-
-
- asm
- asm
-
-
- jackson-mapper-asl
- org.codehaus.jackson
-
-
- slf4j-api
- org.slf4j
-
-
- net.java.dev.jnajna
diff --git a/CHANGES.txt b/CHANGES.txt
index cc277dbcc6..149c9b0992 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.0
+ * Remove org.apache.cassandra.hadoop code (CASSANDRA-18323)
* Remove deprecated CQL functions dateOf and unixTimestampOf (CASSANDRA-18328)
* Remove DateTieredCompactionStrategy (CASSANDRA-18043)
* Add system_views.max_sstable_size and system_views.max_sstable_duration tables (CASSANDRA-18333)
diff --git a/NEWS.txt b/NEWS.txt
index e414d66500..c1fe5427f2 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -150,6 +150,8 @@ Upgrading
to TimeWindowCompactionStrategy before upgrading to this version.
- The deprecated functions `dateOf` and `unixTimestampOf` have been removed. They were deprecated and replaced by
`toTimestamp` and `toUnixTimestamp` in Cassandra 2.2.
+ - Hadoop integration is no longer available (CASSANDRA-18323). If you want to process Cassandra data by big data frameworks,
+ please upgrade your infrastructure to use Cassandra Spark connector.
Deprecation
-----------
diff --git a/src/java/org/apache/cassandra/hadoop/ColumnFamilySplit.java b/src/java/org/apache/cassandra/hadoop/ColumnFamilySplit.java
deleted file mode 100644
index 36256852f2..0000000000
--- a/src/java/org/apache/cassandra/hadoop/ColumnFamilySplit.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.hadoop;
-
-import org.apache.hadoop.io.Writable;
-import org.apache.hadoop.mapreduce.InputSplit;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.EOFException;
-import java.io.IOException;
-import java.util.Arrays;
-
-public class ColumnFamilySplit extends InputSplit implements Writable, org.apache.hadoop.mapred.InputSplit
-{
- private String startToken;
- private String endToken;
- private long length;
- private String[] dataNodes;
-
- @Deprecated
- public ColumnFamilySplit(String startToken, String endToken, String[] dataNodes)
- {
- this(startToken, endToken, Long.MAX_VALUE, dataNodes);
- }
-
- public ColumnFamilySplit(String startToken, String endToken, long length, String[] dataNodes)
- {
- assert startToken != null;
- assert endToken != null;
- this.startToken = startToken;
- this.endToken = endToken;
- this.length = length;
- this.dataNodes = dataNodes;
- }
-
- public String getStartToken()
- {
- return startToken;
- }
-
- public String getEndToken()
- {
- return endToken;
- }
-
- // getLength and getLocations satisfy the InputSplit abstraction
-
- public long getLength()
- {
- return length;
- }
-
- public String[] getLocations()
- {
- return dataNodes;
- }
-
- // This should only be used by KeyspaceSplit.read();
- protected ColumnFamilySplit() {}
-
- // These three methods are for serializing and deserializing
- // KeyspaceSplits as needed by the Writable interface.
- public void write(DataOutput out) throws IOException
- {
- out.writeUTF(startToken);
- out.writeUTF(endToken);
- out.writeInt(dataNodes.length);
- for (String endpoint : dataNodes)
- {
- out.writeUTF(endpoint);
- }
- out.writeLong(length);
- }
-
- public void readFields(DataInput in) throws IOException
- {
- startToken = in.readUTF();
- endToken = in.readUTF();
- int numOfEndpoints = in.readInt();
- dataNodes = new String[numOfEndpoints];
- for(int i = 0; i < numOfEndpoints; i++)
- {
- dataNodes[i] = in.readUTF();
- }
- try
- {
- length = in.readLong();
- }
- catch (EOFException e)
- {
- //We must be deserializing in a mixed-version cluster.
- }
- }
-
- @Override
- public String toString()
- {
- return "ColumnFamilySplit(" +
- "(" + startToken
- + ", '" + endToken + ']'
- + " @" + (dataNodes == null ? null : Arrays.asList(dataNodes)) + ')';
- }
-
- public static ColumnFamilySplit read(DataInput in) throws IOException
- {
- ColumnFamilySplit w = new ColumnFamilySplit();
- w.readFields(in);
- return w;
- }
-}
diff --git a/src/java/org/apache/cassandra/hadoop/ConfigHelper.java b/src/java/org/apache/cassandra/hadoop/ConfigHelper.java
deleted file mode 100644
index cc539b1a70..0000000000
--- a/src/java/org/apache/cassandra/hadoop/ConfigHelper.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.cassandra.hadoop;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.cassandra.dht.IPartitioner;
-import org.apache.cassandra.schema.CompressionParams;
-import org.apache.cassandra.utils.FBUtilities;
-import org.apache.cassandra.utils.Pair;
-import org.apache.hadoop.conf.Configuration;
-
-public class ConfigHelper
-{
- private static final String INPUT_PARTITIONER_CONFIG = "cassandra.input.partitioner.class";
- private static final String OUTPUT_PARTITIONER_CONFIG = "cassandra.output.partitioner.class";
- private static final String INPUT_KEYSPACE_CONFIG = "cassandra.input.keyspace";
- private static final String OUTPUT_KEYSPACE_CONFIG = "cassandra.output.keyspace";
- private static final String INPUT_KEYSPACE_USERNAME_CONFIG = "cassandra.input.keyspace.username";
- private static final String INPUT_KEYSPACE_PASSWD_CONFIG = "cassandra.input.keyspace.passwd";
- private static final String OUTPUT_KEYSPACE_USERNAME_CONFIG = "cassandra.output.keyspace.username";
- private static final String OUTPUT_KEYSPACE_PASSWD_CONFIG = "cassandra.output.keyspace.passwd";
- private static final String INPUT_COLUMNFAMILY_CONFIG = "cassandra.input.columnfamily";
- private static final String OUTPUT_COLUMNFAMILY_CONFIG = "mapreduce.output.basename"; //this must == OutputFormat.BASE_OUTPUT_NAME
- private static final String INPUT_PREDICATE_CONFIG = "cassandra.input.predicate";
- private static final String INPUT_KEYRANGE_CONFIG = "cassandra.input.keyRange";
- private static final String INPUT_SPLIT_SIZE_CONFIG = "cassandra.input.split.size";
- private static final String INPUT_SPLIT_SIZE_IN_MIB_CONFIG = "cassandra.input.split.size_mb";
- private static final String INPUT_WIDEROWS_CONFIG = "cassandra.input.widerows";
- private static final int DEFAULT_SPLIT_SIZE = 64 * 1024;
- private static final String RANGE_BATCH_SIZE_CONFIG = "cassandra.range.batch.size";
- private static final int DEFAULT_RANGE_BATCH_SIZE = 4096;
- private static final String INPUT_INITIAL_ADDRESS = "cassandra.input.address";
- private static final String OUTPUT_INITIAL_ADDRESS = "cassandra.output.address";
- private static final String OUTPUT_INITIAL_PORT = "cassandra.output.port";
- private static final String READ_CONSISTENCY_LEVEL = "cassandra.consistencylevel.read";
- private static final String WRITE_CONSISTENCY_LEVEL = "cassandra.consistencylevel.write";
- private static final String OUTPUT_COMPRESSION_CLASS = "cassandra.output.compression.class";
- private static final String OUTPUT_COMPRESSION_CHUNK_LENGTH = "cassandra.output.compression.length";
- private static final String OUTPUT_LOCAL_DC_ONLY = "cassandra.output.local.dc.only";
- private static final String DEFAULT_CASSANDRA_NATIVE_PORT = "7000";
-
- private static final Logger logger = LoggerFactory.getLogger(ConfigHelper.class);
-
- /**
- * Set the keyspace and column family for the input of this job.
- *
- * @param conf Job configuration you are about to run
- * @param keyspace
- * @param columnFamily
- * @param widerows
- */
- public static void setInputColumnFamily(Configuration conf, String keyspace, String columnFamily, boolean widerows)
- {
- if (keyspace == null)
- throw new UnsupportedOperationException("keyspace may not be null");
-
- if (columnFamily == null)
- throw new UnsupportedOperationException("table may not be null");
-
- conf.set(INPUT_KEYSPACE_CONFIG, keyspace);
- conf.set(INPUT_COLUMNFAMILY_CONFIG, columnFamily);
- conf.set(INPUT_WIDEROWS_CONFIG, String.valueOf(widerows));
- }
-
- /**
- * Set the keyspace and column family for the input of this job.
- *
- * @param conf Job configuration you are about to run
- * @param keyspace
- * @param columnFamily
- */
- public static void setInputColumnFamily(Configuration conf, String keyspace, String columnFamily)
- {
- setInputColumnFamily(conf, keyspace, columnFamily, false);
- }
-
- /**
- * Set the keyspace for the output of this job.
- *
- * @param conf Job configuration you are about to run
- * @param keyspace
- */
- public static void setOutputKeyspace(Configuration conf, String keyspace)
- {
- if (keyspace == null)
- throw new UnsupportedOperationException("keyspace may not be null");
-
- conf.set(OUTPUT_KEYSPACE_CONFIG, keyspace);
- }
-
- /**
- * Set the column family for the output of this job.
- *
- * @param conf Job configuration you are about to run
- * @param columnFamily
- */
- public static void setOutputColumnFamily(Configuration conf, String columnFamily)
- {
- conf.set(OUTPUT_COLUMNFAMILY_CONFIG, columnFamily);
- }
-
- /**
- * Set the column family for the output of this job.
- *
- * @param conf Job configuration you are about to run
- * @param keyspace
- * @param columnFamily
- */
- public static void setOutputColumnFamily(Configuration conf, String keyspace, String columnFamily)
- {
- setOutputKeyspace(conf, keyspace);
- setOutputColumnFamily(conf, columnFamily);
- }
-
- /**
- * The number of rows to request with each get range slices request.
- * Too big and you can either get timeouts when it takes Cassandra too
- * long to fetch all the data. Too small and the performance
- * will be eaten up by the overhead of each request.
- *
- * @param conf Job configuration you are about to run
- * @param batchsize Number of rows to request each time
- */
- public static void setRangeBatchSize(Configuration conf, int batchsize)
- {
- conf.setInt(RANGE_BATCH_SIZE_CONFIG, batchsize);
- }
-
- /**
- * The number of rows to request with each get range slices request.
- * Too big and you can either get timeouts when it takes Cassandra too
- * long to fetch all the data. Too small and the performance
- * will be eaten up by the overhead of each request.
- *
- * @param conf Job configuration you are about to run
- * @return Number of rows to request each time
- */
- public static int getRangeBatchSize(Configuration conf)
- {
- return conf.getInt(RANGE_BATCH_SIZE_CONFIG, DEFAULT_RANGE_BATCH_SIZE);
- }
-
- /**
- * Set the size of the input split.
- * This affects the number of maps created, if the number is too small
- * the overhead of each map will take up the bulk of the job time.
- *
- * @param conf Job configuration you are about to run
- * @param splitsize Number of partitions in the input split
- */
- public static void setInputSplitSize(Configuration conf, int splitsize)
- {
- conf.setInt(INPUT_SPLIT_SIZE_CONFIG, splitsize);
- }
-
- public static int getInputSplitSize(Configuration conf)
- {
- return conf.getInt(INPUT_SPLIT_SIZE_CONFIG, DEFAULT_SPLIT_SIZE);
- }
-
- /**
- * Set the size of the input split. setInputSplitSize value is used if this is not set.
- * This affects the number of maps created, if the number is too small
- * the overhead of each map will take up the bulk of the job time.
- *
- * @param conf Job configuration you are about to run
- * @param splitSizeMb Input split size in MiB
- */
- public static void setInputSplitSizeInMb(Configuration conf, int splitSizeMb)
- {
- conf.setInt(INPUT_SPLIT_SIZE_IN_MIB_CONFIG, splitSizeMb);
- }
-
- /**
- * cassandra.input.split.size will be used if the value is undefined or negative.
- * @param conf Job configuration you are about to run
- * @return split size in MiB or -1 if it is undefined.
- */
- public static int getInputSplitSizeInMb(Configuration conf)
- {
- return conf.getInt(INPUT_SPLIT_SIZE_IN_MIB_CONFIG, -1);
- }
-
- /**
- * Set the KeyRange to limit the rows.
- * @param conf Job configuration you are about to run
- */
- public static void setInputRange(Configuration conf, String startToken, String endToken)
- {
- conf.set(INPUT_KEYRANGE_CONFIG, startToken + "," + endToken);
- }
-
- /**
- * The start and end token of the input key range as a pair.
- *
- * may be null if unset.
- */
- public static Pair getInputKeyRange(Configuration conf)
- {
- String str = conf.get(INPUT_KEYRANGE_CONFIG);
- if (str == null)
- return null;
-
- String[] parts = str.split(",");
- assert parts.length == 2;
- return Pair.create(parts[0], parts[1]);
- }
-
- public static String getInputKeyspace(Configuration conf)
- {
- return conf.get(INPUT_KEYSPACE_CONFIG);
- }
-
- public static String getOutputKeyspace(Configuration conf)
- {
- return conf.get(OUTPUT_KEYSPACE_CONFIG);
- }
-
- public static void setInputKeyspaceUserNameAndPassword(Configuration conf, String username, String password)
- {
- setInputKeyspaceUserName(conf, username);
- setInputKeyspacePassword(conf, password);
- }
-
- public static void setInputKeyspaceUserName(Configuration conf, String username)
- {
- conf.set(INPUT_KEYSPACE_USERNAME_CONFIG, username);
- }
-
- public static String getInputKeyspaceUserName(Configuration conf)
- {
- return conf.get(INPUT_KEYSPACE_USERNAME_CONFIG);
- }
-
- public static void setInputKeyspacePassword(Configuration conf, String password)
- {
- conf.set(INPUT_KEYSPACE_PASSWD_CONFIG, password);
- }
-
- public static String getInputKeyspacePassword(Configuration conf)
- {
- return conf.get(INPUT_KEYSPACE_PASSWD_CONFIG);
- }
-
- public static void setOutputKeyspaceUserNameAndPassword(Configuration conf, String username, String password)
- {
- setOutputKeyspaceUserName(conf, username);
- setOutputKeyspacePassword(conf, password);
- }
-
- public static void setOutputKeyspaceUserName(Configuration conf, String username)
- {
- conf.set(OUTPUT_KEYSPACE_USERNAME_CONFIG, username);
- }
-
- public static String getOutputKeyspaceUserName(Configuration conf)
- {
- return conf.get(OUTPUT_KEYSPACE_USERNAME_CONFIG);
- }
-
- public static void setOutputKeyspacePassword(Configuration conf, String password)
- {
- conf.set(OUTPUT_KEYSPACE_PASSWD_CONFIG, password);
- }
-
- public static String getOutputKeyspacePassword(Configuration conf)
- {
- return conf.get(OUTPUT_KEYSPACE_PASSWD_CONFIG);
- }
-
- public static String getInputColumnFamily(Configuration conf)
- {
- return conf.get(INPUT_COLUMNFAMILY_CONFIG);
- }
-
- public static String getOutputColumnFamily(Configuration conf)
- {
- if (conf.get(OUTPUT_COLUMNFAMILY_CONFIG) != null)
- return conf.get(OUTPUT_COLUMNFAMILY_CONFIG);
- else
- throw new UnsupportedOperationException("You must set the output column family using either setOutputColumnFamily or by adding a named output with MultipleOutputs");
- }
-
- public static boolean getInputIsWide(Configuration conf)
- {
- return Boolean.parseBoolean(conf.get(INPUT_WIDEROWS_CONFIG));
- }
-
- public static String getReadConsistencyLevel(Configuration conf)
- {
- return conf.get(READ_CONSISTENCY_LEVEL, "LOCAL_ONE");
- }
-
- public static void setReadConsistencyLevel(Configuration conf, String consistencyLevel)
- {
- conf.set(READ_CONSISTENCY_LEVEL, consistencyLevel);
- }
-
- public static String getWriteConsistencyLevel(Configuration conf)
- {
- return conf.get(WRITE_CONSISTENCY_LEVEL, "LOCAL_ONE");
- }
-
- public static void setWriteConsistencyLevel(Configuration conf, String consistencyLevel)
- {
- conf.set(WRITE_CONSISTENCY_LEVEL, consistencyLevel);
- }
-
- public static String getInputInitialAddress(Configuration conf)
- {
- return conf.get(INPUT_INITIAL_ADDRESS);
- }
-
- public static void setInputInitialAddress(Configuration conf, String address)
- {
- conf.set(INPUT_INITIAL_ADDRESS, address);
- }
- public static void setInputPartitioner(Configuration conf, String classname)
- {
- conf.set(INPUT_PARTITIONER_CONFIG, classname);
- }
-
- public static IPartitioner getInputPartitioner(Configuration conf)
- {
- return FBUtilities.newPartitioner(conf.get(INPUT_PARTITIONER_CONFIG));
- }
-
- public static String getOutputInitialAddress(Configuration conf)
- {
- return conf.get(OUTPUT_INITIAL_ADDRESS);
- }
-
- public static void setOutputInitialPort(Configuration conf, Integer port)
- {
- conf.set(OUTPUT_INITIAL_PORT, port.toString());
- }
-
- public static Integer getOutputInitialPort(Configuration conf)
- {
- return Integer.valueOf(conf.get(OUTPUT_INITIAL_PORT, DEFAULT_CASSANDRA_NATIVE_PORT));
- }
-
- public static void setOutputInitialAddress(Configuration conf, String address)
- {
- conf.set(OUTPUT_INITIAL_ADDRESS, address);
- }
-
- public static void setOutputPartitioner(Configuration conf, String classname)
- {
- conf.set(OUTPUT_PARTITIONER_CONFIG, classname);
- }
-
- public static IPartitioner getOutputPartitioner(Configuration conf)
- {
- return FBUtilities.newPartitioner(conf.get(OUTPUT_PARTITIONER_CONFIG));
- }
-
- public static String getOutputCompressionClass(Configuration conf)
- {
- return conf.get(OUTPUT_COMPRESSION_CLASS);
- }
-
- public static String getOutputCompressionChunkLength(Configuration conf)
- {
- return conf.get(OUTPUT_COMPRESSION_CHUNK_LENGTH, String.valueOf(CompressionParams.DEFAULT_CHUNK_LENGTH));
- }
-
- public static void setOutputCompressionClass(Configuration conf, String classname)
- {
- conf.set(OUTPUT_COMPRESSION_CLASS, classname);
- }
-
- public static void setOutputCompressionChunkLength(Configuration conf, String length)
- {
- conf.set(OUTPUT_COMPRESSION_CHUNK_LENGTH, length);
- }
-
- public static boolean getOutputLocalDCOnly(Configuration conf)
- {
- return Boolean.parseBoolean(conf.get(OUTPUT_LOCAL_DC_ONLY, "false"));
- }
-
- public static void setOutputLocalDCOnly(Configuration conf, boolean localDCOnly)
- {
- conf.set(OUTPUT_LOCAL_DC_ONLY, Boolean.toString(localDCOnly));
- }
-}
diff --git a/src/java/org/apache/cassandra/hadoop/HadoopCompat.java b/src/java/org/apache/cassandra/hadoop/HadoopCompat.java
deleted file mode 100644
index 479f948e60..0000000000
--- a/src/java/org/apache/cassandra/hadoop/HadoopCompat.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.hadoop;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.mapreduce.Counter;
-import org.apache.hadoop.mapreduce.InputSplit;
-import org.apache.hadoop.mapreduce.JobContext;
-import org.apache.hadoop.mapreduce.JobID;
-import org.apache.hadoop.mapreduce.MapContext;
-import org.apache.hadoop.mapreduce.OutputCommitter;
-import org.apache.hadoop.mapreduce.RecordReader;
-import org.apache.hadoop.mapreduce.RecordWriter;
-import org.apache.hadoop.mapreduce.StatusReporter;
-import org.apache.hadoop.mapreduce.TaskAttemptContext;
-import org.apache.hadoop.mapreduce.TaskAttemptID;
-import org.apache.hadoop.mapreduce.TaskInputOutputContext;
-
-/*
- * This is based on ContextFactory.java from hadoop-2.0.x sources.
- */
-
-/**
- * Utility methods to allow applications to deal with inconsistencies between
- * MapReduce Context Objects API between Hadoop 1.x and 2.x.
- */
-public class HadoopCompat
-{
-
- private static final boolean useV21;
-
- private static final Constructor> JOB_CONTEXT_CONSTRUCTOR;
- private static final Constructor> TASK_CONTEXT_CONSTRUCTOR;
- private static final Constructor> MAP_CONTEXT_CONSTRUCTOR;
- private static final Constructor> GENERIC_COUNTER_CONSTRUCTOR;
-
- private static final Field READER_FIELD;
- private static final Field WRITER_FIELD;
-
- private static final Method GET_CONFIGURATION_METHOD;
- private static final Method SET_STATUS_METHOD;
- private static final Method GET_COUNTER_METHOD;
- private static final Method INCREMENT_COUNTER_METHOD;
- private static final Method GET_TASK_ATTEMPT_ID;
- private static final Method PROGRESS_METHOD;
-
- static
- {
- boolean v21 = true;
- final String PACKAGE = "org.apache.hadoop.mapreduce";
- try
- {
- Class.forName(PACKAGE + ".task.JobContextImpl");
- } catch (ClassNotFoundException cnfe)
- {
- v21 = false;
- }
- useV21 = v21;
- Class> jobContextCls;
- Class> taskContextCls;
- Class> taskIOContextCls;
- Class> mapContextCls;
- Class> genericCounterCls;
- try
- {
- if (v21)
- {
- jobContextCls =
- Class.forName(PACKAGE+".task.JobContextImpl");
- taskContextCls =
- Class.forName(PACKAGE+".task.TaskAttemptContextImpl");
- taskIOContextCls =
- Class.forName(PACKAGE+".task.TaskInputOutputContextImpl");
- mapContextCls = Class.forName(PACKAGE + ".task.MapContextImpl");
- genericCounterCls = Class.forName(PACKAGE+".counters.GenericCounter");
- }
- else
- {
- jobContextCls =
- Class.forName(PACKAGE+".JobContext");
- taskContextCls =
- Class.forName(PACKAGE+".TaskAttemptContext");
- taskIOContextCls =
- Class.forName(PACKAGE+".TaskInputOutputContext");
- mapContextCls = Class.forName(PACKAGE + ".MapContext");
- genericCounterCls =
- Class.forName("org.apache.hadoop.mapred.Counters$Counter");
-
- }
- } catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException("Can't find class", e);
- }
- try
- {
- JOB_CONTEXT_CONSTRUCTOR =
- jobContextCls.getConstructor(Configuration.class, JobID.class);
- JOB_CONTEXT_CONSTRUCTOR.setAccessible(true);
- TASK_CONTEXT_CONSTRUCTOR =
- taskContextCls.getConstructor(Configuration.class,
- TaskAttemptID.class);
- TASK_CONTEXT_CONSTRUCTOR.setAccessible(true);
- GENERIC_COUNTER_CONSTRUCTOR =
- genericCounterCls.getDeclaredConstructor(String.class,
- String.class,
- Long.TYPE);
- GENERIC_COUNTER_CONSTRUCTOR.setAccessible(true);
-
- if (useV21)
- {
- MAP_CONTEXT_CONSTRUCTOR =
- mapContextCls.getDeclaredConstructor(Configuration.class,
- TaskAttemptID.class,
- RecordReader.class,
- RecordWriter.class,
- OutputCommitter.class,
- StatusReporter.class,
- InputSplit.class);
- Method get_counter;
- try
- {
- get_counter = Class.forName(PACKAGE + ".TaskAttemptContext").getMethod("getCounter", String.class,
- String.class);
- }
- catch (Exception e)
- {
- get_counter = Class.forName(PACKAGE + ".TaskInputOutputContext").getMethod("getCounter",
- String.class, String.class);
- }
- GET_COUNTER_METHOD = get_counter;
- }
- else
- {
- MAP_CONTEXT_CONSTRUCTOR =
- mapContextCls.getConstructor(Configuration.class,
- TaskAttemptID.class,
- RecordReader.class,
- RecordWriter.class,
- OutputCommitter.class,
- StatusReporter.class,
- InputSplit.class);
- GET_COUNTER_METHOD = Class.forName(PACKAGE+".TaskInputOutputContext")
- .getMethod("getCounter", String.class, String.class);
- }
- MAP_CONTEXT_CONSTRUCTOR.setAccessible(true);
- READER_FIELD = mapContextCls.getDeclaredField("reader");
- READER_FIELD.setAccessible(true);
- WRITER_FIELD = taskIOContextCls.getDeclaredField("output");
- WRITER_FIELD.setAccessible(true);
- GET_CONFIGURATION_METHOD = Class.forName(PACKAGE+".JobContext")
- .getMethod("getConfiguration");
- SET_STATUS_METHOD = Class.forName(PACKAGE+".TaskAttemptContext")
- .getMethod("setStatus", String.class);
- GET_TASK_ATTEMPT_ID = Class.forName(PACKAGE+".TaskAttemptContext")
- .getMethod("getTaskAttemptID");
- INCREMENT_COUNTER_METHOD = Class.forName(PACKAGE+".Counter")
- .getMethod("increment", Long.TYPE);
- PROGRESS_METHOD = Class.forName(PACKAGE+".TaskAttemptContext")
- .getMethod("progress");
-
- }
- catch (SecurityException e)
- {
- throw new IllegalArgumentException("Can't run constructor ", e);
- }
- catch (NoSuchMethodException e)
- {
- throw new IllegalArgumentException("Can't find constructor ", e);
- }
- catch (NoSuchFieldException e)
- {
- throw new IllegalArgumentException("Can't find field ", e);
- }
- catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException("Can't find class", e);
- }
- }
-
- /**
- * True if runtime Hadoop version is 2.x, false otherwise.
- */
- public static boolean isVersion2x()
- {
- return useV21;
- }
-
- private static Object newInstance(Constructor> constructor, Object...args)
- {
- try
- {
- return constructor.newInstance(args);
- }
- catch (InstantiationException e)
- {
- throw new IllegalArgumentException("Can't instantiate " + constructor, e);
- }
- catch (IllegalAccessException e)
- {
- throw new IllegalArgumentException("Can't instantiate " + constructor, e);
- }
- catch (InvocationTargetException e)
- {
- throw new IllegalArgumentException("Can't instantiate " + constructor, e);
- }
- }
-
- /**
- * Creates JobContext from a JobConf and jobId using the correct constructor
- * for based on Hadoop version. jobId could be null.
- */
- public static JobContext newJobContext(Configuration conf, JobID jobId) {
- return (JobContext) newInstance(JOB_CONTEXT_CONSTRUCTOR, conf, jobId);
- }
-
- /**
- * Creates TaskAttempContext from a JobConf and jobId using the correct
- * constructor for based on Hadoop version.
- */
- public static TaskAttemptContext newTaskAttemptContext(
- Configuration conf, TaskAttemptID taskAttemptId) {
- return (TaskAttemptContext)
- newInstance(TASK_CONTEXT_CONSTRUCTOR, conf, taskAttemptId);
- }
-
- /**
- * Instantiates MapContext under Hadoop 1 and MapContextImpl under Hadoop 2.
- */
- public static MapContext newMapContext(Configuration conf,
- TaskAttemptID taskAttemptID,
- RecordReader recordReader,
- RecordWriter recordWriter,
- OutputCommitter outputCommitter,
- StatusReporter statusReporter,
- InputSplit inputSplit) {
- return (MapContext) newInstance(MAP_CONTEXT_CONSTRUCTOR,
- conf, taskAttemptID, recordReader, recordWriter, outputCommitter,
- statusReporter, inputSplit);
- }
-
- /**
- * @return with Hadoop 2 : new GenericCounter(args),
- * with Hadoop 1 : new Counter(args)
- */
- public static Counter newGenericCounter(String name, String displayName, long value)
- {
- try
- {
- return (Counter)
- GENERIC_COUNTER_CONSTRUCTOR.newInstance(name, displayName, value);
- }
- catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
- {
- throw new IllegalArgumentException("Can't instantiate Counter", e);
- }
- }
-
- /**
- * Invokes a method and rethrows any exception as runtime excetpions.
- */
- private static Object invoke(Method method, Object obj, Object... args)
- {
- try
- {
- return method.invoke(obj, args);
- }
- catch (IllegalAccessException | InvocationTargetException e)
- {
- throw new IllegalArgumentException("Can't invoke method " + method.getName(), e);
- }
- }
-
- /**
- * Invoke getConfiguration() on JobContext. Works with both
- * Hadoop 1 and 2.
- */
- public static Configuration getConfiguration(JobContext context)
- {
- return (Configuration) invoke(GET_CONFIGURATION_METHOD, context);
- }
-
- /**
- * Invoke setStatus() on TaskAttemptContext. Works with both
- * Hadoop 1 and 2.
- */
- public static void setStatus(TaskAttemptContext context, String status)
- {
- invoke(SET_STATUS_METHOD, context, status);
- }
-
- /**
- * returns TaskAttemptContext.getTaskAttemptID(). Works with both
- * Hadoop 1 and 2.
- */
- public static TaskAttemptID getTaskAttemptID(TaskAttemptContext taskContext)
- {
- return (TaskAttemptID) invoke(GET_TASK_ATTEMPT_ID, taskContext);
- }
-
- /**
- * Invoke getCounter() on TaskInputOutputContext. Works with both
- * Hadoop 1 and 2.
- */
- public static Counter getCounter(TaskInputOutputContext context,
- String groupName, String counterName)
- {
- return (Counter) invoke(GET_COUNTER_METHOD, context, groupName, counterName);
- }
-
- /**
- * Invoke TaskAttemptContext.progress(). Works with both
- * Hadoop 1 and 2.
- */
- public static void progress(TaskAttemptContext context)
- {
- invoke(PROGRESS_METHOD, context);
- }
-
- /**
- * Increment the counter. Works with both Hadoop 1 and 2
- */
- public static void incrementCounter(Counter counter, long increment)
- {
- // incrementing a count might be called often. Might be affected by
- // cost of invoke(). might be good candidate to handle in a shim.
- // (TODO Raghu) figure out how achieve such a build with maven
- invoke(INCREMENT_COUNTER_METHOD, counter, increment);
- }
-}
diff --git a/src/java/org/apache/cassandra/hadoop/ReporterWrapper.java b/src/java/org/apache/cassandra/hadoop/ReporterWrapper.java
deleted file mode 100644
index d2cc7699ad..0000000000
--- a/src/java/org/apache/cassandra/hadoop/ReporterWrapper.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cassandra.hadoop;
-
-import org.apache.hadoop.mapred.Counters;
-import org.apache.hadoop.mapred.InputSplit;
-import org.apache.hadoop.mapred.Reporter;
-import org.apache.hadoop.mapreduce.StatusReporter;
-
-/**
- * A reporter that works with both mapred and mapreduce APIs.
- */
-public class ReporterWrapper extends StatusReporter implements Reporter
-{
- private Reporter wrappedReporter;
-
- public ReporterWrapper(Reporter reporter)
- {
- wrappedReporter = reporter;
- }
-
- @Override
- public Counters.Counter getCounter(Enum> anEnum)
- {
- return wrappedReporter.getCounter(anEnum);
- }
-
- @Override
- public Counters.Counter getCounter(String s, String s1)
- {
- return wrappedReporter.getCounter(s, s1);
- }
-
- @Override
- public void incrCounter(Enum> anEnum, long l)
- {
- wrappedReporter.incrCounter(anEnum, l);
- }
-
- @Override
- public void incrCounter(String s, String s1, long l)
- {
- wrappedReporter.incrCounter(s, s1, l);
- }
-
- @Override
- public InputSplit getInputSplit() throws UnsupportedOperationException
- {
- return wrappedReporter.getInputSplit();
- }
-
- @Override
- public void progress()
- {
- wrappedReporter.progress();
- }
-
- // @Override
- public float getProgress()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void setStatus(String s)
- {
- wrappedReporter.setStatus(s);
- }
-}
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/CqlBulkOutputFormat.java b/src/java/org/apache/cassandra/hadoop/cql3/CqlBulkOutputFormat.java
deleted file mode 100644
index dfdf855e57..0000000000
--- a/src/java/org/apache/cassandra/hadoop/cql3/CqlBulkOutputFormat.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.hadoop.cql3;
-
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.cassandra.hadoop.ConfigHelper;
-import org.apache.cassandra.hadoop.HadoopCompat;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.mapred.JobConf;
-import org.apache.hadoop.mapreduce.JobContext;
-import org.apache.hadoop.mapreduce.OutputCommitter;
-import org.apache.hadoop.mapreduce.OutputFormat;
-import org.apache.hadoop.mapreduce.RecordWriter;
-import org.apache.hadoop.mapreduce.TaskAttemptContext;
-import org.apache.hadoop.util.Progressable;
-
-/**
- * The CqlBulkOutputFormat acts as a Hadoop-specific
- * OutputFormat that allows reduce tasks to store keys (and corresponding
- * bound variable values) as CQL rows (and respective columns) in a given
- * table.
- *
- *
- * As is the case with the {@link org.apache.cassandra.hadoop.cql3.CqlOutputFormat},
- * you need to set the prepared statement in your
- * Hadoop job Configuration. The {@link CqlConfigHelper} class, through its
- * {@link org.apache.cassandra.hadoop.ConfigHelper#setOutputPreparedStatement} method, is provided to make this
- * simple.
- * you need to set the Keyspace. The {@link ConfigHelper} class, through its
- * {@link org.apache.cassandra.hadoop.ConfigHelper#setOutputColumnFamily} method, is provided to make this
- * simple.
- *
- */
-public class CqlBulkOutputFormat extends OutputFormat
- *
- * @param keyColumns
- * the key to write.
- * @param values
- * the values to write.
- * @throws IOException
- */
- @Override
- public void write(Map keyColumns, List values) throws IOException
- {
- TokenRange range = ringCache.getRange(getPartitionKey(keyColumns));
-
- // get the client for the given range, or create a new one
- final InetAddress address = ringCache.getEndpoints(range).get(0);
- RangeClient client = clients.get(address);
- if (client == null)
- {
- // haven't seen keys for this range: create new client
- client = new RangeClient(ringCache.getEndpoints(range));
- client.start();
- clients.put(address, client);
- }
-
- // add primary key columns to the bind variables
- List allValues = new ArrayList(values);
- for (ColumnMetadata column : partitionKeyColumns)
- allValues.add(keyColumns.get(column.getName()));
- for (ColumnMetadata column : clusterColumns)
- allValues.add(keyColumns.get(column.getName()));
-
- client.put(allValues);
-
- if (progressable != null)
- progressable.progress();
- if (context != null)
- HadoopCompat.progress(context);
- }
-
- private static void closeSession(Session session)
- {
- //Close the session to satisfy to avoid warnings for the resource not being closed
- try
- {
- if (session != null)
- session.getCluster().closeAsync();
- }
- catch (Throwable t)
- {
- logger.warn("Error closing connection", t);
- }
- }
-
- /**
- * A client that runs in a threadpool and connects to the list of endpoints for a particular
- * range. Bound variables for keys in that range are sent to this client via a queue.
- */
- public class RangeClient extends Thread
- {
- // The list of endpoints for this range
- protected final List endpoints;
- protected Cluster cluster = null;
- // A bounded queue of incoming mutations for this range
- protected final BlockingQueue> queue = new ArrayBlockingQueue>(queueSize);
-
- protected volatile boolean run = true;
- // we want the caller to know if something went wrong, so we record any unrecoverable exception while writing
- // so we can throw it on the caller's stack when he calls put() again, or if there are no more put calls,
- // when the client is closed.
- protected volatile IOException lastException;
-
- /**
- * Constructs an {@link RangeClient} for the given endpoints.
- * @param endpoints the possible endpoints to execute the mutations on
- */
- public RangeClient(List endpoints)
- {
- super("client-" + endpoints);
- this.endpoints = endpoints;
- }
-
- /**
- * enqueues the given value to Cassandra
- */
- public void put(List value) throws IOException
- {
- while (true)
- {
- if (lastException != null)
- throw lastException;
- try
- {
- if (queue.offer(value, 100, TimeUnit.MILLISECONDS))
- break;
- }
- catch (InterruptedException e)
- {
- throw new AssertionError(e);
- }
- }
- }
-
- /**
- * Loops collecting cql binded variable values from the queue and sending to Cassandra
- */
- @SuppressWarnings("resource")
- public void run()
- {
- Session session = null;
-
- try
- {
- outer:
- while (run || !queue.isEmpty())
- {
- List bindVariables;
- try
- {
- bindVariables = queue.take();
- }
- catch (InterruptedException e)
- {
- // re-check loop condition after interrupt
- continue;
- }
-
- ListIterator iter = endpoints.listIterator();
- while (true)
- {
- // send the mutation to the last-used endpoint. first time through, this will NPE harmlessly.
- if (session != null)
- {
- try
- {
- int i = 0;
- PreparedStatement statement = preparedStatement(session);
- while (bindVariables != null)
- {
- BoundStatement boundStatement = new BoundStatement(statement);
- for (int columnPosition = 0; columnPosition < bindVariables.size(); columnPosition++)
- {
- boundStatement.setBytesUnsafe(columnPosition, bindVariables.get(columnPosition));
- }
- session.execute(boundStatement);
- i++;
-
- if (i >= batchThreshold)
- break;
- bindVariables = queue.poll();
- }
- break;
- }
- catch (Exception e)
- {
- closeInternal();
- if (!iter.hasNext())
- {
- lastException = new IOException(e);
- break outer;
- }
- }
- }
-
- // attempt to connect to a different endpoint
- try
- {
- InetAddress address = iter.next();
- String host = address.getHostName();
- cluster = CqlConfigHelper.getOutputCluster(host, conf);
- closeSession(session);
- session = cluster.connect();
- }
- catch (Exception e)
- {
- //If connection died due to Interrupt, just try connecting to the endpoint again.
- //There are too many ways for the Thread.interrupted() state to be cleared, so
- //we can't rely on that here. Until the java driver gives us a better way of knowing
- //that this exception came from an InterruptedException, this is the best solution.
- if (canRetryDriverConnection(e))
- {
- iter.previous();
- }
- closeInternal();
-
- // Most exceptions mean something unexpected went wrong to that endpoint, so
- // we should try again to another. Other exceptions (auth or invalid request) are fatal.
- if ((e instanceof AuthenticationException || e instanceof InvalidQueryException) || !iter.hasNext())
- {
- lastException = new IOException(e);
- break outer;
- }
- }
- }
- }
- }
- finally
- {
- closeSession(session);
- // close all our connections once we are done.
- closeInternal();
- }
- }
-
- /** get prepared statement id from cache, otherwise prepare it from Cassandra server*/
- private PreparedStatement preparedStatement(Session client)
- {
- PreparedStatement statement = preparedStatements.get(client);
- if (statement == null)
- {
- PreparedStatement result;
- try
- {
- result = client.prepare(cql);
- }
- catch (NoHostAvailableException e)
- {
- throw new RuntimeException("failed to prepare cql query " + cql, e);
- }
-
- PreparedStatement previousId = preparedStatements.putIfAbsent(client, result);
- statement = previousId == null ? result : previousId;
- }
- return statement;
- }
-
- public void close() throws IOException
- {
- // stop the run loop. this will result in closeInternal being called by the time join() finishes.
- run = false;
- interrupt();
- try
- {
- this.join();
- }
- catch (InterruptedException e)
- {
- throw new AssertionError(e);
- }
-
- if (lastException != null)
- throw lastException;
- }
-
- protected void closeInternal()
- {
- if (cluster != null)
- {
- cluster.close();
- }
- }
-
- private boolean canRetryDriverConnection(Exception e)
- {
- if (e instanceof DriverException && e.getMessage().contains("Connection thread interrupted"))
- return true;
- if (e instanceof NoHostAvailableException)
- {
- if (((NoHostAvailableException) e).getErrors().size() == 1)
- {
- Throwable cause = ((NoHostAvailableException) e).getErrors().values().iterator().next();
- if (cause != null && cause.getCause() instanceof java.nio.channels.ClosedByInterruptException)
- {
- return true;
- }
- }
- }
- return false;
- }
- }
-
- private ByteBuffer getPartitionKey(Map keyColumns)
- {
- ByteBuffer partitionKey;
- if (partitionKeyColumns.size() > 1)
- {
- ByteBuffer[] keys = new ByteBuffer[partitionKeyColumns.size()];
- for (int i = 0; i< keys.length; i++)
- keys[i] = keyColumns.get(partitionKeyColumns.get(i).getName());
-
- partitionKey = CompositeType.build(ByteBufferAccessor.instance, keys);
- }
- else
- {
- partitionKey = keyColumns.get(partitionKeyColumns.get(0).getName());
- }
- return partitionKey;
- }
-
- /**
- * add where clauses for partition keys and cluster columns
- */
- private String appendKeyWhereClauses(String cqlQuery)
- {
- String keyWhereClause = "";
-
- for (ColumnMetadata partitionKey : partitionKeyColumns)
- keyWhereClause += String.format("%s = ?", keyWhereClause.isEmpty() ? quote(partitionKey.getName()) : (" AND " + quote(partitionKey.getName())));
- for (ColumnMetadata clusterColumn : clusterColumns)
- keyWhereClause += " AND " + quote(clusterColumn.getName()) + " = ?";
-
- return cqlQuery + " WHERE " + keyWhereClause;
- }
-
- /** Quoting for working with uppercase */
- private String quote(String identifier)
- {
- return "\"" + identifier.replaceAll("\"", "\"\"") + "\"";
- }
-
- static class NativeRingCache
- {
- private final Map> rangeMap;
- private final Metadata metadata;
- private final IPartitioner partitioner;
-
- public NativeRingCache(Configuration conf, Metadata metadata)
- {
- this.partitioner = ConfigHelper.getOutputPartitioner(conf);
- this.metadata = metadata;
- String keyspace = ConfigHelper.getOutputKeyspace(conf);
- this.rangeMap = metadata.getTokenRanges()
- .stream()
- .collect(toMap(p -> p, p -> metadata.getReplicas('"' + keyspace + '"', p)));
- }
-
- public TokenRange getRange(ByteBuffer key)
- {
- Token t = partitioner.getToken(key);
- com.datastax.driver.core.Token driverToken = metadata.newToken(partitioner.getTokenFactory().toString(t));
- for (TokenRange range : rangeMap.keySet())
- {
- if (range.contains(driverToken))
- {
- return range;
- }
- }
-
- throw new RuntimeException("Invalid token information returned by describe_ring: " + rangeMap);
- }
-
- public List getEndpoints(TokenRange range)
- {
- Set hostSet = rangeMap.get(range);
- List addresses = new ArrayList<>(hostSet.size());
- for (Host host: hostSet)
- {
- addresses.add(host.getAddress());
- }
- return addresses;
- }
- }
-}
diff --git a/src/java/org/apache/cassandra/hadoop/cql3/LimitedLocalNodeFirstLocalBalancingPolicy.java b/src/java/org/apache/cassandra/hadoop/cql3/LimitedLocalNodeFirstLocalBalancingPolicy.java
deleted file mode 100644
index 59b4ecab11..0000000000
--- a/src/java/org/apache/cassandra/hadoop/cql3/LimitedLocalNodeFirstLocalBalancingPolicy.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.cassandra.hadoop.cql3;
-
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Host;
-import com.datastax.driver.core.HostDistance;
-import com.datastax.driver.core.Statement;
-import com.datastax.driver.core.policies.LoadBalancingPolicy;
-import com.google.common.base.Function;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Sets;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.util.*;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-/**
- * This load balancing policy is intended to be used only for CqlRecordReader when it fetches a particular split.
- *
- * It chooses alive hosts only from the set of the given replicas - because the connection is used to load the data from
- * the particular split, with a strictly defined list of the replicas, it is pointless to try the other nodes.
- * The policy tracks which of the replicas are alive, and when a new query plan is requested, it returns those replicas
- * in the following order:
- *
- *
the local node
- *
the collection of the remaining hosts (which is shuffled on each request)
- *
- */
-class LimitedLocalNodeFirstLocalBalancingPolicy implements LoadBalancingPolicy
-{
- private final static Logger logger = LoggerFactory.getLogger(LimitedLocalNodeFirstLocalBalancingPolicy.class);
-
- private final static Set localAddresses = Collections.unmodifiableSet(getLocalInetAddresses());
-
- private final CopyOnWriteArraySet liveReplicaHosts = new CopyOnWriteArraySet<>();
-
- private final Set replicaAddresses = new HashSet<>();
- private final Set allowedDCs = new CopyOnWriteArraySet<>();
-
- public LimitedLocalNodeFirstLocalBalancingPolicy(String[] replicas)
- {
- for (String replica : replicas)
- {
- try
- {
- InetAddress[] addresses = InetAddress.getAllByName(replica);
- Collections.addAll(replicaAddresses, addresses);
- }
- catch (UnknownHostException e)
- {
- logger.warn("Invalid replica host name: {}, skipping it", replica);
- }
- }
- if (logger.isTraceEnabled())
- logger.trace("Created instance with the following replicas: {}", Arrays.asList(replicas));
- }
-
- @Override
- public void init(Cluster cluster, Collection hosts)
- {
- // first find which DCs the user defined
- Set dcs = new HashSet<>();
- for (Host host : hosts)
- {
- if (replicaAddresses.contains(host.getAddress()))
- dcs.add(host.getDatacenter());
- }
- // filter to all nodes within the targeted DCs
- List replicaHosts = new ArrayList<>();
- for (Host host : hosts)
- {
- if (dcs.contains(host.getDatacenter()))
- replicaHosts.add(host);
- }
- liveReplicaHosts.addAll(replicaHosts);
- allowedDCs.addAll(dcs);
- logger.trace("Initialized with replica hosts: {}", replicaHosts);
- }
-
- @Override
- public void close()
- {
- //
- }
-
- @Override
- public HostDistance distance(Host host)
- {
- if (isLocalHost(host))
- {
- return HostDistance.LOCAL;
- }
- else
- {
- return HostDistance.REMOTE;
- }
- }
-
- @Override
- public Iterator newQueryPlan(String keyspace, Statement statement)
- {
- List local = new ArrayList<>(1);
- List remote = new ArrayList<>(liveReplicaHosts.size());
- for (Host liveReplicaHost : liveReplicaHosts)
- {
- if (isLocalHost(liveReplicaHost))
- {
- local.add(liveReplicaHost);
- }
- else
- {
- remote.add(liveReplicaHost);
- }
- }
-
- Collections.shuffle(remote);
-
- logger.trace("Using the following hosts order for the new query plan: {} | {}", local, remote);
-
- return Iterators.concat(local.iterator(), remote.iterator());
- }
-
- @Override
- public void onAdd(Host host)
- {
- if (liveReplicaHosts.contains(host))
- {
- liveReplicaHosts.add(host);
- logger.trace("Added a new host {}", host);
- }
- }
-
- @Override
- public void onUp(Host host)
- {
- if (liveReplicaHosts.contains(host))
- {
- liveReplicaHosts.add(host);
- logger.trace("The host {} is now up", host);
- }
- }
-
- @Override
- public void onDown(Host host)
- {
- if (liveReplicaHosts.remove(host))
- {
- logger.trace("The host {} is now down", host);
- }
- }
-
-
- @Override
- public void onRemove(Host host)
- {
- if (liveReplicaHosts.remove(host))
- {
- logger.trace("Removed the host {}", host);
- }
- }
-
- public void onSuspected(Host host)
- {
- // not supported by this load balancing policy
- }
-
- private static boolean isLocalHost(Host host)
- {
- InetAddress hostAddress = host.getAddress();
- return hostAddress.isLoopbackAddress() || localAddresses.contains(hostAddress);
- }
-
- private static Set getLocalInetAddresses()
- {
- try
- {
- return Sets.newHashSet(Iterators.concat(
- Iterators.transform(
- Iterators.forEnumeration(NetworkInterface.getNetworkInterfaces()),
- new Function>()
- {
- @Override
- public Iterator apply(NetworkInterface netIface)
- {
- return Iterators.forEnumeration(netIface.getInetAddresses());
- }
- })));
- }
- catch (SocketException e)
- {
- logger.warn("Could not retrieve local network interfaces.", e);
- return Collections.emptySet();
- }
- }
-}
diff --git a/src/java/org/apache/cassandra/hadoop/package-info.java b/src/java/org/apache/cassandra/hadoop/package-info.java
deleted file mode 100644
index 835165b738..0000000000
--- a/src/java/org/apache/cassandra/hadoop/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * This package was deprecated. See CASSANDRA-16984.
- */
-@Deprecated
-package org.apache.cassandra.hadoop;
\ No newline at end of file
diff --git a/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java b/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java
index a050245d04..e6046979ff 100644
--- a/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java
+++ b/test/burn/org/apache/cassandra/transport/SimpleClientPerfTest.java
@@ -30,7 +30,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import com.google.common.util.concurrent.RateLimiter;
-import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/test/simulator/main/org/apache/cassandra/simulator/debug/SelfReconcilingRandom.java b/test/simulator/main/org/apache/cassandra/simulator/debug/SelfReconcilingRandom.java
index 444ec44344..99df4b987e 100644
--- a/test/simulator/main/org/apache/cassandra/simulator/debug/SelfReconcilingRandom.java
+++ b/test/simulator/main/org/apache/cassandra/simulator/debug/SelfReconcilingRandom.java
@@ -20,24 +20,29 @@ package org.apache.cassandra.simulator.debug;
import java.util.function.Supplier;
+import org.agrona.collections.Long2LongHashMap;
import org.apache.cassandra.simulator.RandomSource;
-import org.hsqldb.lib.IntKeyLongValueHashMap;
import static org.apache.cassandra.simulator.SimulatorUtils.failWithOOM;
public class SelfReconcilingRandom implements Supplier
{
- static class Map extends IntKeyLongValueHashMap
+ static class Map extends Long2LongHashMap
{
+ public Map(long missingValue)
+ {
+ super(missingValue);
+ }
+
public boolean put(int i, long v)
{
int size = this.size();
- super.addOrRemove((long)i, (long)v, (Object)null, (Object)null, false);
+ super.put(i, v);
return size != this.size();
}
}
- final Map map = new Map();
- long[] tmp = new long[1];
+
+ final Map map = new Map(Long.MIN_VALUE);
boolean isNextPrimary = true;
static abstract class AbstractVerifying extends RandomSource.Abstract
@@ -113,10 +118,11 @@ public class SelfReconcilingRandom implements Supplier
{
void next(long v)
{
- if (!map.get(++cur, tmp))
+ long value = map.get(++cur);
+ if (value == Long.MIN_VALUE)
throw failWithOOM();
map.remove(cur);
- if (tmp[0] != v)
+ if (value != v)
throw failWithOOM();
}