@Override public void run() { for (OIndex index : database.getMetadata().getIndexManager().getIndexes()) { if (!canCheck(index)) { continue; } checkIndex(index); } message("Total errors found on indexes: " + getTotalErrors()); }
private void checkCluster(int clusterId, OIndex index, List<String> fields) { long totRecordsForCluster = database.countClusterElements(clusterId); String clusterName = database.getClusterNameById(clusterId); int TOT_STEPS = 20; message("Checking cluster " + clusterName + " for index " + index.getName()+"\n"); ORecordIteratorCluster<ORecord> iter = database.browseCluster(clusterName); long count = 0; long step = -1; while (iter.hasNext()) { long currentStep = count * 20 / totRecordsForCluster; if (currentStep > step) { printProgress(clusterName, clusterId, (int) currentStep, TOT_STEPS); step = currentStep; } ORecord record = iter.next(); if (record instanceof ODocument) { ODocument doc = (ODocument) record; checkThatRecordIsIndexed(doc, index, fields); } count++; } printProgress(clusterName, clusterId, TOT_STEPS, TOT_STEPS); message("\n"); }
@ConsoleCommand(description = "Check database integrity", splitInWords = false) public void checkDatabase(@ConsoleParameter(name = "options", description = "Options: -v", optional = true) final String iOptions) throws IOException { checkForDatabase(); if (!(currentDatabase.getStorage() instanceof OAbstractPaginatedStorage)) { message("\nCannot check integrity of non-local database. Connect to it using local mode."); return; } boolean verbose = iOptions != null && iOptions.contains("-v"); message("\nChecking storage."); try { ((OAbstractPaginatedStorage) currentDatabase.getStorage()).check(verbose, this); } catch (ODatabaseImportException e) { printError(e); } message("\nChecking indexes.\n"); OCheckIndexTool indexTool = new OCheckIndexTool(); indexTool.setDatabase(currentDatabase); indexTool.setOutputListener(this); indexTool.setVerbose(true); indexTool.run(); }
void printProgress(String clusterName, int clusterId, int step, int totSteps) { StringBuilder msg = new StringBuilder(); msg.append("\rcluster " + clusterName + " (" + clusterId + ") |"); for (int i = 0; i < totSteps; i++) { if (i < step) { msg.append("*"); } else { msg.append(" "); } } msg.append("| "); msg.append(step * 100 / totSteps); msg.append("%%"); message(msg.toString()); }
private void checkIndex(OIndex index) { List<String> fields = index.getDefinition().getFields(); String className = index.getDefinition().getClassName(); OClass clazz = database.getMetadata().getSchema().getClass(className); int[] clusterIds = clazz.getPolymorphicClusterIds(); for (int clusterId : clusterIds) { checkCluster(clusterId, index, fields); } }