Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Excavator: Upgrades Baseline to the latest version #5517

Merged
merged 2 commits into from
Jul 5, 2021
Merged
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 @@ -43,6 +43,7 @@ private ColumnSelection(SortedSet<byte[]> selectedColumns) {
this.selectedColumns = selectedColumns;
}

@SuppressWarnings("BadAssert") // performance sensitive asserts
public static ColumnSelection valueOf(String serialized) {
Set<byte[]> columns = new TreeSet<>(UnsignedBytes.lexicographicalComparator());
for (String columnString : serialized.split("\\s*,\\s*")) {
Expand Down Expand Up @@ -93,6 +94,7 @@ public boolean allColumnsSelected() {
return selectedColumns == null;
}

@SuppressWarnings("BadAssert") // performance sensitive asserts
public Collection<byte[]> getSelectedColumns() {
assert selectedColumns != null;
return Collections.unmodifiableCollection(selectedColumns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private CassandraKeyValueServices() {
/**
* Attempt to wait until a quorum of nodes has reached consensus on a schema version, and it is known that no
* other nodes currently disagree with this quorum.
*
* <p>
* The goals of this method include:
* <ol>
* <li>
Expand All @@ -87,10 +87,9 @@ private CassandraKeyValueServices() {
* </li>
* </ol>
*
* @param schemaMutationTimeMillis time to wait for nodes' schema versions to match.
* @param client Cassandra client.
* @param schemaMutationTimeMillis time to wait for nodes' schema versions to match.
* @param client Cassandra client.
* @param unsafeSchemaChangeDescription description of the schema change that was performed prior to this check.
*
* @throws IllegalStateException if we wait for more than schemaMutationTimeoutMillis specified in config.
*/
static void waitForSchemaVersions(
Expand Down Expand Up @@ -203,6 +202,7 @@ static String encodeAsHex(byte[] array) {
return "0x" + PtBytes.encodeHexString(array);
}

@SuppressWarnings("BadAssert") // performance sensitive asserts
public static ByteBuffer makeCompositeBuffer(byte[] colName, long positiveTimestamp) {
assert colName.length <= 1 << 16 : "Cannot use column names larger than 64KiB, was " + colName.length;

Expand Down Expand Up @@ -295,7 +295,7 @@ static Column createColumn(Cell cell, Value value) {
* These columns have an Atlas timestamp of zero, but should not have a Cassandra timestamp of zero as that may
* interfere with compactions. We want these to be at least reasonably consistent with Atlas's overall logical
* time.
*
* <p>
* In practice, usage may involve obtaining a (reasonably) fresh timestamp and using that as the timestamp for the
* deletion.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static <T> Collection<T> chooseRandomElements(Iterator<? extends T> it, f
ret.set(nextInt, next);
}
}
assert i != Integer.MAX_VALUE : "i is too big";
Preconditions.checkState(i != Integer.MAX_VALUE, "i is too big");
}
return ret;
}
Expand Down Expand Up @@ -140,6 +140,7 @@ private IteratorUtils() {
/**
* The iterators provided to this function have to be sorted and strictly increasing.
*/
@SuppressWarnings("BadAssert") // performance sensitive assert checks
public static <T> Iterator<T> mergeIterators(
Iterator<? extends T> one,
Iterator<? extends T> two,
Expand All @@ -157,16 +158,12 @@ protected T computeNext() {
}
if (!a.hasNext()) {
T ret = b.next();
if (b.hasNext()) {
assert ordering.compare(ret, b.peek()) < 0;
}
assert !b.hasNext() || ordering.compare(ret, b.peek()) < 0;
return ret;
}
if (!b.hasNext()) {
T ret = a.next();
if (a.hasNext()) {
assert ordering.compare(ret, a.peek()) < 0;
}
assert !a.hasNext() || ordering.compare(ret, a.peek()) < 0;
return ret;
}
T peekA = a.peek();
Expand All @@ -176,15 +173,11 @@ protected T computeNext() {
return mergeFunction.apply(Pair.create(a.next(), b.next()));
} else if (comp < 0) {
T ret = a.next();
if (a.hasNext()) {
assert ordering.compare(ret, a.peek()) < 0;
}
assert !a.hasNext() || ordering.compare(ret, a.peek()) < 0;
return ret;
} else {
T ret = b.next();
if (b.hasNext()) {
assert ordering.compare(ret, b.peek()) < 0;
}
assert !b.hasNext() || ordering.compare(ret, b.peek()) < 0;
return ret;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.palantir.common.concurrent;

import com.google.common.base.Throwables;
import com.palantir.logsafe.Preconditions;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
Expand All @@ -40,12 +41,13 @@ public BlockingWorkerPool(ExecutorService executor, int concurrentTaskLimit) {
* currently executing tasks has finished.
*
* @throws RuntimeException wrapping an ExecutionException if a previously
* submitted task threw an exception.
* submitted task threw an exception.
*/
public synchronized void submitTask(Runnable task) throws InterruptedException {
waitForAvailability();

assert currentTaskCount.get() < concurrentTaskLimit : "currentTaskCount must be less than currentTaskLimit";
Preconditions.checkState(
currentTaskCount.get() < concurrentTaskLimit, "currentTaskCount must be less than currentTaskLimit");
service.submit(task, null);
currentTaskCount.incrementAndGet();
}
Expand All @@ -69,7 +71,7 @@ private void waitForSingleTask() throws InterruptedException {
* finish.
*
* @throws RuntimeException wrapping an ExecutionException if a previously
* submitted task threw an exception.
* submitted task threw an exception.
*/
public synchronized void waitForSubmittedTasks() throws InterruptedException {
while (currentTaskCount.get() > 0) {
Expand All @@ -79,6 +81,7 @@ public synchronized void waitForSubmittedTasks() throws InterruptedException {

/**
* Waits until the number of tasks drops below the concurrent task limit.
*
* @throws InterruptedException
*/
public synchronized void waitForAvailability() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.reflect.Proxy;
import java.util.function.Supplier;

@SuppressWarnings("ProxyNonConstantType")
public class DelayProxy implements DelegatingInvocationHandler {

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("ProxyNonConstantType")
public final class ExperimentRunningProxy<T> extends AbstractInvocationHandler {
private static final Logger log = LoggerFactory.getLogger(ExperimentRunningProxy.class);
static final Duration REFRESH_INTERVAL = Duration.ofMinutes(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
* Proxy that calls the requested method in another thread waits on a Future.
* If the calling thread is interrupted, this proxy will throw a PalantirInterruptedException.
* If given the CancelDelgate#Cancel option, it will also interrupt the delegated thread.
* @author dcohen
*
* @author dcohen
*/
@SuppressWarnings("ProxyNonConstantType")
public final class InterruptibleProxy implements DelegatingInvocationHandler {
private static final Supplier<ExecutorService> defaultExecutor =
Suppliers.memoize(() -> PTExecutors.newCachedThreadPool("Interruptible Proxy"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
* are/aren't called, but you want to use a Fake to do the work.
* <p>
*/
@SuppressWarnings("ProxyNonConstantType")
public final class MultiDelegateProxy<T> extends AbstractInvocationHandler {
private static final Logger log = LoggerFactory.getLogger(MultiDelegateProxy.class);

@SafeVarargs
public static <T> T newProxyInstance(Class<T> interfaceClass, T mainDelegate, T... delegatesToCall) {
return newProxyInstance(interfaceClass, mainDelegate, Arrays.asList(delegatesToCall));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("ProxyNonConstantType")
public final class PredicateSwitchedProxy<T> extends AbstractInvocationHandler {
private final T firstService;
private final T secondService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("ProxyNonConstantType")
public final class ReplaceIfExceptionMatchingProxy<T> extends AbstractInvocationHandler {
private static final Logger log = LoggerFactory.getLogger(ReplaceIfExceptionMatchingProxy.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

@SuppressWarnings("ProxyNonConstantType")
public final class TimingProxy implements DelegatingInvocationHandler {

@SuppressWarnings("unchecked")
Expand All @@ -43,7 +44,6 @@ private TimingProxy(Object delegate, OperationTimer timer) {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
TimingState token = timer.begin(method.getName());
assert token != null;
try {
return method.invoke(delegate, args);
} catch (InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("BadAssert") // explicitly using asserts for test-only
public class AssertUtils {

/**
Expand All @@ -33,7 +34,7 @@ public class AssertUtils {
* which is extremely annoying to try to filter based on your logging properties.
* (Should it go into the server error log, or maybe the upgrade log, or the import log file?
* Can't tell, cause it's all AssertUtils!)
*
* <p>
* Until we get all downstream projects off of using defaultLog however,
* this will stay, just deprecated.
*/
Expand Down
38 changes: 26 additions & 12 deletions atlasdb-commons/src/main/java/com/palantir/util/SoftCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.palantir.logsafe.Preconditions;
import com.palantir.logsafe.UnsafeArg;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
Expand All @@ -36,7 +38,6 @@

/**
* Thread Safe
*
*/
public class SoftCache<K, V> extends MBeanCache<K, V> {
private static final int INITIAL_SIZE = 1000;
Expand Down Expand Up @@ -101,7 +102,10 @@ private synchronized void removeReference(Reference<? extends V> ref) {
cacheEntries.remove(key);
}
} else {
assert false : "All references should be of type KeyedReference";
Preconditions.checkState(
false,
"All references should be of type KeyedReference",
UnsafeArg.of("ref", ref == null ? "null" : ref.getClass().getName()));
}
}

Expand All @@ -121,7 +125,9 @@ public synchronized boolean containsValue(V val) {
return false;
}

/** Adds an object to the cache.
/**
* Adds an object to the cache.
*
* @param key
* @param value
*/
Expand Down Expand Up @@ -166,7 +172,9 @@ public void putAllIfAbsent(Map<? extends K, ? extends V> map, long loadTimeInMil
putAllIfAbsent(map);
}

/** Gets an object from the cache.
/**
* Gets an object from the cache.
*
* @param key
*/
@Override
Expand Down Expand Up @@ -203,7 +211,9 @@ public synchronized V get(K key) {
return ret;
}

/** Removes an object from the cache.
/**
* Removes an object from the cache.
*
* @param key
*/
public synchronized V remove(K key) {
Expand All @@ -216,7 +226,8 @@ public synchronized int size() {
return cacheEntries.size();
}

/** Clears all entries from the cache.
/**
* Clears all entries from the cache.
*/
@Override
public synchronized void clear() {
Expand Down Expand Up @@ -255,6 +266,7 @@ public synchronized Set<V> removeMatchingKeys(Predicate<K> predicate) {
* Iterates through the cache and cleans up any cache references that have
* been collected by the garbage collector.
*/
@SuppressWarnings("BadAssert") // performance sensitive assertion checks
public final void cleanup() {
mbean.cleanups.incrementAndGet();
if (log.isTraceEnabled()) {
Expand All @@ -279,16 +291,17 @@ public final void cleanup() {
* Convenience cache operations *****************************
*/

/** This convenience method filters a request by removing all items in the request which
/**
* This convenience method filters a request by removing all items in the request which
* are in the cache and returning the corresponding values.
*
* <p>
* Synchronization note: this method is not synchronized on the cache. Thus, if replacements
* are performed during a canonicalization, it is undefined which object is returned. Similarly,
* this function is not synchronized on the request collection, so if synchronization is required,
* it must be performed externally.
*
* @param request The list of items to be fetched from the backing store. This collection must
* be modifiable.
* be modifiable.
*/
public Collection<V> filter(Collection<K> request) {
Collection<V> rv = new ArrayList<V>();
Expand All @@ -307,12 +320,13 @@ public Collection<V> filter(Collection<K> request) {
return rv;
}

/** This convenience method takes a map of items returned from the backing store and replaces
/**
* This convenience method takes a map of items returned from the backing store and replaces
* references loaded from the backing store with items in the cache.
*
* <p>
* A call to canonicalize will typically be followed by a putAll on the returnVal, so that
* future requests to the cache will return the new items loaded.
*
* <p>
* Synchronization note: this method is not synchronized on the cache. Thus, if replacements
* are performed during a canonicalization, it is undefined which object is returned. Similarly,
* this function is not synchronized on the returnVal map, so if synchronization is required, it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static String[] getStackTraceForConnection(MBeanServerConnection connecti
return getStackTraceForConnection(connection, false);
}

@SuppressWarnings("BadAssert") // performance sensitive
public static String[] getStackTraceForConnection(MBeanServerConnection connection, boolean redact)
throws JMException, IOException {
long[] threadIDs = (long[]) connection.getAttribute(THREAD_MXBEAN, "AllThreadIds");
Expand Down Expand Up @@ -125,7 +126,7 @@ public static String[] getStackTraceForConnection(MBeanServerConnection connecti
stackDepths[j] = ((Integer) getLockedStackDepthMethod.invoke(lockedMonitors[j])).intValue();
}
} catch (InvocationTargetException e) {
/** if lockedMonitors is not empty, then getLockedMonitors exists,
/* if lockedMonitors is not empty, then getLockedMonitors exists,
* ergo monitorInfo exists and we should never end up here
* (or in the next catch block)
*/
Expand Down Expand Up @@ -310,9 +311,9 @@ public static String processTrace(String serverName, String[] traces, boolean ab
}

/**
* This function pluralizes the given text and now accounts for three capitalization cases: lower case, Camel Case, and ALL CAPS.
* It converts the text to lower case first and looks it up in the plurals dictionary (which we assume to be all lower case now).
* If it does not exist, it simply appends a "s" to the word. Then it converts the capitalization. Also see TextUtilText.testPluralizeWithCaps().
* This function pluralizes the given text and now accounts for three capitalization cases: lower case, Camel Case, and ALL CAPS.
* It converts the text to lower case first and looks it up in the plurals dictionary (which we assume to be all lower case now).
* If it does not exist, it simply appends a "s" to the word. Then it converts the capitalization. Also see TextUtilText.testPluralizeWithCaps().
*/
public static String pluralize(String text) {
if (text == null || "".equals(text)) {
Expand All @@ -336,7 +337,6 @@ public static String pluralize(String text) {
if (plural != null && plural.length() > 0) {
return Character.toUpperCase(plural.charAt(0)) + plural.substring(1); // Camel Case
} else {
assert false : "dictionary entry too short";
return plural;
}
} else {
Expand Down
Loading