Search in sources :

Example 66 with Stopwatch

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;
}
Also used : Stopwatch(com.google.common.base.Stopwatch) Connection(java.sql.Connection) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 67 with Stopwatch

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;
}
Also used : Condition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition) RDBJDBCTools.closeResultSet(org.apache.jackrabbit.oak.plugins.document.rdb.RDBJDBCTools.closeResultSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) HashSet(java.util.HashSet) Connection(java.sql.Connection) Stopwatch(com.google.common.base.Stopwatch) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Entry(java.util.Map.Entry) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key)

Example 68 with Stopwatch

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;
}
Also used : Connection(java.sql.Connection) Stopwatch(com.google.common.base.Stopwatch) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 69 with Stopwatch

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());
    }
}
Also used : SQLException(java.sql.SQLException) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) Connection(java.sql.Connection) Stopwatch(com.google.common.base.Stopwatch) Operation(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation) CheckForNull(javax.annotation.CheckForNull)

Example 70 with Stopwatch

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;
}
Also used : Stopwatch(com.google.common.base.Stopwatch)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)314 IOException (java.io.IOException)81 ArrayList (java.util.ArrayList)29 ExecutionException (java.util.concurrent.ExecutionException)28 File (java.io.File)19 Map (java.util.Map)18 Test (org.junit.Test)18 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)15 HashMap (java.util.HashMap)14 Path (org.apache.hadoop.fs.Path)14 List (java.util.List)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)11 DBCollection (com.mongodb.DBCollection)9 ISE (io.druid.java.util.common.ISE)9 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)8 OptionsParser (com.google.devtools.common.options.OptionsParser)8 MongoException (com.mongodb.MongoException)8 Connection (java.sql.Connection)8 CountDownLatch (java.util.concurrent.CountDownLatch)8