Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 439D8D6FF for ; Wed, 13 Mar 2013 13:45:34 +0000 (UTC) Received: (qmail 25923 invoked by uid 500); 13 Mar 2013 13:45:34 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 25118 invoked by uid 500); 13 Mar 2013 13:45:32 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 24622 invoked by uid 99); 13 Mar 2013 13:45:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Mar 2013 13:45:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Mar 2013 13:45:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7F3BB23889D7; Wed, 13 Mar 2013 13:44:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1455938 - /jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDbTest.java Date: Wed, 13 Mar 2013 13:44:18 -0000 To: oak-commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130313134418.7F3BB23889D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: thomasm Date: Wed Mar 13 13:44:17 2013 New Revision: 1455938 URL: http://svn.apache.org/r1455938 Log: OAK-619 Lock-free MongoMK implementation (MongoDB test case to support efficient diff if there are many child nodes) Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDbTest.java Added: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDbTest.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDbTest.java?rev=1455938&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDbTest.java (added) +++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/MongoDbTest.java Wed Mar 13 13:44:17 2013 @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.mongomk.prototype; + +import org.apache.jackrabbit.mongomk.prototype.DocumentStore.Collection; +import org.junit.Ignore; +import org.junit.Test; + +import com.mongodb.BasicDBObject; +import com.mongodb.DB; +import com.mongodb.DBCollection; +import com.mongodb.DBCursor; +import com.mongodb.DBObject; +import com.mongodb.QueryBuilder; +import com.mongodb.WriteConcern; + +/** + * Test directly ran against MongoDB. + */ +public class MongoDbTest { + + @Test + @Ignore + public void manyChildNodes() { + DB db = MongoUtils.getConnection().getDB(); + MongoUtils.dropCollections(db); + DBCollection nodes = db.getCollection(Collection.NODES.toString()); + DBObject index = new BasicDBObject(); + // modification time (descending) + index.put("_mod", -1L); + // and then id (ascending) + index.put("_id", 1L); + DBObject options = new BasicDBObject(); + // options.put("unique", Boolean.TRUE); + nodes.ensureIndex(index, options); + + // index on (_id, _mod): + // Query plan: { "cursor" : "BtreeCursor _id_1__mod_-1" , + // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 , + // "nscanned" : 954647 , "nscannedObjectsAllPlans" : 1907080 , + // "nscannedAllPlans" : 2859727 , "scanAndOrder" : false , + // "indexOnly" : true , "nYields" : 5 , "nChunkSkips" : 0 , + // "millis" : 5112 ,... + // Time: 2229 ms + // Count: 2000 + + // index on (_mod, _id) + // Query plan: { "cursor" : "BtreeCursor _mod_-1__id_1" , + // "isMultiKey" : false , "n" : 2000 , "nscannedObjects" : 2000 , + // "nscanned" : 2000 , "nscannedObjectsAllPlans" : 2203 , + // "nscannedAllPlans" : 2203 , "scanAndOrder" : false , + // "indexOnly" : true , "nYields" : 0 , "nChunkSkips" : 0 , + // "millis" : 3 ,... + // Time: 43 ms + // Count: 2000 + + int children = 1000000; + int perInsert = 1000; + int group = 0; + String parent = "/parent/node/abc"; + for (int i = 0; i < children;) { + DBObject[] inserts = new DBObject[perInsert]; + group++; + for (int j = 0; j < perInsert; j++, i++) { + BasicDBObject doc = new BasicDBObject(); + inserts[j] = doc; + doc.put("_id", parent + "/node" + i); + doc.put("_mod", group); + } + nodes.insert(inserts, WriteConcern.SAFE); + log("inserted " + i + "/" + children); + } + QueryBuilder queryBuilder = QueryBuilder.start("_mod"); + queryBuilder.greaterThanEquals(group - 1); + queryBuilder.and("_id").greaterThan(parent + "/"); + queryBuilder.and("_id").lessThanEquals(parent + "0"); + DBObject query = queryBuilder.get(); + BasicDBObject keys = new BasicDBObject(); + keys.put("_id", 1); + DBCursor cursor = nodes.find(query, keys); + int count = 0; + log("Query plan: " + cursor.explain()); + long time = System.currentTimeMillis(); + while (cursor.hasNext()) { + DBObject obj = cursor.next(); + // dummy read operation (to ensure we did get the data) + obj.get("_id"); + count++; + // log(" read " + obj); + } + time = System.currentTimeMillis() - time; + log("Time: " + time + " ms"); + log("Count: " + count); + db.getMongo().close(); + } + + private static void log(String msg) { + System.out.println(msg); + } + +}