use of org.apache.jackrabbit.oak.plugins.document.DocumentStoreException in project jackrabbit-oak by apache.
the class RDBDataSourceFactory method forJdbcUrl.
public static DataSource forJdbcUrl(String url, String username, String passwd, String driverName) {
// load driver class when specified
if (driverName != null && !driverName.isEmpty()) {
LOG.info("trying to load {}", driverName);
try {
Class.forName(driverName);
} catch (ClassNotFoundException ex) {
LOG.error("driver " + driverName + " not loaded", ex);
}
} else {
// try to determine driver from JDBC URL
String defaultDriver = RDBJDBCTools.driverForDBType(RDBJDBCTools.jdbctype(url));
if (defaultDriver != null && !defaultDriver.isEmpty()) {
LOG.info("trying to load {}", defaultDriver);
try {
Class.forName(defaultDriver);
} catch (ClassNotFoundException ex) {
LOG.error("driver " + defaultDriver + " not loaded", ex);
}
}
}
try {
LOG.debug("Getting driver for " + url);
Driver d = DriverManager.getDriver(url);
String classname = "org.apache.tomcat.jdbc.pool.DataSource";
try {
Class<?> dsclazz = Class.forName(classname);
DataSource ds = (DataSource) dsclazz.newInstance();
dsclazz.getMethod("setDriverClassName", String.class).invoke(ds, d.getClass().getName());
dsclazz.getMethod("setUsername", String.class).invoke(ds, username);
dsclazz.getMethod("setPassword", String.class).invoke(ds, passwd);
dsclazz.getMethod("setUrl", String.class).invoke(ds, url);
String interceptors = System.getProperty("org.apache.jackrabbit.oak.plugins.document.rdb.RDBDataSourceFactory.jdbcInterceptors", "SlowQueryReport(threshold=10000);ConnectionState;StatementCache");
if (!interceptors.isEmpty()) {
dsclazz.getMethod("setJdbcInterceptors", String.class).invoke(ds, interceptors);
}
return new CloseableDataSource(ds);
} catch (Exception ex) {
String message = "trying to create datasource " + classname;
LOG.info(message, ex);
throw new DocumentStoreException(message, ex);
}
} catch (SQLException ex) {
String message = "trying to obtain driver for " + url;
LOG.info(message, ex);
throw new DocumentStoreException(message, ex);
}
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStoreException in project jackrabbit-oak by apache.
the class RDBDocumentSerializer method asString.
/**
* Serializes the changes in the {@link UpdateOp} into a JSON array; each
* entry is another JSON array holding operation, key, revision, and value.
*/
public String asString(UpdateOp update) {
StringBuilder sb = new StringBuilder("[");
boolean needComma = false;
for (Map.Entry<Key, Operation> change : update.getChanges().entrySet()) {
Operation op = change.getValue();
Key key = change.getKey();
// exclude properties that are serialized into special columns
if (columnProperties.contains(key.getName()) && null == key.getRevision())
continue;
if (needComma) {
sb.append(",");
}
sb.append("[");
if (op.type == UpdateOp.Operation.Type.INCREMENT) {
sb.append("\"+\",");
} else if (op.type == UpdateOp.Operation.Type.SET || op.type == UpdateOp.Operation.Type.SET_MAP_ENTRY) {
sb.append("\"=\",");
} else if (op.type == UpdateOp.Operation.Type.MAX) {
sb.append("\"M\",");
} else if (op.type == UpdateOp.Operation.Type.REMOVE || op.type == UpdateOp.Operation.Type.REMOVE_MAP_ENTRY) {
sb.append("\"*\",");
} else {
throw new DocumentStoreException("Can't serialize " + update.toString() + " for JSON append");
}
appendJsonString(sb, key.getName());
sb.append(",");
Revision rev = key.getRevision();
if (rev != null) {
appendJsonString(sb, rev.toString());
sb.append(",");
}
appendJsonValue(sb, op.value);
sb.append("]");
needComma = true;
}
return sb.append("]").toString();
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStoreException in project jackrabbit-oak by apache.
the class RDBVersionGCSupport method getOldestDeletedOnceTimestamp.
@Override
public long getOldestDeletedOnceTimestamp(Clock clock, long precisionMs) {
long modifiedMs = Long.MIN_VALUE;
LOG.debug("getOldestDeletedOnceTimestamp() <- start");
try {
modifiedMs = store.getMinValue(Collection.NODES, NodeDocument.MODIFIED_IN_SECS, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, Collections.singletonList(new QueryCondition(NodeDocument.DELETED_ONCE, "=", 1)));
} catch (DocumentStoreException ex) {
LOG.debug("getMinValue(MODIFIED)", ex);
}
if (modifiedMs > 0) {
LOG.debug("getOldestDeletedOnceTimestamp() -> {}", Utils.timestampToString(modifiedMs));
return modifiedMs;
} else {
LOG.debug("getOldestDeletedOnceTimestamp() -> none found, return current time");
return clock.getTime();
}
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStoreException in project jackrabbit-oak by apache.
the class MongoDocumentStore method queryInternal.
@SuppressWarnings("unchecked")
@Nonnull
<T extends Document> List<T> queryInternal(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit, long maxQueryTime) {
log("query", fromKey, toKey, indexedProperty, startValue, limit);
DBCollection dbCollection = getDBCollection(collection);
QueryBuilder queryBuilder = QueryBuilder.start(Document.ID);
queryBuilder.greaterThan(fromKey);
queryBuilder.lessThan(toKey);
DBObject hint = new BasicDBObject(NodeDocument.ID, 1);
if (indexedProperty != null) {
if (NodeDocument.DELETED_ONCE.equals(indexedProperty)) {
if (startValue != 1) {
throw new DocumentStoreException("unsupported value for property " + NodeDocument.DELETED_ONCE);
}
queryBuilder.and(indexedProperty);
queryBuilder.is(true);
} else {
queryBuilder.and(indexedProperty);
queryBuilder.greaterThanEquals(startValue);
if (NodeDocument.MODIFIED_IN_SECS.equals(indexedProperty) && canUseModifiedTimeIdx(startValue)) {
hint = new BasicDBObject(NodeDocument.MODIFIED_IN_SECS, -1);
}
}
}
DBObject query = queryBuilder.get();
String parentId = Utils.getParentIdFromLowerLimit(fromKey);
long lockTime = -1;
final Stopwatch watch = startWatch();
boolean isSlaveOk = false;
int resultSize = 0;
CacheChangesTracker cacheChangesTracker = null;
if (parentId != null && collection == Collection.NODES) {
cacheChangesTracker = nodesCache.registerTracker(fromKey, toKey);
}
try {
DBCursor cursor = dbCollection.find(query).sort(BY_ID_ASC);
if (!disableIndexHint && !hasModifiedIdCompoundIndex) {
cursor.hint(hint);
}
if (maxQueryTime > 0) {
// OAK-2614: set maxTime if maxQueryTimeMS > 0
cursor.maxTime(maxQueryTime, TimeUnit.MILLISECONDS);
}
ReadPreference readPreference = getMongoReadPreference(collection, parentId, null, getDefaultReadPreference(collection));
if (readPreference.isSlaveOk()) {
isSlaveOk = true;
LOG.trace("Routing call to secondary for fetching children from [{}] to [{}]", fromKey, toKey);
}
cursor.setReadPreference(readPreference);
List<T> list;
try {
list = new ArrayList<T>();
for (int i = 0; i < limit && cursor.hasNext(); i++) {
DBObject o = cursor.next();
T doc = convertFromDBObject(collection, o);
list.add(doc);
}
resultSize = list.size();
} finally {
cursor.close();
}
if (cacheChangesTracker != null) {
nodesCache.putNonConflictingDocs(cacheChangesTracker, (List<NodeDocument>) list);
}
return list;
} finally {
if (cacheChangesTracker != null) {
cacheChangesTracker.close();
}
stats.doneQuery(watch.elapsed(TimeUnit.NANOSECONDS), collection, fromKey, toKey, indexedProperty != null, resultSize, lockTime, isSlaveOk);
}
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStoreException in project jackrabbit-oak by apache.
the class RetryReadIT method retry.
@Test
public void retry() {
// must survive two consecutive failures. -> 2 retries
store.failRead = 2;
NodeDocument doc = store.find(NODES, Utils.getIdFromPath("/foo"));
assertNull(doc);
// previous result is cached and will not fail
store.failRead = 3;
doc = store.find(NODES, Utils.getIdFromPath("/foo"));
assertNull(doc);
// must fail with three consecutive failures on unknown path
try {
store.find(NODES, Utils.getIdFromPath("/bar"));
fail("must fail with DocumentStoreException");
} catch (DocumentStoreException e) {
// expected
}
}
Aggregations