Example usage for com.mongodb Bytes QUERYOPTION_OPLOGREPLAY

List of usage examples for com.mongodb Bytes QUERYOPTION_OPLOGREPLAY

Introduction

In this page you can find the example usage for com.mongodb Bytes QUERYOPTION_OPLOGREPLAY.

Prototype

int QUERYOPTION_OPLOGREPLAY

To view the source code for com.mongodb Bytes QUERYOPTION_OPLOGREPLAY.

Click Source Link

Document

Internal replication use only - driver should not set

Usage

From source file:com.edgytech.umongo.MongoUtils.java

License:Apache License

public static String queryOptionsToString(int options) {
    String opt = "";
    if ((options & Bytes.QUERYOPTION_TAILABLE) != 0) {
        opt += "TAILABLE ";
    }//  ww w  .j  ava 2s.  c  om
    if ((options & Bytes.QUERYOPTION_SLAVEOK) != 0) {
        opt += "SLAVEOK ";
    }
    if ((options & Bytes.QUERYOPTION_OPLOGREPLAY) != 0) {
        opt += "OPLOGREPLAY ";
    }
    if ((options & Bytes.QUERYOPTION_NOTIMEOUT) != 0) {
        opt += "NOTIMEOUT ";
    }
    if ((options & Bytes.QUERYOPTION_AWAITDATA) != 0) {
        opt += "AWAITDATA ";
    }
    if ((options & Bytes.QUERYOPTION_EXHAUST) != 0) {
        opt += "EXHAUST ";
    }
    return opt;
}

From source file:com.edgytech.umongo.OptionDialog.java

License:Apache License

void update(int options, WriteConcern wc, ReadPreference rp) {
    // reset/* ww w. j  a  v  a  2 s. com*/
    xmlLoadCheckpoint();

    setBooleanFieldValue(Item.tailable, (options & Bytes.QUERYOPTION_TAILABLE) != 0);
    setBooleanFieldValue(Item.slaveOk, (options & Bytes.QUERYOPTION_SLAVEOK) != 0);
    setBooleanFieldValue(Item.opLogReplay, (options & Bytes.QUERYOPTION_OPLOGREPLAY) != 0);
    setBooleanFieldValue(Item.noTimeout, (options & Bytes.QUERYOPTION_NOTIMEOUT) != 0);
    setBooleanFieldValue(Item.awaitData, (options & Bytes.QUERYOPTION_AWAITDATA) != 0);
    setBooleanFieldValue(Item.exhaust, (options & Bytes.QUERYOPTION_EXHAUST) != 0);
    setBooleanFieldValue(Item.partial, (options & Bytes.QUERYOPTION_PARTIAL) != 0);

    Object w = wc.getWObject();
    int wInt = (Integer) (w instanceof Integer ? w : 0);
    String wStr = (String) (w instanceof String ? w : "");
    setIntFieldValue(Item.writeFactor, wInt);
    setStringFieldValue(Item.writePolicy, wStr);
    setIntFieldValue(Item.writeTimeout, wc.getWtimeout());
    //        setBooleanFieldValue(Item.fsync, wc.fsync());

    DBObject rpObj = rp.toDBObject();
    ComboBox readBox = (ComboBox) getBoundUnit(Item.rpPreference);
    ReadPref rpEnm = ReadPref.primary;
    if (rp != null)
        rpEnm = ReadPref.valueOf(rp.getName());
    readBox.value = rpEnm.ordinal();
    if (rpObj.containsField("tags")) {
        List tags = (List) rpObj.get("tags");
        if (tags.size() > 0) {
            ((DocBuilderField) getBoundComponentUnit(Item.rpTag)).setDBObject((DBObject) tags.get(0));
        }
    }
}

From source file:com.edgytech.umongo.OptionDialog.java

License:Apache License

int getQueryOptions() {
    int options = 0;
    if (getBooleanFieldValue(Item.tailable))
        options |= Bytes.QUERYOPTION_TAILABLE;
    if (getBooleanFieldValue(Item.slaveOk))
        options |= Bytes.QUERYOPTION_SLAVEOK;
    if (getBooleanFieldValue(Item.opLogReplay))
        options |= Bytes.QUERYOPTION_OPLOGREPLAY;
    if (getBooleanFieldValue(Item.noTimeout))
        options |= Bytes.QUERYOPTION_NOTIMEOUT;
    if (getBooleanFieldValue(Item.awaitData))
        options |= Bytes.QUERYOPTION_AWAITDATA;
    if (getBooleanFieldValue(Item.exhaust))
        options |= Bytes.QUERYOPTION_EXHAUST;
    if (getBooleanFieldValue(Item.partial))
        options |= Bytes.QUERYOPTION_PARTIAL;
    return options;
}

