Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from nodesmith/mongo
Browse files Browse the repository at this point in the history
Mongo read only concept
  • Loading branch information
Samm Desmond authored Oct 11, 2018
2 parents 0565249 + e9f9d6d commit 0e03183
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions modDbImpl/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
requires leveldbjni.all;
requires rocksdbjni;
requires h2.mvstore;
requires java.security.sasl;

exports org.aion.db.impl;
exports org.aion.db.impl.leveldb;
Expand Down
36 changes: 36 additions & 0 deletions modDbImpl/src/org/aion/db/impl/mongodb/MongoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ public boolean matchedExpectation(WriteBatch batch) {
private ClientSession clientSession;
private MongoCollection<BsonDocument> collection = null;
private WriteBatch batch = null;
private boolean isReader = false;

public MongoDB(String dbName, String mongoClientUri) {
super(dbName);
this.mongoClientUri = mongoClientUri;

this.isReader = mongoClientUri.contains("reader");
}

/**
Expand Down Expand Up @@ -272,6 +275,10 @@ public boolean commitCache(Map<ByteArrayWrapper, byte[]> cache) {
check();
check(cache.keySet().stream().map(k -> k.getData()).collect(Collectors.toList()));

if (this.isReader) {
return true;
}

WriteBatch edits = new WriteBatch().addEditsWrapper(cache);
WriteBatchResult result = doBulkWrite(edits);

Expand All @@ -293,6 +300,10 @@ public void put(byte[] key, byte[] value) {
check();
check(key);

if (this.isReader) {
return;
}

// Write this single edit in as a batch
WriteBatch edits = new WriteBatch().addEdit(key, value);
doBulkWrite(edits);
Expand All @@ -303,6 +314,10 @@ public void delete(byte[] key) {
check();
check(key);

if (this.isReader) {
return;
}

// Write this single edit in as a batch
WriteBatch edits = new WriteBatch().addEdit(key, null);
doBulkWrite(edits);
Expand All @@ -313,6 +328,10 @@ public void putBatch(Map<byte[], byte[]> inputMap) {
check();
check(inputMap.keySet());

if (this.isReader) {
return;
}

WriteBatch edits = new WriteBatch().addEdits(inputMap);
doBulkWrite(edits);
}
Expand All @@ -322,6 +341,10 @@ public void putToBatch(byte[] key, byte[] value) {
check();
check(key);

if (this.isReader) {
return;
}

if (this.batch == null) {
this.batch = new WriteBatch();
}
Expand All @@ -333,6 +356,10 @@ public void putToBatch(byte[] key, byte[] value) {
public void commitBatch() {
check();

if (this.isReader) {
return;
}

if (this.batch != null) {
LOG.info("Committing batch of writes");
doBulkWrite(this.batch);
Expand All @@ -348,6 +375,11 @@ public void deleteBatch(Collection<byte[]> keys) {
check();
check(keys);


if (this.isReader) {
return;
}

if (!keys.isEmpty()) {
Map<byte[], byte[]> batch = new HashMap();
keys.forEach(key -> batch.put(key, null));
Expand All @@ -374,6 +406,10 @@ public void close() {
public void drop() {
check();

if (this.isReader) {
return;
}

LOG.info("Dropping collection {}", this.name);
this.collection.drop(this.clientSession);
}
Expand Down
2 changes: 1 addition & 1 deletion script/prepack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi

# generate aion runtime
if [ ! -d "$JDK_RT" ]; then
$JDK_PATH/bin/jlink --module-path $JDK_PATH/jmods --add-modules java.base,java.xml,java.logging,java.management,jdk.unsupported,javafx.graphics,javafx.controls,javafx.base,jdk.sctp,javafx.fxml,javafx.swing --output $JDK_RT
$JDK_PATH/bin/jlink --module-path $JDK_PATH/jmods --add-modules java.base,java.xml,java.logging,java.management,jdk.unsupported,javafx.graphics,javafx.controls,javafx.base,jdk.sctp,javafx.fxml,javafx.swing,java.security.sasl --output $JDK_RT
cp $JDK_PATH/bin/jstack $JDK_RT/bin
fi

Expand Down

0 comments on commit 0e03183

Please sign in to comment.