Skip to content

Commit ea9090e

Browse files
committed
Removed redundant iterator constructors
Signed-off-by: Laurent Klock <Laurent.Klock@arhs-cube.com>
1 parent 92466f6 commit ea9090e

File tree

5 files changed

+23
-62
lines changed

5 files changed

+23
-62
lines changed

service/src/main/java/crawlercommons/urlfrontier/service/AbstractFrontierService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,9 @@ public void listURLs(
936936
responseObserver.onCompleted();
937937
}
938938

939-
protected abstract Iterator<URLItem> urlIterator(
940-
Entry<QueueWithinCrawl, QueueInterface> qentry);
939+
protected Iterator<URLItem> urlIterator(Entry<QueueWithinCrawl, QueueInterface> qentry) {
940+
return urlIterator(qentry, 0L, Long.MAX_VALUE);
941+
}
941942

942943
protected abstract Iterator<URLItem> urlIterator(
943944
Entry<QueueWithinCrawl, QueueInterface> qentry, long start, long max);

service/src/main/java/crawlercommons/urlfrontier/service/ignite/IgniteService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,4 @@ protected Iterator<URLItem> urlIterator(
863863
java.util.Map.Entry<QueueWithinCrawl, QueueInterface> qentry, long start, long max) {
864864
throw new UnsupportedOperationException("Feature not implemented for Ignite backend");
865865
}
866-
867-
@Override
868-
// TODO Implementation of listURLs for Ignite
869-
protected Iterator<URLItem> urlIterator(
870-
java.util.Map.Entry<QueueWithinCrawl, QueueInterface> qentry) {
871-
throw new UnsupportedOperationException("Feature not implemented for Ignite backend");
872-
}
873866
}

service/src/main/java/crawlercommons/urlfrontier/service/memory/MemoryFrontierService.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,15 @@ public Iterator<URLItem> urlIterator(
227227
return new MemoryURLItemIterator(qentry, start, maxURLs);
228228
}
229229

