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
createDatabaseIfNotExists throws "org.ektorp.DbAccessException: A database with path X already exists" #159
Comments
Additional info about dependencies:
|
Do you create databases on the fly? |
The databases are all existing already and the exception is happening really randomly. I'm executing similar actions on a bunch of databases of this type where only the dbName is changed. But those are all fresh instances that are sharing the same CouchDbInstance. Executing those actions multiple times results in the exception above with different dbNames. Databases that worked on a previous run would suddenly throw the exception and vice versa. The code initializing our repository looks like this: private void setCouchDbInstance(CouchDbInstance couchDbInstance)
{
this.couchDbInstance = couchDbInstance;
StdCouchDbConnector db = new StdCouchDbConnector(dbName, couchDbInstance, new ResourceObjectMapperFactory());
repo=new StringListCouchDbRepository(db);
}
private static class ResourceObjectMapperFactory
implements ObjectMapperFactory
{
public ObjectMapper createObjectMapper()
{
ObjectMapper result = new ObjectMapper();
result.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
result.setDateFormat(new ISO8601DateFormat());
result.registerModule(new StringListModule());
result.registerModule(new AfterburnerModule());
return result;
}
public ObjectMapper createObjectMapper(CouchDbConnector connector)
{
return createObjectMapper();
}
} And the configuration of the CouchDbInstance looks like this: <bean name="couchDb" class="org.ektorp.impl.StdCouchDbInstance">
<constructor-arg>
<bean class="org.ektorp.spring.HttpClientFactoryBean" p:username="xxx" p:password="yyy" p:port="5984">
<property name="host" value="zzz"/>
<property name="autoUpdateViewOnChange" value="true"/>
</bean>
</constructor-arg>
</bean> I suspect that our CouchDB was barfing under heavy load and returned some error (probably 500) which is interpreted as "does not exist" in public boolean checkIfDbExists(DbPath db) {
return restTemplate.head(db.getPath(), new StdResponseHandler<Boolean>() {
@Override
public Boolean error(HttpResponse hr) {
return false;
}
@Override
public Boolean success(HttpResponse hr) throws Exception {
return true;
}
});
} I'd suggest throwing a |
I can confirm that the couchdb is returning 500 in those cases (for unrelated reasons). This causes checkIfDbExists(..) to erroneously return false. |
I've sent #186 to fix this. The tests are working (after fixing mock assumptions according to the new implementation) but I didn't check it against a real CouchDB since I don't know if/how I could do that in your build. Let me know if anything is wrong. |
This happens pretty random and I suspect that the database is under load...
Using ektorp 1.4.1 with couchdb 1.5.0.
Code looks like this:
The text was updated successfully, but these errors were encountered: