You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2015/07/09 07:26:46 UTC

svn commit: r1689987 - /jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js

Author: chetanm
Date: Thu Jul  9 05:26:45 2015
New Revision: 1689987

URL: http://svn.apache.org/r1689987
Log:
OAK-3086 - [oak-mongo.js] Generate mongoexport command to get a slice of oplog entries

Applying patch from Vikas Saurabh

Modified:
    jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js

Modified: jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js?rev=1689987&r1=1689986&r2=1689987&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/js/oak-mongo.js Thu Jul  9 05:26:45 2015
@@ -588,6 +588,47 @@ var oak = (function(global){
         return mongoExportCommand;
     };
 
+    /**
+     * Prints mongoexport command to export oplog entries around time represented by revision.
+     * e.g.
+     * > oak.printOplogSliceCommand("r14e64620028-0-1", {db: "aem-author"})
+     * Note, this assumed that time on mongo instance is synchronized with time on oak instance. If that's
+     * not the case, then adjust revStr to account for the difference.
+     *
+     * @memberof oak
+     * @method printOplogSliceCommand
+     * @param {string} revStr revision string around which oplog is to be exported.
+     * @param {object} options pass optional parameters for host, port, db, filename, oplogTimeBuffer
+     * @returns {string} command line which can be used to export oplog entries using mongoexport
+     */
+
+    api.printOplogSliceCommand = function (revStr, options) {
+        options = options || {};
+        var host = options.host || "127.0.0.1";
+        var port = options.port || "27017";
+        var db = options.db || "oak";
+        var filename = options.filename || "oplog.json";
+        var oplogTimeBuffer = options.oplogTimeBuffer || 10;
+
+        var rev = new Revision(revStr);
+        var revTimeInSec = rev.asDate().getTime()/1000;
+        var startOplogTime = Math.floor(revTimeInSec - oplogTimeBuffer);
+        var endOplogTime = Math.ceil(revTimeInSec + oplogTimeBuffer);
+
+        var query = '{"ns" : "' + db + '.nodes", "ts": {"$gte": Timestamp(' + startOplogTime
+                                                + ', 1), "$lte": Timestamp(' + endOplogTime + ', 1)}}';
+
+        var mongoExportCommand = "mongoexport"
+                                    + " --host " + host
+                                    + " --port " + port
+                                    + " --db local"
+                                    + " --collection oplog.rs"
+                                    + " --out " + filename
+                                    + " --query '" + query + "'";
+
+        return mongoExportCommand;
+    };
+
     //~--------------------------------------------------< internal >
 
     var checkOrFixDeepHistory = function(path, fix, prepare, verbose) {
@@ -970,4 +1011,4 @@ var oak = (function(global){
     };
 
     return api;
-}(this));
\ No newline at end of file
+}(this));