Search in sources :

Example 6 with Document

use of org.apache.jackrabbit.oak.plugins.document.Document in project jackrabbit-oak by apache.

the class MongoDocumentStoreMetrics method getStats.

private CollectionStats getStats(Collection<? extends Document> c) throws MongoException {
    CollectionStats stats = new CollectionStats();
    BasicDBObject result = new BasicDBObject(db.runCommand(new org.bson.Document("collStats", c.toString())));
    stats.count = result.getLong("count", 0);
    stats.size = result.getLong("size", 0);
    stats.storageSize = result.getLong("storageSize", 0);
    stats.totalIndexSize = result.getLong("totalIndexSize", 0);
    return stats;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Document(org.apache.jackrabbit.oak.plugins.document.Document)

Example 7 with Document

use of org.apache.jackrabbit.oak.plugins.document.Document in project jackrabbit-oak by apache.

the class RDBDocumentStore method insertDocuments.

private <T extends Document> boolean insertDocuments(Collection<T> collection, List<T> documents) {
    Connection connection = null;
    RDBTableMetaData tmd = getTable(collection);
    try {
        connection = this.ch.getRWConnection();
        Set<String> insertedKeys = db.insert(connection, tmd, documents);
        connection.commit();
        return insertedKeys.size() == documents.size();
    } catch (SQLException ex) {
        this.ch.rollbackConnection(connection);
        List<String> ids = new ArrayList<String>();
        for (T doc : documents) {
            ids.add(doc.getId());
        }
        String message = String.format("insert of %s failed", ids);
        LOG.debug(message, ex);
        // collect additional exceptions
        String messages = LOG.isDebugEnabled() ? RDBJDBCTools.getAdditionalMessages(ex) : "";
        // see whether a DATA error was involved
        boolean dataRelated = false;
        SQLException walk = ex;
        while (walk != null && !dataRelated) {
            dataRelated = RDBJDBCTools.matchesSQLState(walk, "22", "72");
            walk = walk.getNextException();
        }
        if (dataRelated) {
            String id = null;
            int longest = 0, longestChars = 0;
            for (Document d : documents) {
                String data = ser.asString(d, tmd.getColumnOnlyProperties());
                byte[] bytes = asBytes(data);
                if (bytes.length > longest) {
                    longest = bytes.length;
                    longestChars = data.length();
                    id = d.getId();
                }
            }
            String m = String.format(" (potential cause: long data for ID %s - longest octet DATA size in Java characters: %d, in octets: %d, computed character limit: %d)", id, longest, longestChars, tmd.getDataLimitInOctets() / CHAR2OCTETRATIO);
            messages += m;
        }
        if (!messages.isEmpty()) {
            LOG.debug("additional diagnostics: " + messages);
        }
        throw handleException(message, ex, collection, ids);
    } finally {
        this.ch.closeConnection(connection);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Document(org.apache.jackrabbit.oak.plugins.document.Document)

Aggregations

Document (org.apache.jackrabbit.oak.plugins.document.Document)7 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)4 BasicDBObject (com.mongodb.BasicDBObject)3 ArrayList (java.util.ArrayList)3 Stopwatch (com.google.common.base.Stopwatch)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 MongoCollection (com.mongodb.client.MongoCollection)2 List (java.util.List)2 Collection (org.apache.jackrabbit.oak.plugins.document.Collection)2 Test (org.junit.Test)2 Function (com.google.common.base.Function)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Predicates.in (com.google.common.base.Predicates.in)1 Predicates.not (com.google.common.base.Predicates.not)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Iterables.filter (com.google.common.collect.Iterables.filter)1 Iterators (com.google.common.collect.Iterators)1