use of com.mongodb.MongoException in project jackrabbit-oak by apache.
the class ReplicaSetInfo method updateReplicaStatus.
void updateReplicaStatus() {
BasicDBObject result;
try {
result = getReplicaStatus();
} catch (MongoException e) {
LOG.error("Can't get replica status", e);
rootRevisions = null;
secondariesSafeTimestamp = 0;
return;
}
@SuppressWarnings("unchecked") Iterable<BasicBSONObject> members = (Iterable<BasicBSONObject>) result.get("members");
if (members == null) {
members = Collections.emptyList();
}
updateRevisions(members);
}
use of com.mongodb.MongoException in project jackrabbit-oak by apache.
the class MongoCacheConsistencyTest method getFixture.
@Override
public DocumentStoreFixture getFixture() throws Exception {
Fongo fongo = new OakFongo("fongo") {
private String suppressedEx = null;
@Override
protected void afterInsert(WriteResult result) {
maybeThrow();
}
@Override
protected void afterFindAndModify(DBObject result) {
maybeThrow();
}
@Override
protected void afterUpdate(WriteResult result) {
maybeThrow();
}
@Override
protected void afterRemove(WriteResult result) {
maybeThrow();
}
@Override
protected void beforeExecuteBulkWriteOperation(boolean ordered, Boolean bypassDocumentValidation, List<?> writeRequests, WriteConcern aWriteConcern) {
// suppress potentially set exception message because
// fongo bulk writes call other update methods
suppressedEx = exceptionMsg;
exceptionMsg = null;
}
@Override
protected void afterExecuteBulkWriteOperation(BulkWriteResult result) {
exceptionMsg = suppressedEx;
suppressedEx = null;
maybeThrow();
}
private void maybeThrow() {
if (exceptionMsg != null) {
throw new MongoException(exceptionMsg);
}
}
};
DocumentMK.Builder builder = provider.newBuilder().setAsyncDelay(0);
final DocumentStore store = new MongoDocumentStore(fongo.getDB("oak"), builder);
return new DocumentStoreFixture() {
@Override
public String getName() {
return "MongoDB";
}
@Override
public DocumentStore createDocumentStore(int clusterId) {
return store;
}
};
}
use of com.mongodb.MongoException in project jackrabbit-oak by apache.
the class MongoDocumentStore method findUncachedWithRetry.
/**
* Finds a document and performs a number of retries if the read fails with
* an exception.
*
* @param collection the collection to read from.
* @param key the key of the document to find.
* @param docReadPref the read preference.
* @param retries the number of retries. Must not be negative.
* @param <T> the document type of the given collection.
* @return the document or {@code null} if the document doesn't exist.
*/
@CheckForNull
private <T extends Document> T findUncachedWithRetry(Collection<T> collection, String key, DocumentReadPreference docReadPref, int retries) {
checkArgument(retries >= 0, "retries must not be negative");
if (key.equals("0:/")) {
LOG.trace("root node");
}
int numAttempts = retries + 1;
MongoException ex = null;
for (int i = 0; i < numAttempts; i++) {
if (i > 0) {
LOG.warn("Retrying read of " + key);
}
try {
return findUncached(collection, key, docReadPref);
} catch (MongoException e) {
ex = e;
}
}
if (ex != null) {
throw ex;
} else {
// impossible to get here
throw new IllegalStateException();
}
}
use of com.mongodb.MongoException in project mongo-java-driver by mongodb.
the class MongoIterableSubscription method requestInitialData.
@Override
void requestInitialData() {
mongoIterable.batchSize(getBatchSize());
mongoIterable.batchCursor(new SingleResultCallback<AsyncBatchCursor<TResult>>() {
@Override
public void onResult(final AsyncBatchCursor<TResult> result, final Throwable t) {
if (t != null) {
onError(t);
} else if (result != null) {
batchCursor = result;
requestMoreData();
} else {
onError(new MongoException("Unexpected error, no AsyncBatchCursor returned from the MongoIterable."));
}
}
});
}
use of com.mongodb.MongoException in project mongo-java-driver by mongodb.
the class Base64Codec method encode.
public String encode(final byte[] in) {
int modulus = 0;
int bitWorkArea = 0;
int numEncodedBytes = (in.length / BYTES_PER_UNENCODED_BLOCK) * BYTES_PER_ENCODED_BLOCK + ((in.length % BYTES_PER_UNENCODED_BLOCK == 0) ? 0 : 4);
byte[] buffer = new byte[numEncodedBytes];
int pos = 0;
for (int b : in) {
modulus = (modulus + 1) % BYTES_PER_UNENCODED_BLOCK;
if (b < 0) {
b += 256;
}
// BITS_PER_BYTE
bitWorkArea = (bitWorkArea << 8) + b;
if (0 == modulus) {
// 3 bytes = 24 bits = 4 * 6 bits to extract
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 18) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 12) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 6) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[bitWorkArea & SIX_BIT_MASK];
}
}
switch(// 0-2
modulus) {
case // 8 bits = 6 + 2
1:
// top 6 bits
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 2) & SIX_BIT_MASK];
// remaining 2
buffer[pos++] = ENCODE_TABLE[(bitWorkArea << 4) & SIX_BIT_MASK];
buffer[pos++] = PAD;
// Last entry no need to ++
buffer[pos] = PAD;
break;
case // 16 bits = 6 + 6 + 4
2:
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 10) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea >> 4) & SIX_BIT_MASK];
buffer[pos++] = ENCODE_TABLE[(bitWorkArea << 2) & SIX_BIT_MASK];
// Last entry no need to ++
buffer[pos] = PAD;
break;
default:
break;
}
try {
return new String(buffer, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new MongoException("UTF-8 Charset is not available");
}
}
Aggregations