List of usage examples for com.mongodb WriteConcern FSYNC_SAFE
WriteConcern FSYNC_SAFE
To view the source code for com.mongodb WriteConcern FSYNC_SAFE.
Click Source Link
Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk.
This field has been superseded by WriteConcern.FSYNCED , and may be deprecated in a future release.
From source file:ch.agent.crnickl.mongodb.MongoDB.java
License:Apache License
private WriteConcern getWriteConcernFromKeyword(String keyword) throws T2DBException { WriteConcern wc = null;//from w w w.j ava2s . c o m if (keyword == null) keyword = "SAFE"; WriteConcernKeyword k = null; try { k = WriteConcernKeyword.valueOf(keyword); } catch (IllegalArgumentException e) { throw T2DBMMsg.exception(e, J.J81020, keyword); } switch (k) { case NONE: wc = WriteConcern.NONE; break; case NORMAL: wc = WriteConcern.NORMAL; break; case SAFE: wc = WriteConcern.SAFE; break; case MAJORITY: wc = WriteConcern.MAJORITY; break; case FSYNC_SAFE: wc = WriteConcern.FSYNC_SAFE; break; case JOURNAL_SAFE: wc = WriteConcern.JOURNAL_SAFE; break; case REPLICAS_SAFE: wc = WriteConcern.REPLICAS_SAFE; break; default: throw new RuntimeException("bug: " + k.name()); } if (wc != WriteConcern.SAFE) throw T2DBMMsg.exception(J.J81021, keyword); return wc; }
From source file:com.andreig.jetty.MongoDB.java
License:GNU General Public License
public static Mongo get() { if (db == null) { try {// w ww . j a v a 2 s. co m List<ServerAddress> addrs = str2addresses(Config.mongo_servers); MongoOptions opts = new MongoOptions(); opts.autoConnectRetry = true; int thrno = Config.server_threadsno; if (thrno < 100) opts.connectionsPerHost = thrno; else opts.connectionsPerHost = 100; opts.threadsAllowedToBlockForConnectionMultiplier = 10; opts.maxWaitTime = 10000; // millisecs db = new Mongo(addrs, opts); write_concern = Config.mongo_safeoperations ? WriteConcern.FSYNC_SAFE : WriteConcern.NORMAL; log.info("getDB():" + db); } catch (UnknownHostException e) { log.severe("Bad host " + e); db = null; } } return db; }
From source file:com.cyslab.craftvm.rest.mongo.MongoDB.java
License:GNU General Public License
public static Mongo get() { if (db == null) { try {/* ww w .j av a 2s. c o m*/ List<ServerAddress> addrs = str2addresses(Config.mongo_servers); MongoOptions opts = new MongoOptions(); opts.autoConnectRetry = true; int thrno = Config.server_threadsno; if (thrno < 100) opts.connectionsPerHost = thrno; else opts.connectionsPerHost = 100; opts.threadsAllowedToBlockForConnectionMultiplier = 10; opts.maxWaitTime = 10000; // millisecs db = new Mongo(addrs, opts); write_concern = Config.mongo_safeoperations ? WriteConcern.FSYNC_SAFE : WriteConcern.NORMAL; log.info("getDB():" + db); } catch (UnknownHostException e) { log.error("Bad host " + e); db = null; } } return db; }
From source file:com.linuxbox.enkive.audit.mongodb.MongoAuditService.java
License:Open Source License
public MongoAuditService(Mongo mongo, DBCollection collection) { this.mongo = mongo; this.auditCollection = collection; // see comments on def'n of CALL_ENSURE_INDEX_ON_INIT to see why it's // done conditionally if (CALL_ENSURE_INDEX_ON_INIT) { // see class com.linuxbox.enkive.MongoDBIndexManager }/* w ww .ja v a2 s. com*/ // TODO: do we (will we) need a who, what, when index, so we can select // by who/what and sort by when? if (CONFIRM_AUDIT_LOG_WRITES) { auditCollection.setWriteConcern(WriteConcern.FSYNC_SAFE); } else { auditCollection.setWriteConcern(WriteConcern.NORMAL); } final int indexCount = auditCollection.getIndexInfo().size(); // we expect 4 -- our 3 plus the default index on ObjectID if (indexCount > 4) { if (LOGGER.isWarnEnabled()) LOGGER.warn( "the MongoAuditService may have extra indices (which could impact performance); expect 4 but have " + indexCount); } }
From source file:com.linuxbox.enkive.docstore.mongogrid.MongoGridDocStoreService.java
License:Open Source License
public MongoGridDocStoreService(GridFS gridFS, DBCollection collection) { this.gridFS = gridFS; this.filesCollection = collection; // see comments on def'n of CALL_ENSURE_INDEX_ON_INIT to see why it's // done conditionally if (CALL_ENSURE_INDEX_ON_INIT) { // see class com.linuxbox.enkive.MongoDBIndexManager }/*from w w w .j a va 2 s .co m*/ // insure data is written to disk this.filesCollection.setWriteConcern(WriteConcern.FSYNC_SAFE); }
From source file:com.linuxbox.util.lockservice.mongodb.MongoLockService.java
License:Open Source License
public MongoLockService(Mongo mongo, DBCollection collection) { this.mongo = mongo; this.lockCollection = collection; lockCollection.setWriteConcern(WriteConcern.FSYNC_SAFE); // see comments on def'n of CALL_ENSURE_INDEX_ON_INIT to see why it's // done conditionally if (CALL_ENSURE_INDEX_ON_INIT) { // see class com.linuxbox.enkive.MongoDBIndexManager }/*from w ww .jav a 2s. co m*/ }
From source file:com.linuxbox.util.queueservice.mongodb.MongoQueueService.java
License:Open Source License
public MongoQueueService(Mongo mongo, DBCollection collection) { this.mongo = mongo; this.queueCollection = collection; // see comments on def'n of CALL_ENSURE_INDEX_ON_INIT to see why it's // done conditionally if (CALL_ENSURE_INDEX_ON_INIT) { // see class com.linuxbox.enkive.MongoDBIndexManager }/*from w ww . ja v a 2s .c o m*/ // Make sure data is written out to disk before operation is complete. queueCollection.setWriteConcern(WriteConcern.FSYNC_SAFE); }
From source file:com.softwear.plugins.mongodb.MongoDBScriptObject.java
License:BSD License
public WriteConcern js_getMongoWriteConcern(String _type) { WriteConcern wc = WriteConcern.UNACKNOWLEDGED; if (_type.equals("none") || _type.equals("unacknowledge")) { wc = WriteConcern.UNACKNOWLEDGED; } else if (_type.equals("normal")) { wc = WriteConcern.NORMAL;//ww w .ja va2 s . c om } else if (_type.equals("safe")) { wc = WriteConcern.SAFE; } else if (_type.equals("replicas_safe")) { wc = WriteConcern.REPLICAS_SAFE; } else if (_type.equals("fsync_safe")) { wc = WriteConcern.FSYNC_SAFE; } return wc; }
From source file:de.fhg.igd.mongomvcc.impl.internal.Tree.java
License:Open Source License
/** * Adds a named branch. Always waits for the database to fsync before * returning. This guarantees all threads will see the change. * @param name the branch's name//from w w w . j a va 2 s .com * @param headCID the CID of the head commit the branch points to * @throws VException if there already is a branch with the given name or * if the given head CID could not be resolved to an existing commit */ public void addBranch(String name, long headCID) { //synchronize here, because we first check for branch existence //and then we write synchronized (this) { //check prerequisites if (_branches.findOne(name) != null) { throw new VException("A branch with the name " + name + " already exists"); } resolveCommit(headCID); //create branch DBObject o = new BasicDBObject(); o.put(MongoDBConstants.ID, name); o.put(MongoDBConstants.CID, headCID); o.put(ROOT_CID, headCID); _branches.insert(o, WriteConcern.FSYNC_SAFE); } }
From source file:de.fhg.igd.mongomvcc.impl.internal.Tree.java
License:Open Source License
/** * Updates the head of a branch. Always waits for the database to * fsync before returning. This guarantees all threads will see the change. * This operation will usually be the last one when a commit is made, so * fsync'ing here is crucial for the database's integrity. Fsync'ing will * also make the database write all other documents created during the * commit to the hard disk.//w w w. j a v a 2 s .c o m * @param name the branch's name * @param headCID the CID of the new head */ public void updateBranchHead(String name, long headCID) { _branches.update(new BasicDBObject(MongoDBConstants.ID, name), new BasicDBObject("$set", new BasicDBObject(MongoDBConstants.CID, headCID)), false, false, WriteConcern.FSYNC_SAFE); }