use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.
the class Main method main.
public static void main(String[] args) throws Exception {
try {
Console console = JCommander.getConsole();
ResourceBundle cliBundle = PropertyResourceBundle.getBundle("CliMessages");
final CliConfig cliConfig = new CliConfig();
JCommander jCommander = new JCommander(cliConfig, cliBundle, args);
jCommander.setColumnSize(Integer.MAX_VALUE);
if (cliConfig.isVersion()) {
BuildProperties buildProperties = new DefaultBuildProperties();
console.println(buildProperties.getFullVersion());
System.exit(0);
}
if (cliConfig.isHelp()) {
jCommander.usage();
System.exit(0);
}
if (cliConfig.isHelpParam()) {
console.println(cliBundle.getString("cli.help-param-header"));
ConfigUtils.printParamDescriptionFromConfigSchema(Config.class, cliBundle, console, 0);
System.exit(0);
}
cliConfig.addParams();
final Config config = CliConfigUtils.readConfig(cliConfig);
if (cliConfig.isPrintConfig()) {
ConfigUtils.printYamlConfig(config, console);
System.exit(0);
}
if (cliConfig.isPrintXmlConfig()) {
ConfigUtils.printXmlConfig(config, console);
System.exit(0);
}
if (cliConfig.isPrintParam()) {
JsonNode jsonNode = ConfigUtils.getParam(config, cliConfig.getPrintParamPath());
if (jsonNode != null) {
console.print(jsonNode.asText());
}
System.exit(0);
}
configureLogger(cliConfig, config);
config.getBackend().getBackendImplementation().accept(new BackendImplementationVisitor() {
@Override
public void visit(AbstractDerby value) {
parseToropassFile(value);
}
@Override
public void visit(AbstractPostgres value) {
parseToropassFile(value);
}
public void parseToropassFile(BackendPasswordConfig value) {
try {
ConfigUtils.parseToropassFile(value);
} catch (Exception ex) {
throw new SystemException(ex);
}
}
});
AbstractReplication replication = config.getReplication();
if (replication.getAuth().getUser() != null) {
HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
ConfigUtils.parseMongopassFile(new MongoPasswordConfig() {
@Override
public void setPassword(String password) {
replication.getAuth().setPassword(password);
}
@Override
public String getUser() {
return replication.getAuth().getUser();
}
@Override
public Integer getPort() {
return syncSource.getPort();
}
@Override
public String getPassword() {
return replication.getAuth().getPassword();
}
@Override
public String getMongopassFile() {
return config.getReplication().getMongopassFile();
}
@Override
public String getHost() {
return syncSource.getHostText();
}
@Override
public String getDatabase() {
return replication.getAuth().getSource();
}
});
}
if (config.getBackend().isLike(AbstractPostgres.class)) {
AbstractPostgres postgres = config.getBackend().as(AbstractPostgres.class);
if (cliConfig.isAskForPassword()) {
console.print("Type database user " + postgres.getUser() + "'s password:");
postgres.setPassword(readPwd());
}
if (postgres.getPassword() == null) {
throw new SystemException("No password provided for database user " + postgres.getUser() + ".\n\n" + "Please add following line to file " + postgres.getToropassFile() + ":\n" + postgres.getHost() + ":" + postgres.getPort() + ":" + postgres.getDatabase() + ":" + postgres.getUser() + ":<password>\n" + "Replace <password> for database user " + postgres.getUser() + "'s password");
}
}
try {
Clock clock = Clock.systemDefaultZone();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
@SuppressFBWarnings(value = "DM_EXIT", justification = "Since is really hard to stop cleanly all threads when an OOME is thrown we must " + "exit to avoid no more action is performed that could lead to an unespected " + "state")
public void uncaughtException(Thread t, Throwable e) {
if (e instanceof OutOfMemoryError) {
try {
LOGGER.error("Fatal out of memory: " + e.getLocalizedMessage(), e);
} finally {
System.exit(1);
}
}
}
});
Service stampedeService = StampedeBootstrap.createStampedeService(config, clock);
stampedeService.startAsync();
stampedeService.awaitTerminated();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
stampedeService.stopAsync();
stampedeService.awaitTerminated();
}));
} catch (CreationException ex) {
ex.getErrorMessages().stream().forEach(m -> {
if (m.getCause() != null) {
LOGGER.error(m.getCause().getMessage());
} else {
LOGGER.error(m.getMessage());
}
});
LogManager.shutdown();
System.exit(1);
}
} catch (Throwable ex) {
LOGGER.debug("Fatal error on initialization", ex);
Throwable rootCause = Throwables.getRootCause(ex);
String causeMessage = rootCause.getMessage();
LogManager.shutdown();
JCommander.getConsole().println("Fatal error while ToroDB was starting: " + causeMessage);
System.exit(1);
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.
the class SqlWriteTorodTransaction method dropIndex.
@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", justification = "Findbugs thinks MutableMetaCollection#removeMetaIndexByName" + "has no side effect")
@Override
public boolean dropIndex(String dbName, String colName, String indexName) {
MutableMetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
if (db == null) {
return false;
}
MutableMetaCollection col = db.getMetaCollectionByName(colName);
if (col == null) {
return false;
}
MetaIndex index = col.getMetaIndexByName(indexName);
if (index == null) {
return false;
}
col.removeMetaIndexByName(indexName);
getInternalTransaction().getBackendTransaction().dropIndex(db, col, index);
return true;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.
the class AbstractReadInterface method getCollectionResultSets.
@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a DocPartResult. It's iterated and closed in caller code")
public List<DocPartResult> getCollectionResultSets(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection, Collection<Integer> dids) throws SQLException {
ArrayList<DocPartResult> result = new ArrayList<>();
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
Iterator<? extends MetaDocPart> metaDocPartIterator = metaCollection.streamContainedMetaDocParts().sorted(TableRefComparator.MetaDocPart.DESC).iterator();
while (metaDocPartIterator.hasNext()) {
MetaDocPart metaDocPart = metaDocPartIterator.next();
String statament = getDocPartStatament(metaDatabase, metaDocPart, dids);
PreparedStatement preparedStatement = connection.prepareStatement(statament);
result.add(new ResultSetDocPartResult(metaDataReadInterface, dataTypeProvider, errorHandler, metaDocPart, preparedStatement.executeQuery(), sqlHelper));
}
} finally {
dsl.configuration().connectionProvider().release(connection);
}
return result;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.
the class AbstractReadInterface method getAllCollectionDids.
@Override
@SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code")
public Cursor<Integer> getAllCollectionDids(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCollection) throws SQLException {
MetaDocPart rootDocPart = metaCollection.getMetaDocPartByTableRef(tableRefFactory.createRoot());
if (rootDocPart == null) {
return new EmptyCursor<>();
}
String statement = getReadAllCollectionDidsStatement(metaDatabase.getIdentifier(), rootDocPart.getIdentifier());
Connection connection = dsl.configuration().connectionProvider().acquire();
try {
PreparedStatement preparedStatement = connection.prepareStatement(statement);
return new DefaultDidCursor(errorHandler, preparedStatement.executeQuery());
} finally {
dsl.configuration().connectionProvider().release(connection);
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.
the class MvccMetainfoRepository method startMerge.
@Override
@Nonnull
@SuppressFBWarnings(value = { "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "UL_UNRELEASED_LOCK" })
public MergerStage startMerge(MutableMetaSnapshot newSnapshot) throws UnmergeableException {
LOGGER.trace("Trying to create a {}", MvccMergerStage.class);
MergerStage mergeStage = null;
if (newSnapshot.hasChanged()) {
lock.writeLock().lock();
try {
mergeStage = new MvccMergerStage(newSnapshot, lock.writeLock());
LOGGER.trace("{} created", MvccMergerStage.class);
} finally {
if (mergeStage == null) {
LOGGER.error("Error while trying to create a {}", MvccMergerStage.class);
lock.writeLock().unlock();
}
}
} else {
mergeStage = noChangeMergeStage;
}
assert mergeStage != null;
return mergeStage;
}
Aggregations