cshannon commented on code in PR #3332:
URL: https://github.com/apache/accumulo/pull/3332#discussion_r1180538903
##########
core/src/main/java/org/apache/accumulo/core/file/rfile/RFile.java:
##########
@@ -1553,4 +1556,117 @@ public void setCacheProvider(CacheProvider
cacheProvider) {
reader.setCacheProvider(cacheProvider);
}
}
+
+ interface IndexedFileSKVIterator extends FileSKVIterator {
+ FileSKVIterator getIndex() throws IOException;
+ }
+
+ static class FencedReader implements IndexedFileSKVIterator {
+
+ private final Reader reader;
+ private final Range fence;
+
+ public FencedReader(Reader reader, Range seekFence) {
+ this.reader = Objects.requireNonNull(reader);
+ this.fence = seekFence;
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies,
boolean inclusive)
+ throws IOException {
+ reader.clear();
+
+ if (fence != null) {
+ range = fence.clip(range, true);
+ if (range == null) {
+ return;
+ }
+ }
+
+ reader.seek(range, columnFamilies, inclusive);
+ }
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source,
Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasTop() {
+ return reader.hasTop();
+ }
+
+ @Override
+ public void next() throws IOException {
+ reader.next();
+ }
+
+ @Override
+ public Key getTopKey() {
+ return reader.getTopKey();
+ }
+
+ @Override
+ public Value getTopValue() {
+ return reader.getTopValue();
+ }
+
+ @Override
+ public FencedReader deepCopy(IteratorEnvironment env) {
+ return new FencedReader(reader.deepCopy(env), fence);
+ }
+
+ @Override
+ public boolean isRunningLowOnMemory() {
+ return reader.isRunningLowOnMemory();
+ }
+
+ @Override
+ public void setInterruptFlag(AtomicBoolean flag) {
+ reader.setInterruptFlag(flag);
+ }
+
+ @Override
+ public Key getFirstKey() throws IOException {
+ return fence.isInfiniteStartKey() ? reader.getFirstKey() :
fence.getStartKey();
+ }
+
+ @Override
+ public Key getLastKey() throws IOException {
+ return fence.isInfiniteStopKey() ? reader.getLastKey() :
fence.getEndKey();
+ }
Review Comment:
> Even when the fence range is not infinite, the first and last keys of the
underlying file may still fall within the fence range. If so then those should
be returned.
I guess I was thinking a fence shouldn't or wouldn't be created that extends
outside the file but this would be a good thing to check either way. I'm not
sure if we need or want to do some validation when creating a Fence to make
sure it's valid but we probably don't really need to care as long as the
underlying code is smart enough to realize the fence boundary is larger than
the file and handle it as you pointed out here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]