Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix major issues from sonarqube #2336

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -726,11 +726,17 @@ protected void reapEvictions() {
String recursiveDeletePath = ZKPaths.makePath(curatorClient.getNamespace(), path);
ZKUtil.deleteRecursive(curatorClient.getZookeeperClient().getZooKeeper(), recursiveDeletePath);
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
log.trace("Problem deleting " + path + " (this may be ok): " + e.getMessage(), e);
}
}
}
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
log.warn("Error cleaning up eviction notices: " + e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ protected void map(Key key, Value value, org.apache.hadoop.mapreduce.Mapper<Key,
}
context.write(key, val);
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new RuntimeException("Unable to serialize response of class: " + response.getClass().getName(), e);
}
context.progress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ protected void map(Key key, Value value, org.apache.hadoop.mapreduce.Mapper<Key,
m.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp(), val);
context.write(this.tableName, m);
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new RuntimeException("Unable to serialize response of class: " + response.getClass().getName(), e);
}
context.progress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void run() {
log.debug(Thread.currentThread().getName() + ": Got null result");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// if this was on purpose, then just log and the loop will naturally exit
if (interrupted) {
log.warn("QueryLogic thread interrupted", e);
Expand Down Expand Up @@ -478,6 +479,7 @@ public void close() {
try {
holder.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("Error joining query logic thread", e);
throw new RuntimeException("Error joining query logic thread", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public boolean hasNext() {
if (failure != null) {
Throwables.propagate(failure);
}
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public RecordReader<K,RawRecordContainer> createRecordReader(InputSplit split, T
try {
reader.initialize(split, context);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Error initializing SecureEventSequenceFileRecordReader", e);
}
return reader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datawave.ingest.data.tokenize;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.hadoop.conf.Configuration;
import org.apache.log4j.Logger;
Expand All @@ -25,6 +26,7 @@ public static class HeartBeatThread extends Thread {

public static final long INTERVAL = 500; // half second resolution
public static volatile int counter = 0;

public static long lastRun;

static {
Expand All @@ -41,6 +43,7 @@ public void run() {
try {
Thread.sleep(INTERVAL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public RawRecordContainer getEvent() {

try {
event.setRawRecordNumber(getCurrentKey().get());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Unable to get current key", e);
} catch (Exception e) {
throw new RuntimeException("Unable to get current key", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public void setup(Context context) throws IOException, InterruptedException {
try {
contextWriter = contextWriterClass.getDeclaredConstructor().newInstance();
contextWriter.setup(filterConf, filterConf.getBoolean(CONTEXT_WRITER_OUTPUT_TABLE_COUNTERS, false));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
} catch (Exception e) {
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
}
Expand Down Expand Up @@ -480,7 +483,11 @@ public void map(K1 key, V1 value, Context context) throws IOException, Interrupt
NDC.push(origFiles.iterator().next());
reprocessedNDCPush = true;
}

} catch (InterruptedException e) {
contextWriter.rollback();
Thread.currentThread().interrupt();
log.error("Failed to clean event from error table. Terminating map", e);
throw new IOException("Failed to clean event from error table, Terminating map", e);
} catch (Exception e) {
contextWriter.rollback();
log.error("Failed to clean event from error table. Terminating map", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ public Collection<NormalizedContentInterface> apply(@Nullable Collection<Normali

try {
contextWriter.write(map, context);
} catch (IOException | InterruptedException e) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected void flushTokenOffsetCache(RawRecordContainer event, Multimap<BulkInge
log.fatal("IOException", ex);
} catch (InterruptedException ex) {
log.warn("Interrupted!", ex);
Thread.interrupted();
Thread.currentThread().interrupt();
}

tokenOffsetCache.clear();
Expand Down Expand Up @@ -303,6 +303,9 @@ protected Multimap<String,NormalizedContentInterface> getShardNamesAndValues(Raw
if (indexField || reverseIndexField) {
try {
tokenizeField(analyzer, nci, indexField, reverseIndexField, reporter);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RuntimeException(ex);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ public void close(TaskAttemptContext context) {
this.docWriterService.shutdown();
this.docWriterService.awaitTermination(1, TimeUnit.MINUTES);
this.docWriter.close();
} catch (InterruptedException | MutationsRejectedException e) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("Unable to terminate document writing service!", e);
} catch (MutationsRejectedException e) {
log.error("Unable to terminate document writing service!", e);
}
}
Expand Down Expand Up @@ -669,6 +672,7 @@ public void run() {
try {
Thread.sleep(INTERVAL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ public void run() {
try {
Thread.sleep(FAILURE_SLEEP_TIME);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
log.warn("Interrupted while sleeping.", ie);
}
}
Expand Down Expand Up @@ -822,6 +823,7 @@ public void bringMapFilesOnline(Path mapFilesDir) throws IOException, AccumuloEx
if (e == null)
e = importTask.getException();
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
// this task was interrupted, wait for the others and then terminate
if (e == null)
e = interrupted;
Expand All @@ -844,6 +846,7 @@ public void bringMapFilesOnline(Path mapFilesDir) throws IOException, AccumuloEx
if (e == null)
e = importTask.getException();
} catch (InterruptedException interrupted) {
Thread.currentThread().interrupt();
// this task was interrupted, wait for the others and then terminate
if (e == null)
e = interrupted;
Expand Down Expand Up @@ -1238,6 +1241,7 @@ public void markSourceFilesLoaded(Path jobDirectory) throws IOException {
}

} catch (InterruptedException e) {
Thread.currentThread().interrupt();
if (null != e.getCause())
throw new IOException(e.getCause().getMessage());
else
Expand Down Expand Up @@ -1320,6 +1324,7 @@ private void sleep() {
System.gc();
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("Interrupted while sleeping.", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public int run(String[] args) throws Exception {
try {
Thread.sleep(3000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
// do nothing
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public void flush(ConcurrentMap<String,AtomicLong> counts) {
byte[] countAsBytes = TextUtil.toUtf8(String.valueOf(entry.getValue().get()));
Key key = KeyConverter.fromString(entry.getKey());
contextWriter.write(new BulkIngestKey(table, key), new Value(countAsBytes), context);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Could not flush metrics, dropping them", e);
} catch (Exception e) {
logger.error("Could not flush metrics, dropping them", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void increase(String key, long count) {
Value v = (count == 1L && ONE != null) ? ONE : new Value(String.valueOf(count).getBytes(ENCODING));
Key k = KeyConverter.fromString(key);
contextWriter.write(new BulkIngestKey(table, k), v, context);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Could not write metrics to the context writer, dropping them...", e);
} catch (Exception e) {
logger.error("Could not write metrics to the context writer, dropping them...", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ protected void setupContextWriter(Configuration conf) throws IOException {
try {
setContextWriter(contextWriterClass.newInstance());
contextWriter.setup(conf, conf.getBoolean(CONTEXT_WRITER_OUTPUT_TABLE_COUNTERS, false));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
} catch (Exception e) {
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ protected void setupContextWriter(Configuration conf) throws IOException {
try {
setContextWriter(contextWriterClass.getDeclaredConstructor().newInstance());
contextWriter.setup(conf, conf.getBoolean(CONTEXT_WRITER_OUTPUT_TABLE_COUNTERS, false));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
} catch (Exception e) {
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public void setup(Configuration conf, boolean outputTableCounters) throws IOExce
try {
contextWriter = contextWriterClass.newInstance();
contextWriter.setup(conf, outputTableCounters);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + getChainedContextWriterOption(), e);
} catch (Exception e) {
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + getChainedContextWriterOption(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public void setup(Configuration conf, boolean outputTableCounters) throws IOExce
try {
contextWriter = contextWriterClass.getDeclaredConstructor().newInstance();
contextWriter.setup(conf, outputTableCounters);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
} catch (Exception e) {
throw new IOException("Failed to initialized " + contextWriterClass + " from property " + CONTEXT_WRITER_CLASS, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public void run() {
Job job = null;
try {
job = cluster.getJob(js.getJobID());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("Error getting job: " + js.getJobID() + " Reason: " + e.getMessage());
JOB_FAILED_COUNT.getAndIncrement();
return;
} catch (Exception e) {
System.out.println("Error getting job: " + js.getJobID() + " Reason: " + e.getMessage());
JOB_FAILED_COUNT.getAndIncrement();
Expand Down Expand Up @@ -82,6 +87,7 @@ public static void main(String[] args) throws IOException, InterruptedException
JOB_KILLER_SVC.shutdown(); // signal shutdown
JOB_KILLER_SVC.awaitTermination(1, TimeUnit.MINUTES); // allow processes to stop
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
JOB_KILLER_SVC.shutdownNow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static boolean shutdownAndWait(ThreadPoolExecutor executor, long timeToWa
executor.awaitTermination(timeToWait, unit);
return true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.warn("Closed thread pool but not all threads completed successfully.");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void run() {
} catch (Exception ex) {
log.error("An unexpected exception occurred. Exiting", ex);
running = false;
Thread.currentThread().interrupt();
}
}
} finally {
Expand Down Expand Up @@ -575,7 +576,10 @@ private boolean processResults(List<Future<InputFile>> futures, Collection<Input
if (fe != null && fe.isMoved()) {
entries.add(fe);
}
} catch (InterruptedException | ExecutionException ex) {
} catch (InterruptedException ex) {
ioex = new IOException("Failure during move", ex.getCause());
Thread.currentThread().interrupt();
} catch (ExecutionException ex) {
ioex = new IOException("Failure during move", ex.getCause());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void initializeTotalSize(final InputSplit genericSplit) throws IOExceptio
try {
totalSize = genericSplit.getLength() * 4l;
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted Exception thrown while attempting to get split length", ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ protected long tokenizeTextNode(String content, RawRecordContainer event, byte[]
getMetadata().addEvent(this.ingestHelper, event, normMap);
}

} catch (InterruptedException e) {
log.error("Error processing Wikipedia document", e);
Thread.currentThread().interrupt();
throw new RuntimeException("Error processing Wikipedia document", e);
} catch (Exception e) {
// If error, return empty results map.
log.error("Error processing Wikipedia document", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public int run(String[] args) throws Exception {
if ("errors".equals(type)) {
try {
launchErrorsJob(Job.getInstance(conf), conf);
} catch (InterruptedException e) {
log.info("Failed to launch errors job", e);
Thread.currentThread().interrupt();
} catch (Exception e) {
log.info("Failed to launch errors job", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public static void changeJobPriority(Job job, Logger log) throws IOException {
} else {
log.error("Hadoop process exited abnormally-- job may take a long time if system is saturated.");
}
} catch (InterruptedException e) {
log.error("This job was interrupted.", e);
Thread.currentThread().interrupt();
} catch (Exception e) {
log.error("This job may take a while on a system running at full ingest load.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ private void fillSortedSets() throws IOException {
} else {
try {
result = future.get();
} catch (InterruptedException e) {
exception = e;
result = e;
Thread.currentThread().interrupt();
} catch (Exception e) {
exception = e;
result = e;
Expand Down