Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.Arrays;

import com.google.common.base.Preconditions;
import org.apache.spark.network.util.JavaUtils;

/**
* A factory for array wrappers so that arrays can be used as keys in a map, sorted or not.
Expand All @@ -38,7 +38,7 @@ class ArrayWrappers {

@SuppressWarnings("unchecked")
public static Comparable<Object> forArray(Object a) {
Preconditions.checkArgument(a.getClass().isArray());
JavaUtils.checkArgument(a.getClass().isArray(), "Input should be an array");
Comparable<?> ret;
if (a instanceof int[] ia) {
ret = new ComparableIntArray(ia);
Expand All @@ -47,7 +47,8 @@ public static Comparable<Object> forArray(Object a) {
} else if (a instanceof byte[] ba) {
ret = new ComparableByteArray(ba);
} else {
Preconditions.checkArgument(!a.getClass().getComponentType().isPrimitive());
JavaUtils.checkArgument(!a.getClass().getComponentType().isPrimitive(),
"Array element is primitive");
ret = new ComparableObjectArray((Object[]) a);
}
return (Comparable<Object>) ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.common.base.Preconditions;

import org.apache.spark.annotation.Private;
import org.apache.spark.network.util.JavaUtils;

/**
* Implementation of KVStore that keeps data deserialized in memory. This store does not index
Expand Down Expand Up @@ -419,7 +418,7 @@ private List<T> copyElements() {
// Go through all the values in `data` and collect all the objects has certain parent
// value. This can be slow when there is a large number of entries in `data`.
KVTypeInfo.Accessor parentGetter = ti.getParentAccessor(index);
Preconditions.checkArgument(parentGetter != null, "Parent filter for non-child index.");
JavaUtils.checkArgument(parentGetter != null, "Parent filter for non-child index.");
return data.values().stream()
.filter(e -> compare(e, parentGetter, parentKey) == 0)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

import java.util.Objects;

import com.google.common.base.Preconditions;

import org.apache.spark.annotation.Private;
import org.apache.spark.network.util.JavaUtils;

/**
* A configurable view that allows iterating over values in a {@link KVStore}.
Expand Down Expand Up @@ -98,7 +97,7 @@ public KVStoreView<T> last(Object value) {
* Stops iteration after a number of elements has been retrieved.
*/
public KVStoreView<T> max(long max) {
Preconditions.checkArgument(max > 0L, "max must be positive.");
JavaUtils.checkArgument(max > 0L, "max must be positive.");
this.max = max;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import java.util.Map;
import java.util.stream.Stream;

import com.google.common.base.Preconditions;

import org.apache.spark.annotation.Private;
import org.apache.spark.network.util.JavaUtils;

/**
* Wrapper around types managed in a KVStore, providing easy access to their indexed fields.
Expand Down Expand Up @@ -56,37 +55,37 @@ public KVTypeInfo(Class<?> type) {
KVIndex idx = m.getAnnotation(KVIndex.class);
if (idx != null) {
checkIndex(idx, indices);
Preconditions.checkArgument(m.getParameterCount() == 0,
JavaUtils.checkArgument(m.getParameterCount() == 0,
"Annotated method %s::%s should not have any parameters.", type.getName(), m.getName());
m.setAccessible(true);
indices.put(idx.value(), idx);
accessors.put(idx.value(), new MethodAccessor(m));
}
}

Preconditions.checkArgument(indices.containsKey(KVIndex.NATURAL_INDEX_NAME),
JavaUtils.checkArgument(indices.containsKey(KVIndex.NATURAL_INDEX_NAME),
"No natural index defined for type %s.", type.getName());

for (KVIndex idx : indices.values()) {
if (!idx.parent().isEmpty()) {
KVIndex parent = indices.get(idx.parent());
Preconditions.checkArgument(parent != null,
JavaUtils.checkArgument(parent != null,
"Cannot find parent %s of index %s.", idx.parent(), idx.value());
Preconditions.checkArgument(parent.parent().isEmpty(),
JavaUtils.checkArgument(parent.parent().isEmpty(),
"Parent index %s of index %s cannot be itself a child index.", idx.parent(), idx.value());
}
}
}

private void checkIndex(KVIndex idx, Map<String, KVIndex> indices) {
Preconditions.checkArgument(idx.value() != null && !idx.value().isEmpty(),
JavaUtils.checkArgument(idx.value() != null && !idx.value().isEmpty(),
"No name provided for index in type %s.", type.getName());
Preconditions.checkArgument(
JavaUtils.checkArgument(
!idx.value().startsWith("_") || idx.value().equals(KVIndex.NATURAL_INDEX_NAME),
"Index name %s (in type %s) is not allowed.", idx.value(), type.getName());
Preconditions.checkArgument(idx.parent().isEmpty() || !idx.parent().equals(idx.value()),
JavaUtils.checkArgument(idx.parent().isEmpty() || !idx.parent().equals(idx.value()),
"Index %s cannot be parent of itself.", idx.value());
Preconditions.checkArgument(!indices.containsKey(idx.value()),
JavaUtils.checkArgument(!indices.containsKey(idx.value()),
"Duplicate index %s for type %s.", idx.value(), type.getName());
}

Expand All @@ -104,7 +103,7 @@ public Stream<KVIndex> indices() {

Accessor getAccessor(String indexName) {
Accessor a = accessors.get(indexName);
Preconditions.checkArgument(a != null, "No index %s.", indexName);
JavaUtils.checkArgument(a != null, "No index %s.", indexName);
return a;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import org.fusesource.leveldbjni.JniDBFactory;
import org.iq80.leveldb.DB;
Expand All @@ -39,6 +38,7 @@
import org.iq80.leveldb.WriteBatch;

import org.apache.spark.annotation.Private;
import org.apache.spark.network.util.JavaUtils;

/**
* Implementation of KVStore that uses LevelDB as the underlying data store.
Expand Down Expand Up @@ -137,20 +137,20 @@ <T> T get(byte[] key, Class<T> klass) throws Exception {
}

private void put(byte[] key, Object value) throws Exception {
Preconditions.checkArgument(value != null, "Null values are not allowed.");
JavaUtils.checkArgument(value != null, "Null values are not allowed.");
db().put(key, serializer.serialize(value));
}

@Override
public <T> T read(Class<T> klass, Object naturalKey) throws Exception {
Preconditions.checkArgument(naturalKey != null, "Null keys are not allowed.");
JavaUtils.checkArgument(naturalKey != null, "Null keys are not allowed.");
byte[] key = getTypeInfo(klass).naturalIndex().start(null, naturalKey);
return get(key, klass);
}

@Override
public void write(Object value) throws Exception {
Preconditions.checkArgument(value != null, "Null values are not allowed.");
JavaUtils.checkArgument(value != null, "Null values are not allowed.");
LevelDBTypeInfo ti = getTypeInfo(value.getClass());

try (WriteBatch batch = db().createWriteBatch()) {
Expand All @@ -163,7 +163,7 @@ public void write(Object value) throws Exception {
}

public void writeAll(List<?> values) throws Exception {
Preconditions.checkArgument(values != null && !values.isEmpty(),
JavaUtils.checkArgument(values != null && !values.isEmpty(),
"Non-empty values required.");

// Group by class, in case there are values from different classes in the values
Expand Down Expand Up @@ -225,7 +225,7 @@ private void updateBatch(

@Override
public void delete(Class<?> type, Object naturalKey) throws Exception {
Preconditions.checkArgument(naturalKey != null, "Null keys are not allowed.");
JavaUtils.checkArgument(naturalKey != null, "Null keys are not allowed.");
try (WriteBatch batch = db().createWriteBatch()) {
LevelDBTypeInfo ti = getTypeInfo(type);
byte[] key = ti.naturalIndex().start(null, naturalKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import java.util.concurrent.atomic.AtomicBoolean;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import org.iq80.leveldb.DBIterator;

import org.apache.spark.internal.SparkLogger;
import org.apache.spark.internal.SparkLoggerFactory;
import org.apache.spark.network.util.JavaUtils;

class LevelDBIterator<T> implements KVStoreIterator<T> {

Expand Down Expand Up @@ -66,7 +66,7 @@ class LevelDBIterator<T> implements KVStoreIterator<T> {
this.resourceCleaner = new ResourceCleaner(it, db);
this.cleanable = CLEANER.register(this, this.resourceCleaner);

Preconditions.checkArgument(!index.isChild() || params.parent != null,
JavaUtils.checkArgument(!index.isChild() || params.parent != null,
"Cannot iterate over child index %s without parent value.", params.index);
byte[] parent = index.isChild() ? index.parent().childPrefix(params.parent) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import java.util.Objects;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.base.Preconditions;
import org.iq80.leveldb.WriteBatch;

import org.apache.spark.network.util.JavaUtils;

/**
* Holds metadata about app-specific types stored in LevelDB. Serves as a cache for data collected
* via reflection, to make it cheaper to access it multiple times.
Expand Down Expand Up @@ -164,7 +165,7 @@ Index naturalIndex() {

Index index(String name) {
Index i = indices.get(name);
Preconditions.checkArgument(i != null, "Index %s does not exist for type %s.", name,
JavaUtils.checkArgument(i != null, "Index %s does not exist for type %s.", name,
type.getName());
return i;
}
Expand Down Expand Up @@ -253,7 +254,7 @@ Index parent() {
* same parent index exist.
*/
byte[] childPrefix(Object value) {
Preconditions.checkState(parent == null, "Not a parent index.");
JavaUtils.checkState(parent == null, "Not a parent index.");
return buildKey(name, toParentKey(value));
}

Expand All @@ -268,9 +269,9 @@ Object getValue(Object entity) throws Exception {

private void checkParent(byte[] prefix) {
if (prefix != null) {
Preconditions.checkState(parent != null, "Parent prefix provided for parent index.");
JavaUtils.checkState(parent != null, "Parent prefix provided for parent index.");
} else {
Preconditions.checkState(parent == null, "Parent prefix missing for child index.");
JavaUtils.checkState(parent == null, "Parent prefix missing for child index.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import org.rocksdb.*;

import org.apache.spark.annotation.Private;
import org.apache.spark.network.util.JavaUtils;

/**
* Implementation of KVStore that uses RocksDB as the underlying data store.
Expand Down Expand Up @@ -170,20 +170,20 @@ <T> T get(byte[] key, Class<T> klass) throws Exception {
}

private void put(byte[] key, Object value) throws Exception {
Preconditions.checkArgument(value != null, "Null values are not allowed.");
JavaUtils.checkArgument(value != null, "Null values are not allowed.");
db().put(key, serializer.serialize(value));
}

@Override
public <T> T read(Class<T> klass, Object naturalKey) throws Exception {
Preconditions.checkArgument(naturalKey != null, "Null keys are not allowed.");
JavaUtils.checkArgument(naturalKey != null, "Null keys are not allowed.");
byte[] key = getTypeInfo(klass).naturalIndex().start(null, naturalKey);
return get(key, klass);
}

@Override
public void write(Object value) throws Exception {
Preconditions.checkArgument(value != null, "Null values are not allowed.");
JavaUtils.checkArgument(value != null, "Null values are not allowed.");
RocksDBTypeInfo ti = getTypeInfo(value.getClass());
byte[] data = serializer.serialize(value);
synchronized (ti) {
Expand All @@ -195,7 +195,7 @@ public void write(Object value) throws Exception {
}

public void writeAll(List<?> values) throws Exception {
Preconditions.checkArgument(values != null && !values.isEmpty(),
JavaUtils.checkArgument(values != null && !values.isEmpty(),
"Non-empty values required.");

// Group by class, in case there are values from different classes in the values
Expand Down Expand Up @@ -257,7 +257,7 @@ private void updateBatch(

@Override
public void delete(Class<?> type, Object naturalKey) throws Exception {
Preconditions.checkArgument(naturalKey != null, "Null keys are not allowed.");
JavaUtils.checkArgument(naturalKey != null, "Null keys are not allowed.");
try (WriteBatch writeBatch = new WriteBatch()) {
RocksDBTypeInfo ti = getTypeInfo(type);
byte[] key = ti.naturalIndex().start(null, naturalKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import java.util.concurrent.atomic.AtomicBoolean;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import org.rocksdb.RocksIterator;

import org.apache.spark.network.util.JavaUtils;

class RocksDBIterator<T> implements KVStoreIterator<T> {

private static final Cleaner CLEANER = Cleaner.create();
Expand Down Expand Up @@ -58,7 +59,7 @@ class RocksDBIterator<T> implements KVStoreIterator<T> {
this.resourceCleaner = new RocksDBIterator.ResourceCleaner(it, db);
this.cleanable = CLEANER.register(this, resourceCleaner);

Preconditions.checkArgument(!index.isChild() || params.parent != null,
JavaUtils.checkArgument(!index.isChild() || params.parent != null,
"Cannot iterate over child index %s without parent value.", params.index);
byte[] parent = index.isChild() ? index.parent().childPrefix(params.parent) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import java.util.Map;
import java.util.Objects;

import com.google.common.base.Preconditions;
import org.rocksdb.RocksDBException;
import org.rocksdb.WriteBatch;

import org.apache.spark.network.util.JavaUtils;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
Expand Down Expand Up @@ -166,7 +167,7 @@ Index naturalIndex() {

Index index(String name) {
Index i = indices.get(name);
Preconditions.checkArgument(i != null, "Index %s does not exist for type %s.", name,
JavaUtils.checkArgument(i != null, "Index %s does not exist for type %s.", name,
type.getName());
return i;
}
Expand Down Expand Up @@ -255,7 +256,7 @@ Index parent() {
* same parent index exist.
*/
byte[] childPrefix(Object value) {
Preconditions.checkState(parent == null, "Not a parent index.");
JavaUtils.checkState(parent == null, "Not a parent index.");
return buildKey(name, toParentKey(value));
}

Expand All @@ -270,9 +271,9 @@ Object getValue(Object entity) throws Exception {

private void checkParent(byte[] prefix) {
if (prefix != null) {
Preconditions.checkState(parent != null, "Parent prefix provided for parent index.");
JavaUtils.checkState(parent != null, "Parent prefix provided for parent index.");
} else {
Preconditions.checkState(parent == null, "Parent prefix missing for child index.");
JavaUtils.checkState(parent == null, "Parent prefix missing for child index.");
}
}

Expand Down
Loading