Search in sources :

Example 36 with WriteConcern

use of com.mongodb.WriteConcern in project jackrabbit-oak by apache.

the class MemoryDocumentStore method setReadWriteMode.

@Override
public void setReadWriteMode(String readWriteMode) {
    if (readWriteMode == null || readWriteMode.equals(lastReadWriteMode)) {
        return;
    }
    lastReadWriteMode = readWriteMode;
    try {
        Map<String, String> map = Splitter.on(", ").withKeyValueSeparator(":").split(readWriteMode);
        String read = map.get("read");
        if (read != null) {
            ReadPreference readPref = ReadPreference.valueOf(read);
            if (!readPref.equals(this.readPreference)) {
                this.readPreference = readPref;
            }
        }
        String write = map.get("write");
        if (write != null) {
            WriteConcern writeConcern = WriteConcern.valueOf(write);
            if (!writeConcern.equals(this.writeConcern)) {
                this.writeConcern = writeConcern;
            }
        }
    } catch (Exception e) {
    // unsupported or parse error - ignore
    }
}
Also used : ReadPreference(com.mongodb.ReadPreference) WriteConcern(com.mongodb.WriteConcern) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)

Example 37 with WriteConcern

use of com.mongodb.WriteConcern in project jackrabbit-oak by apache.

the class BlobThroughPutTest method performBenchMark_WriteConcern.

@Ignore
@Test
public void performBenchMark_WriteConcern() throws UnknownHostException, InterruptedException {
    Mongo mongo = new Mongo(new DBAddress(remoteServer));
    final DB db = mongo.getDB(TEST_DB1);
    final DBCollection nodes = db.getCollection("nodes");
    final DBCollection blobs = db.getCollection("blobs");
    int readers = 0;
    int writers = 2;
    for (WriteConcern wc : namedConcerns.keySet()) {
        prepareDB(nodes, blobs);
        final Benchmark b = new Benchmark(nodes, blobs);
        Result r = b.run(readers, writers, true, wc);
        results.add(r);
    }
    prepareDB(nodes, blobs);
    dumpResult();
}
Also used : DBCollection(com.mongodb.DBCollection) Mongo(com.mongodb.Mongo) WriteConcern(com.mongodb.WriteConcern) DBAddress(com.mongodb.DBAddress) DB(com.mongodb.DB) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with WriteConcern

use of com.mongodb.WriteConcern in project jackrabbit-oak by apache.

the class MongoDBExceptionTest method before.

@Before
public void before() throws Exception {
    OakFongo fongo = new OakFongo("fongo") {

        @Override
        protected void beforeExecuteBulkWriteOperation(boolean ordered, Boolean bypassDocumentValidation, List<?> writeRequests, WriteConcern aWriteConcern) {
            maybeThrow();
        }

        @Override
        protected void beforeFindAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert) {
            maybeThrow();
        }

        @Override
        protected void beforeUpdate(DBObject q, DBObject o, boolean upsert, boolean multi, WriteConcern concern, DBEncoder encoder) {
            maybeThrow();
        }

        @Override
        protected void beforeFind(DBObject query, DBObject projection) {
            maybeThrow();
        }

        private void maybeThrow() {
            if (exceptionMsg != null) {
                throw new MongoException(exceptionMsg);
            }
        }
    };
    store = new MongoDocumentStore(fongo.getMongo(), "oak", new DocumentMK.Builder());
}
Also used : MongoException(com.mongodb.MongoException) WriteConcern(com.mongodb.WriteConcern) OakFongo(com.mongodb.OakFongo) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DBEncoder(com.mongodb.DBEncoder) DBObject(com.mongodb.DBObject) Before(org.junit.Before)

Example 39 with WriteConcern

use of com.mongodb.WriteConcern in project jackrabbit-oak by apache.

the class MongoConnection method hasWriteConcern.

/**
 * Returns {@code true} if the given {@code uri} has a write concern set.
 * @param uri the URI to check.
 * @return {@code true} if the URI has a write concern set, {@code false}
 *      otherwise.
 */
public static boolean hasWriteConcern(@Nonnull String uri) {
    MongoClientOptions.Builder builder = MongoClientOptions.builder();
    builder.writeConcern(WC_UNKNOWN);
    WriteConcern wc = new MongoClientURI(checkNotNull(uri), builder).getOptions().getWriteConcern();
    return !WC_UNKNOWN.equals(wc);
}
Also used : MongoClientOptions(com.mongodb.MongoClientOptions) WriteConcern(com.mongodb.WriteConcern) MongoClientURI(com.mongodb.MongoClientURI)

Example 40 with WriteConcern

use of com.mongodb.WriteConcern in project pinpoint by naver.

the class MongoWriteConcernMapper method buildWriteConcern.

private Map<WriteConcern, String> buildWriteConcern() {
    Map<WriteConcern, String> writeConcernMap = new HashMap<>();
    for (final Field f : WriteConcern.class.getFields()) {
        if (Modifier.isStatic(f.getModifiers()) && f.getType().equals(WriteConcern.class) && f.getAnnotation(Deprecated.class) == null) {
            String value = f.getName();
            try {
                WriteConcern key = (WriteConcern) f.get(null);
                writeConcernMap.put(key, value);
            } catch (IllegalAccessException e) {
                PLogger logger = PLoggerFactory.getLogger(this.getClass());
                logger.warn("WriteConcern access error Caused by:" + e.getMessage(), e);
            }
        }
    }
    return writeConcernMap;
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) WriteConcern(com.mongodb.WriteConcern) PLogger(com.navercorp.pinpoint.bootstrap.logging.PLogger)

Aggregations

WriteConcern (com.mongodb.WriteConcern)53 Document (org.bson.Document)14 MongoException (com.mongodb.MongoException)11 List (java.util.List)11 ArrayList (java.util.ArrayList)9 ReadPreference (com.mongodb.ReadPreference)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 TimeUnit (java.util.concurrent.TimeUnit)7 BsonDocument (org.bson.BsonDocument)7 DeleteResult (com.mongodb.client.result.DeleteResult)6 HashMap (java.util.HashMap)6 ClientSessionOptions (com.mongodb.ClientSessionOptions)5 ReadConcern (com.mongodb.ReadConcern)5 Arrays (java.util.Arrays)5 BsonValue (org.bson.BsonValue)5 FullDocument (com.mongodb.client.model.changestream.FullDocument)4 InsertOneResult (com.mongodb.client.result.InsertOneResult)4 MongoClient (com.mongodb.reactivestreams.client.MongoClient)4 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)4