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

Refactor Trough client URL cache put. Limit TroughContentDigestHistor… #395

Merged
merged 1 commit into from
May 28, 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 @@ -197,7 +197,7 @@ public void load(CrawlURI curi) {
}
if(!memoryDedupHit) {
try {
String sql = "select * from dedup where digest_key = %s";
String sql = "select * from dedup where digest_key = %s limit 1";
List<Map<String, Object>> results = troughClient().read(getSegmentId(), sql, new String[]{persistKeyFor(curi)});
if (!results.isEmpty()) {
Map<String, Object> hist = new HashMap<String, Object>();
Expand Down
33 changes: 28 additions & 5 deletions contrib/src/main/java/org/archive/trough/TroughClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,20 @@ public List<Map<String, Object>> read(String segmentId, String sqlTmpl, Object[]

protected String readUrl(String segmentId) throws TroughException {
if (readUrlCache.get(segmentId) == null) {
String url = readUrlNoCache(segmentId);
readUrlCache.put(segmentId, url);
try {
readUrlCache.computeIfAbsent(segmentId, k -> {
try {
return readUrlNoCache(k);
} catch (TroughException e) {
throw new RuntimeException(e);
}
});
}
catch(RuntimeException e) {
if(e.getCause() instanceof TroughException){
throw (TroughException)e.getCause();
}
}
logger.info("segment " + segmentId + " read url is " + readUrlCache.get(segmentId));
}
return readUrlCache.get(segmentId);
Expand Down Expand Up @@ -379,9 +391,20 @@ public void write(String segmentId, String sqlTmpl, Object[] values, String sche

protected String writeUrl(String segmentId, String schemaId) throws IOException {
if (writeUrlCache.get(segmentId) == null) {
String url = writeUrlNoCache(segmentId, schemaId);
writeUrlCache.put(segmentId, url);

try {
writeUrlCache.computeIfAbsent(segmentId, k -> {
try {
return writeUrlNoCache(k, schemaId);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
catch(RuntimeException e) {
if(e.getCause() instanceof IOException){
throw (IOException)e.getCause();
}
}
logger.info("segment " + segmentId + " write url is " + writeUrlCache.get(segmentId));
}
return writeUrlCache.get(segmentId);
Expand Down