use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class RDBDocumentStore method deleteWithCondition.
private <T extends Document> int deleteWithCondition(Collection<T> collection, List<QueryCondition> conditions) {
int numDeleted = 0;
RDBTableMetaData tmd = getTable(collection);
Stopwatch watch = startWatch();
Connection connection = null;
try {
connection = this.ch.getRWConnection();
numDeleted = db.deleteWithCondition(connection, tmd, conditions);
connection.commit();
} catch (Exception ex) {
throw DocumentStoreException.convert(ex, "deleting " + collection + ": " + conditions);
} finally {
this.ch.closeConnection(connection);
stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, numDeleted);
}
return numDeleted;
}
use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class RDBDocumentStore method delete.
private <T extends Document> int delete(Collection<T> collection, Map<String, Map<Key, Condition>> toRemove) {
int numDeleted = 0;
RDBTableMetaData tmd = getTable(collection);
Map<String, Map<Key, Condition>> subMap = Maps.newHashMap();
Iterator<Entry<String, Map<Key, Condition>>> it = toRemove.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Map<Key, Condition>> entry = it.next();
subMap.put(entry.getKey(), entry.getValue());
if (subMap.size() == 64 || !it.hasNext()) {
Connection connection = null;
int num = 0;
Stopwatch watch = startWatch();
try {
connection = this.ch.getRWConnection();
num = db.delete(connection, tmd, subMap);
numDeleted += num;
connection.commit();
} catch (Exception ex) {
Set<String> ids = subMap.keySet();
throw handleException("deleting " + ids, ex, collection, ids);
} finally {
this.ch.closeConnection(connection);
stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, num);
}
subMap.clear();
}
}
return numDeleted;
}
use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class RDBDocumentStore method delete.
private <T extends Document> int delete(Collection<T> collection, List<String> ids) {
int numDeleted = 0;
RDBTableMetaData tmd = getTable(collection);
for (List<String> sublist : Lists.partition(ids, 64)) {
Connection connection = null;
Stopwatch watch = startWatch();
try {
connection = this.ch.getRWConnection();
numDeleted += db.delete(connection, tmd, sublist);
connection.commit();
} catch (Exception ex) {
throw handleException("removing " + ids, ex, collection, ids);
} finally {
this.ch.closeConnection(connection);
stats.doneRemove(watch.elapsed(TimeUnit.NANOSECONDS), collection, ids.size());
}
}
return numDeleted;
}
use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class RDBDocumentStore method internalUpdate.
@CheckForNull
private <T extends Document> void internalUpdate(Collection<T> collection, List<String> ids, UpdateOp update) {
if (isAppendableUpdate(update, true) && !requiresPreviousState(update)) {
Operation modOperation = update.getChanges().get(MODIFIEDKEY);
long modified = getModifiedFromOperation(modOperation);
boolean modifiedIsConditional = modOperation == null || modOperation.type != UpdateOp.Operation.Type.SET;
String appendData = ser.asString(update);
for (List<String> chunkedIds : Lists.partition(ids, CHUNKSIZE)) {
if (collection == Collection.NODES) {
for (String key : chunkedIds) {
nodesCache.invalidate(key);
}
}
Connection connection = null;
RDBTableMetaData tmd = getTable(collection);
boolean success = false;
try {
Stopwatch watch = startWatch();
connection = this.ch.getRWConnection();
success = db.batchedAppendingUpdate(connection, tmd, chunkedIds, modified, modifiedIsConditional, appendData);
connection.commit();
//Internally 'db' would make multiple calls and number of those
//remote calls would not be captured
stats.doneUpdate(watch.elapsed(TimeUnit.NANOSECONDS), collection, chunkedIds.size());
} catch (SQLException ex) {
success = false;
this.ch.rollbackConnection(connection);
} finally {
this.ch.closeConnection(connection);
}
if (success) {
if (collection == Collection.NODES) {
for (String id : chunkedIds) {
nodesCache.invalidate(id);
}
}
} else {
for (String id : chunkedIds) {
UpdateOp up = update.copy();
up = up.shallowCopy(id);
internalCreateOrUpdate(collection, up, false, true);
}
}
}
} else {
Stopwatch watch = startWatch();
for (String id : ids) {
UpdateOp up = update.copy();
up = up.shallowCopy(id);
internalCreateOrUpdate(collection, up, false, true);
}
stats.doneUpdate(watch.elapsed(TimeUnit.NANOSECONDS), collection, ids.size());
}
}
use of com.google.common.base.Stopwatch in project jackrabbit-oak by apache.
the class JournalGarbageCollector method gc.
/**
* Deletes entries in the journal that are older than the given
* maxRevisionAge.
*
* @param maxRevisionAge entries older than this age will be removed
* @param unit the {@linkplain TimeUnit} for maxRevisionAge
* @return the number of entries that have been removed
*/
public int gc(long maxRevisionAge, TimeUnit unit) {
DocumentStore ds = ns.getDocumentStore();
Revision keep = ns.getCheckpoints().getOldestRevisionToKeep();
long maxRevisionAgeInMillis = unit.toMillis(maxRevisionAge);
long now = ns.getClock().getTime();
long gcOlderThan = now - maxRevisionAgeInMillis;
if (keep != null && keep.getTimestamp() < gcOlderThan) {
gcOlderThan = keep.getTimestamp();
log.debug("gc: Checkpoint {} is older than maxRevisionAge: {} min", keep, unit.toMinutes(maxRevisionAge));
}
if (log.isDebugEnabled()) {
log.debug("gc: Journal garbage collection starts with maxAge: {} min.", TimeUnit.MILLISECONDS.toMinutes(maxRevisionAgeInMillis));
}
Stopwatch sw = Stopwatch.createStarted();
// update the tail timestamp in the journalGC document
// of the settings collection
updateTailTimestamp(gcOlderThan);
int numDeleted = ds.remove(Collection.JOURNAL, JournalEntry.MODIFIED, 0, gcOlderThan);
sw.stop();
if (numDeleted > 0) {
log.info("gc: Journal garbage collection took {}, deleted {} entries that were older than {} min.", sw, numDeleted, TimeUnit.MILLISECONDS.toMinutes(now - gcOlderThan));
}
return numDeleted;
}
Aggregations