forked from NationalSecurityAgency/datawave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the query option tserver.logging.active to enable logging of query IDs to the TServer logs. Created the class QueryLogIterator to handle this. Logs the start and end of each method called. Fixes NationalSecurityAgency#2305
- Loading branch information
1 parent
c5a0f3a
commit aab6f6b
Showing
7 changed files
with
394 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
warehouse/query-core/src/main/java/datawave/query/iterator/QueryLogIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package datawave.query.iterator; | ||
|
||
import static datawave.query.iterator.QueryOptions.QUERY_ID; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.accumulo.core.data.ByteSequence; | ||
import org.apache.accumulo.core.data.Key; | ||
import org.apache.accumulo.core.data.Range; | ||
import org.apache.accumulo.core.data.Value; | ||
import org.apache.accumulo.core.iterators.IteratorEnvironment; | ||
import org.apache.accumulo.core.iterators.OptionDescriber; | ||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator; | ||
import org.apache.log4j.Logger; | ||
|
||
public class QueryLogIterator implements SortedKeyValueIterator<Key,Value>, OptionDescriber { | ||
|
||
private static final Logger log = Logger.getLogger(QueryLogIterator.class); | ||
|
||
private static final String CLASS_NAME = QueryLogIterator.class.getSimpleName(); | ||
private String queryID; | ||
private SortedKeyValueIterator<Key,Value> source; | ||
private IteratorEnvironment myEnvironment; | ||
|
||
public QueryLogIterator() {} | ||
|
||
public QueryLogIterator(QueryLogIterator other, IteratorEnvironment env) { | ||
this.myEnvironment = other.myEnvironment; | ||
this.queryID = other.queryID; | ||
} | ||
|
||
@Override | ||
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { | ||
|
||
try { | ||
this.queryID = options.get(QUERY_ID); | ||
this.source = source; | ||
this.myEnvironment = env; | ||
logStartOf("init()"); | ||
} finally { | ||
logEndOf("init()"); | ||
} | ||
} | ||
|
||
private void logStartOf(String methodName) { | ||
if (log.isInfoEnabled()) { | ||
log.info(CLASS_NAME + " " + methodName + " Started QueryID: " + this.queryID); | ||
} | ||
} | ||
|
||
private void logEndOf(String methodName) { | ||
if (log.isInfoEnabled()) { | ||
log.info(CLASS_NAME + " " + methodName + " Ended QueryID: " + this.queryID); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasTop() { | ||
|
||
boolean result; | ||
|
||
try { | ||
logStartOf("hasTop()"); | ||
result = source.hasTop(); | ||
} finally { | ||
logEndOf("hasTop()"); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void next() throws IOException { | ||
try { | ||
logStartOf("next()"); | ||
source.next(); | ||
} finally { | ||
logEndOf("next()"); | ||
} | ||
} | ||
|
||
@Override | ||
public Key getTopKey() { | ||
Key k; | ||
try { | ||
logStartOf("getTopKey()"); | ||
k = source.getTopKey(); | ||
} finally { | ||
logEndOf("getTopKey()"); | ||
} | ||
return k; | ||
} | ||
|
||
@Override | ||
public Value getTopValue() { | ||
Value v; | ||
try { | ||
logStartOf("getTopValue()"); | ||
v = source.getTopValue(); | ||
} finally { | ||
logEndOf("getTopValue()"); | ||
} | ||
return v; | ||
} | ||
|
||
@Override | ||
public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment iteratorEnvironment) { | ||
|
||
QueryLogIterator copy; | ||
|
||
try { | ||
logStartOf("deepCopy()"); | ||
copy = new QueryLogIterator(this, this.myEnvironment); | ||
} finally { | ||
logEndOf("deepCopy()"); | ||
} | ||
return copy; | ||
} | ||
|
||
@Override | ||
public void seek(Range range, Collection<ByteSequence> collection, boolean b) throws IOException { | ||
|
||
try { | ||
logStartOf("seek()"); | ||
this.source.seek(range, collection, b); | ||
} finally { | ||
logEndOf("seek()"); | ||
} | ||
} | ||
|
||
@Override | ||
public IteratorOptions describeOptions() { | ||
Map<String,String> options = new HashMap<>(); | ||
options.put(QUERY_ID, "The QueryID to be logged as methods are invoked"); | ||
|
||
return new IteratorOptions(getClass().getSimpleName(), "An iterator used to log the QueryID", options, null); | ||
} | ||
|
||
@Override | ||
public boolean validateOptions(Map<String,String> options) { | ||
return options.containsKey(QUERY_ID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
warehouse/query-core/src/main/java/datawave/query/iterator/SourcedOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.