static void ai_compactLiveDB(bool withPhase2) { new ai_compactLiveDB_Class c; c.phase1(); if (!withPhase2) ret; print("PHASE 2 in 5 SECONDS"); sleepSeconds(5); c.phase2(); } sclass ai_compactLiveDB_Class { File mainLog, fTriples, file, file2; void phase1() ctex { // First, rotate webs-made.txt mainLog = programFile(#1010745, "webs-made.txt"); rotateLogFile(mainLog); File tripelizedDir = programDir(#1010745, "tripelized"); fTriples = programFile(#1010745, "triples.gz"); // Save triples file = new File(tripelizedDir, "triples.new.gz"); OutputStream out = newGZIPOutputStream(file); int n = ai_writeTripleFile(ai_allTriples(), out); out.close(); // Save non-triples (don't have any) file2 = new File(tripelizedDir, "webs-made.new.gz"); deleteFile(file2); print("Stored " + nTriple(n) + " in " + f2s(file) + ", nothing in " + f2s(file2)); } void phase2 { print("PHASE 2."); // Move data to backups File fBackups = programFile(#1010745, "backups"); for (File f : earlierPartsOfLogFile(mainLog)) { int n = 1; File p; while ((p = newFile(fBackups, dropSuffix(".gz", f.getName()) + ".part" + n + ".gz")).exists()) ++n; renameFile_assertTrue(f, p); } // Backup triples.gz int n = 1; File p; while ((p = newFile(fBackups, dropSuffix(".gz", fTriples.getName()) + ".part" + n + ".gz")).exists()) ++n; renameFile_assertTrue(fTriples, p); // Rename main files renameFile_assertTrue(file, fTriples); if (file2.exists()) renameFile_assertTrue(file2, programFile(#1010745, "webs-made.txt.part1.gz")); print("DONE."); } }