230-
public Iterator<URLItem> urlIterator(Entry<QueueWithinCrawl, QueueInterface> qentry) {
231-
return new MemoryURLItemIterator(qentry);
232-
}
233-
234230
class MemoryURLItemIterator implements Iterator<URLItem> {
235231

236232
private final org.slf4j.Logger LOG = LoggerFactory.getLogger(MemoryURLItemIterator.class);
237233

238234
private final Entry<QueueWithinCrawl, QueueInterface> qentry;
239235
private final long start;
240236
private final long maxURLs;
241-
private int pos = 0;
242-
private int sent = 0;
237+
private long pos = 0;
238+
private long sent = 0;
243239
private URLItem.Builder builder = URLItem.newBuilder();
244240
private KnownURLItem.Builder knownBuilder = KnownURLItem.newBuilder();
245241
private Iterator<InternalURL> iter;
@@ -254,14 +250,6 @@ public MemoryURLItemIterator(
254250
iterCompleted = ((URLQueue) qentry.getValue()).getCompleted().iterator();
255251
}
256252

257-
public MemoryURLItemIterator(Entry<QueueWithinCrawl, QueueInterface> qentry) {
258-
this.qentry = qentry;
259-
this.start = 0;
260-
this.maxURLs = Long.MAX_VALUE;
261-
iter = ((URLQueue) qentry.getValue()).iterator();
262-
iterCompleted = ((URLQueue) qentry.getValue()).getCompleted().iterator();
263-
}
264-
265253
@Override
266254
public boolean hasNext() {
267255
return sent < maxURLs && (iterCompleted.hasNext() || iter.hasNext());

service/src/main/java/crawlercommons/urlfrontier/service/rocksdb/RocksDBService.java

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -861,17 +861,13 @@ public Iterator<URLItem> urlIterator(
861861
return new RocksDBURLItemIterator(qentry, start, maxURLs);
862862
}
863863

864-
public Iterator<URLItem> urlIterator(Entry<QueueWithinCrawl, QueueInterface> qentry) {
865-
return new RocksDBURLItemIterator(qentry);
866-
}
867-
868864
class RocksDBURLItemIterator implements Iterator<URLItem> {
869865

870866
private final org.slf4j.Logger LOG = LoggerFactory.getLogger(RocksDBURLItemIterator.class);
871867

872868
private final long maxURLs;
873-
private int pos = 0;
874-
private int sent = 0;
869+
private long pos = 0;
870+
private long sent = 0;
875871
private URLItem.Builder builder = URLItem.newBuilder();
876872
private KnownURLItem.Builder knownBuilder = KnownURLItem.newBuilder();
877873

@@ -885,45 +881,35 @@ public RocksDBURLItemIterator(
885881

886882
this.queueID = qentry.getKey();
887883
this.prefixKey = (queueID.toString() + "_").getBytes(StandardCharsets.UTF_8);
888-
this.maxURLs = (int) maxURLs;
884+
this.maxURLs = maxURLs;
889885
this.builder = URLItem.newBuilder();
890886
this.knownBuilder = KnownURLItem.newBuilder();
891887

892888
this.rocksIterator = rocksDB.newIterator(columnFamilyHandleList.get(0));
893889
this.rocksIterator.seek(prefixKey);
894890

895-
// advance to the start position
896-
while (rocksIterator.isValid() && pos < start) {
891+
if (rocksIterator.isValid() && start == 0L) {
892+
// Check if we're not past the seeked queue
897893
final String currentKey = new String(rocksIterator.key(), StandardCharsets.UTF_8);
898894
final QueueWithinCrawl Qkey = QueueWithinCrawl.parseAndDeNormalise(currentKey);
899895

900896
if (!queueID.equals(Qkey.getCrawlid(), Qkey.getQueue())) {
901897
hasNext = false;
902-
break;
898+
return;
903899
}
904-
rocksIterator.next();
905-
pos++;
906-
}
907-
}
908-
909-
public RocksDBURLItemIterator(Entry<QueueWithinCrawl, QueueInterface> qentry) {
910-
911-
this.queueID = qentry.getKey();
912-
this.prefixKey = (queueID.toString() + "_").getBytes(StandardCharsets.UTF_8);
913-
this.maxURLs = Long.MAX_VALUE;
914-
this.builder = URLItem.newBuilder();
915-
this.knownBuilder = KnownURLItem.newBuilder();
916-
917-
this.rocksIterator = rocksDB.newIterator(columnFamilyHandleList.get(0));
918-
this.rocksIterator.seek(prefixKey);
919-
920-
if (rocksIterator.isValid()) {
921-
// Check if we're not past the seeked queue
922-
final String currentKey = new String(rocksIterator.key(), StandardCharsets.UTF_8);
923-
final QueueWithinCrawl Qkey = QueueWithinCrawl.parseAndDeNormalise(currentKey);
900+
} else {
901+
// advance to the start position
902+
while (rocksIterator.isValid() && pos < start) {
903+
final String currentKey =
904+
new String(rocksIterator.key(), StandardCharsets.UTF_8);
905+
final QueueWithinCrawl Qkey = QueueWithinCrawl.parseAndDeNormalise(currentKey);
924906

925-
if (!queueID.equals(Qkey.getCrawlid(), Qkey.getQueue())) {
926-
hasNext = false;
907+
if (!queueID.equals(Qkey.getCrawlid(), Qkey.getQueue())) {
908+
hasNext = false;
909+
break;
910+
}
911+
rocksIterator.next();
912+
pos++;
927913
}
928914
}
929915
}

service/src/main/java/crawlercommons/urlfrontier/service/rocksdb/ShardedRocksDBService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,4 @@ protected Iterator<URLItem> urlIterator(
106106
throw new UnsupportedOperationException(
107107
"Feature not implemented for ShardedRocksDB backend");
108108
}
109-
110-
@Override
111-
// TODO Implementation of urlIterator for ShardedRocksDB
112-
protected Iterator<URLItem> urlIterator(Entry<QueueWithinCrawl, QueueInterface> qentry) {
113-
throw new UnsupportedOperationException(
114-
"Feature not implemented for ShardedRocksDB backend");
115-
}
116109
}

0 commit comments

Comments
 (0)