From source file:com.edgytech.umongo.ReplSetPanel.java

License:Apache License

public void queryOplog(ButtonBase button) {
    final DBCollection oplog = getReplSetNode().getMongoClient().getDB("local").getCollection("oplog.rs");
    DBObject start = ((DocBuilderField) getBoundUnit(Item.qoStart)).getDBObject();
    DBObject end = ((DocBuilderField) getBoundUnit(Item.qoEnd)).getDBObject();
    DBObject extra = ((DocBuilderField) getBoundUnit(Item.qoQuery)).getDBObject();

    BasicDBObject query = new BasicDBObject();
    BasicDBObject range = new BasicDBObject();
    if (start != null)
        range.put("$gte", start.get("ts"));
    if (end != null)
        range.put("$lte", end.get("ts"));

    query.put("ts", range);
    if (extra != null)
        query.putAll(extra);//from   w  ww  . ja va  2 s.  c o  m

    CollectionPanel.doFind(oplog, query, null, null, 0, 0, 0, false, null, Bytes.QUERYOPTION_OPLOGREPLAY);
}

From source file:com.wordnik.system.mongodb.OplogTailThread.java

License:Open Source License

public void run() {
    running = true;/*  w w  w  .  ja  v  a2s  .  c o  m*/
    BSONTimestamp lastTimestamp = null;
    try {
        lastTimestamp = getLastTimestamp();

        long lastWrite = 0;
        long startTime = System.currentTimeMillis();
        long lastOutput = System.currentTimeMillis();
        while (true) {
            try {
                if (killMe) {
                    System.out.println("exiting thread");
                    return;
                }
                DBCursor cursor = null;
                oplog.setDBDecoderFactory(OplogDecoder.FACTORY);
                if (lastTimestamp != null) {
                    cursor = oplog.find(new BasicDBObject("ts", new BasicDBObject("$gt", lastTimestamp)));
                    cursor.addOption(Bytes.QUERYOPTION_OPLOGREPLAY);
                } else {
                    cursor = oplog.find();
                }
                cursor.addOption(Bytes.QUERYOPTION_TAILABLE);
                cursor.addOption(Bytes.QUERYOPTION_AWAITDATA);
                long count = 0;
                long skips = 0;

                while (!killMe && cursor.hasNext()) {
                    DBObject x = cursor.next();
                    if (!killMe) {
                        lastTimestamp = (BSONTimestamp) x.get("ts");
                        if (shouldWrite(x)) {
                            processor.processRecord((BasicDBObject) x);
                            count++;
                        } else {
                            skips++;
                        }
                        if (System.currentTimeMillis() - lastWrite > 1000) {
                            writeLastTimestamp(lastTimestamp);
                            lastWrite = System.currentTimeMillis();
                        }
                        long duration = System.currentTimeMillis() - lastOutput;
                        if (duration > reportInterval) {
                            report(this.getName(), count, skips, System.currentTimeMillis() - startTime);
                            lastOutput = System.currentTimeMillis();
                        }
                    }
                }
            } catch (com.mongodb.MongoException.CursorNotFound ex) {
                writeLastTimestamp(lastTimestamp);
                System.out.println("Cursor not found, waiting");
                Thread.sleep(2000);
            } catch (com.mongodb.MongoInternalException ex) {
                System.out.println("Cursor not found, waiting");
                writeLastTimestamp(lastTimestamp);
                ex.printStackTrace();
            } catch (com.mongodb.MongoException ex) {
                writeLastTimestamp(lastTimestamp);
                //   System.out.println("Internal exception, waiting");
                ex.printStackTrace();
                Thread.sleep(2000);
            } catch (Exception ex) {
                killMe = true;
                writeLastTimestamp(lastTimestamp);
                ex.printStackTrace();
                break;
            }
        }
        Thread.sleep(1000);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        writeLastTimestamp(lastTimestamp);
        try {
            processor.close("oplog");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    running = false;
}

From source file:org.mule.module.mongo.tools.IncrementalOplogDump.java

License:Open Source License

private void dump(String outputDirectory, String database) throws IOException {
    Validate.notNull(outputDirectory);/*from  w w  w .  j a va  2  s .c  om*/
    Validate.notNull(database);

    String incrementalFilePath = incrementalTimestampFile != null ? incrementalTimestampFile
            : outputDirectory + File.separator + INCREMENTAL_LAST_TIMESTAMP;
    BSONTimestamp lastTimestamp = getLastTimestamp(incrementalFilePath);

    DBCollection oplogCollection = new OplogCollection(dbs.get(BackupConstants.ADMIN_DB),
            dbs.get(BackupConstants.LOCAL_DB)).getOplogCollection();
    DBCursor oplogCursor;
    if (lastTimestamp != null) {
        DBObject query = new BasicDBObject();
        query.put(BackupConstants.TIMESTAMP_FIELD, new BasicDBObject("$gt", lastTimestamp));
        // Filter only oplogs for given database
        query.put(BackupConstants.NAMESPACE_FIELD, BackupUtils.getNamespacePattern(database));

        oplogCursor = oplogCollection.find(query);
        oplogCursor.addOption(Bytes.QUERYOPTION_OPLOGREPLAY);
    } else {
        oplogCursor = oplogCollection.find();
    }

    DumpWriter dumpWriter = new BsonDumpWriter(outputDirectory);
    String oplogCollectionTimestamp = BackupConstants.OPLOG + appendTimestamp();

    try {
        while (oplogCursor.hasNext()) {
            DBObject oplogEntry = oplogCursor.next();
            lastTimestamp = (BSONTimestamp) oplogEntry.get("ts");

            dumpWriter.writeObject(oplogCollectionTimestamp, oplogEntry);
        }
    } finally {
        writeLastTimestamp(incrementalFilePath, lastTimestamp);
    }
}

From source file:org.mule.module.mongo.tools.MongoDump.java

License:Open Source License

public void dump(final String outputDirectory, final String database, String outputName, final int threads)
        throws IOException {
    Validate.notNull(outputDirectory);//from   w w  w.  ja v  a 2s  .com
    Validate.notNull(outputName);
    Validate.notNull(database);

    String opName = outputName;
    opName += appendTimestamp();

    initOplog(database);

    final Collection<String> collections = mongoClient.listCollections();
    if (collections != null) {
        final ExecutorService executor = Executors.newFixedThreadPool(threads);
        final DumpWriter dumpWriter = new BsonDumpWriter(outputDirectory, opName);
        for (final String collectionName : collections) {
            final DBCollection dbCollection = mongoClient.getCollection(collectionName);
            final MongoDumpCollection dumpCollection = new MongoDumpCollection(dbCollection);
            dumpCollection.setDumpWriter(dumpWriter);

            final Future<Void> future = executor.submit(dumpCollection);
            propagateException(future);
        }

        executor.shutdown();
        try {
            if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
                executor.shutdownNow();
            }

            if (oplog) {
                final ExecutorService singleExecutor = Executors.newSingleThreadExecutor();
                final MongoDumpCollection dumpCollection = new MongoDumpCollection(oplogCollection);
                dumpCollection.setName(BackupConstants.OPLOG);
                dumpCollection.addOption(Bytes.QUERYOPTION_OPLOGREPLAY);
                dumpCollection.addOption(Bytes.QUERYOPTION_SLAVEOK);
                final DBObject query = new BasicDBObject();
                query.put(BackupConstants.TIMESTAMP_FIELD, new BasicDBObject("$gt", oplogStart));
                // Filter only oplogs for given database
                query.put(BackupConstants.NAMESPACE_FIELD, BackupUtils.getNamespacePattern(database));
                dumpCollection.setQuery(query);
                dumpCollection.setDumpWriter(dumpWriter);
                final Future<Void> future = singleExecutor.submit(dumpCollection);
                propagateException(future);
            }

            if (zip) {
                final String dbDumpPath = outputDirectory + File.separator + opName;
                ZipUtils.zipDirectory(dbDumpPath);
                FileUtils.deleteDirectory(new File(dbDumpPath));
            }
        } catch (final InterruptedException ie) {
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        }
    }
}