Skip to content
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 @@ -19,7 +19,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -321,34 +320,10 @@ public boolean updateAll(
return false;
}

// Drop each of tables that need to be updated
Savepoint sp = cd.setSavepoint("court update savepoint");
Map<String, List<String>> rawVersionsToUpdate = cd.getVersionsToUpdate();
Map<String, List<String>> versionsToUpdate =
makeOrRemoveUnsupportedTables(rawVersionsToUpdate, cd);
Instant startDel = Instant.now();
log.info(
"Removing {} court entries, over {} queries",
versionsToUpdate.size(),
versionsToUpdate.values().stream().map(List::size).reduce(0, (a, b) -> a + b));
for (Entry<String, List<String>> courtAndTables : versionsToUpdate.entrySet()) {
final String courtLocation = courtAndTables.getKey();
List<String> tables = courtAndTables.getValue();
log.debug(
"In {},\nremoving entries for court {} for tables: {}",
cd.getJurisdiction(),
courtLocation,
tables);
for (String table : tables) {
Instant delTime = Instant.now();

// Will ignore tables that don't exist.
cd.deleteFromTable(table, courtLocation);

updateDuration = updateDuration.plus(Duration.between(delTime, Instant.now()));
}
}
log.info("Took {} to remove existing tables", Duration.between(startDel, Instant.now()));
Instant startPolicy = Instant.now();
Map<String, List<CourtCodelistInfo>> policies =
streamPolicies(
Expand All @@ -360,6 +335,12 @@ public boolean updateAll(
for (var policy : policies.entrySet()) {
final String courtLocation = policy.getKey();
final List<String> tables = versionsToUpdate.get(courtLocation);
// Delete right before reloading, so the delete, the new rows, and the new installedversion
// commit together. Readers never see a court's old version with its rows missing.
for (String table : tables) {
// Will ignore tables that don't exist.
cd.deleteFromTable(table, courtLocation);
}
if (!downloadCourtTables(
courtLocation, Optional.of(tables), cd, urlGetter, policy.getValue())) {
log.warn("Failed updating court {}'s tables {}", courtLocation, tables);
Expand All @@ -384,6 +365,10 @@ public boolean replaceAll(
CodeUrlGetter urlGetter,
CodeDatabaseAPI cd)
throws SQLException, IOException, JAXBException, URISyntaxException {
cd.setAutoCommit(false);
// All tables for all courts are about to be emptied; drop all versions too.
// Each court gets its version back when it reloads.
cd.deleteFromTable("installedversion");
return replaceSome(systemUrls, codeInfoGetter, urlGetter, cd, List.of());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ public static boolean executeCommand(
if (command.equalsIgnoreCase("replaceall")) {
return cu.replaceAll(systemUrls, codelistGetter, codeUrlGetter, cd);
} else if (command.equalsIgnoreCase("replacesome")) {
return cu.replaceSome(
systemUrls, codelistGetter, codeUrlGetter, cd, args.subList(1, args.size()));
var someLocations = args.subList(1, args.size());
if (someLocations.isEmpty()) {
log.error("Need to provide args of locations to replace (gave none)");
return false;
}
return cu.replaceSome(systemUrls, codelistGetter, codeUrlGetter, cd, someLocations);
} else if (command.equalsIgnoreCase("refresh")) {
return cu.updateAll(systemUrls, codelistGetter, codeUrlGetter, cd);
} else {
Expand All @@ -161,7 +165,7 @@ public static boolean executeCommand(
*/
public static void main(String[] args) throws Exception {
if (args.length < 1) {
log.error("Need to pass in a subprogram: downloadIndiv, or refresh");
log.error("Need to pass in a subprogram: downloadIndiv, refresh, replacesome, replaceall");
System.exit(1);
}

Expand Down
Loading