Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit f978108

Browse files
author
Alexander Patrikalakis
committed
Reduce dependence in implementations on Client.java
1 parent 5a470fc commit f978108

15 files changed

+119
-168
lines changed

dynamodb-janusgraph-storage-backend-cfn.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ Resources:
505505
- "sdk install java < /dev/null && sdk install maven < /dev/null && set -x\n"
506506
- "export GREMLIN_SERVER_USERNAME='ec2-user'\n"
507507
- "export LOG_DIR=/var/log/gremlin-server\n"
508-
- "export SERVER_DIRNAME=dynamodb-janusgraph-storage-backend-1.1.0\n"
508+
- "export SERVER_DIRNAME=dynamodb-janusgraph-storage-backend-1.1.1\n"
509509
- "export SERVER_ZIP=${SERVER_DIRNAME}.zip\n"
510510
- "export PACKAGES_DIR=/usr/local/packages\n"
511511
- "export INSTALL_DIR=${PACKAGES_DIR}/${SERVER_DIRNAME}\n"
@@ -551,7 +551,7 @@ Outputs:
551551
- Fn::GetAtt:
552552
- WebServerInstance
553553
- PublicDnsName
554-
- " /usr/local/packages/dynamodb-janusgraph-storage-backend-1.1.0/bin/gremlin.sh"
554+
- " /usr/local/packages/dynamodb-janusgraph-storage-backend-1.1.1/bin/gremlin.sh"
555555
Description: Use this remote shell to interact with the graph.
556556
GremlinServerEndpoint:
557557
Value:

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.amazonaws</groupId>
44
<artifactId>dynamodb-janusgraph-storage-backend</artifactId>
5-
<version>1.1.0</version>
5+
<version>1.1.1</version>
66
<packaging>jar</packaging>
77
<name>Amazon DynamoDB Storage Backend for JanusGraph</name>
88
<url>https://github.com/awslabs/dynamodb-janusgraph-storage-backend</url>
99
<description>The Amazon DynamoDB Storage Backend for JanusGraph: Distributed Graph Database allows JanusGraph graphs to use DynamoDB as a storage backend.</description>
1010
<scm>
1111
<url>[email protected]:awslabs/dynamodb-janusgraph-storage-backend.git</url>
12-
<tag>jg0.1.1-1.1.0</tag>
12+
<tag>jg0.1.1-1.1.1</tag>
1313
</scm>
1414
<properties>
1515
<default.test.jvm.opts>-Xms256m -Xmx1280m -XX:+HeapDumpOnOutOfMemoryError</default.test.jvm.opts>
@@ -18,7 +18,7 @@
1818
<dynamodb-local.port>4567</dynamodb-local.port>
1919
<dynamodb-local.endpoint>http://localhost:${dynamodb-local.port}</dynamodb-local.endpoint>
2020
<jdk.version>1.8</jdk.version>
21-
<aws.java.sdk.version>1.11.125</aws.java.sdk.version>
21+
<aws.java.sdk.version>1.11.160</aws.java.sdk.version>
2222
<janusgraph.version>0.1.1</janusgraph.version>
2323
<tinkerpop.version>3.2.3</tinkerpop.version>
2424
<dependency.plugin.version>2.10</dependency.plugin.version>
@@ -35,7 +35,7 @@
3535
<commons.logging.version>1.1.1</commons.logging.version>
3636
<hadoop.version>2.2.0</hadoop.version>
3737
<mockito.version>1.9.5</mockito.version>
38-
<lombok.version>1.16.16</lombok.version>
38+
<lombok.version>1.16.18</lombok.version>
3939
<docker.maven.version>0.4.13</docker.maven.version>
4040
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4141
<include.category></include.category>
@@ -193,7 +193,7 @@
193193
<dependency>
194194
<groupId>org.projectlombok</groupId>
195195
<artifactId>lombok</artifactId>
196-
<version>1.16.16</version>
196+
<version>${lombok.version}</version>
197197
</dependency>
198198
</dependencies>
199199
<build>

src/main/java/com/amazon/janusgraph/diskstorage/dynamodb/AbstractDynamoDbStore.java

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@
2020
import java.util.concurrent.ExecutionException;
2121
import java.util.concurrent.TimeUnit;
2222

23+
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
24+
import com.amazonaws.services.dynamodbv2.model.DeleteItemRequest;
25+
import com.amazonaws.services.dynamodbv2.model.GetItemRequest;
26+
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
27+
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
28+
import com.amazonaws.services.dynamodbv2.model.ReturnConsumedCapacity;
29+
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
30+
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest;
31+
import lombok.Getter;
2332
import org.apache.commons.codec.binary.Hex;
33+
import org.apache.commons.lang.builder.EqualsBuilder;
2434
import org.apache.commons.lang3.tuple.Pair;
2535
import org.janusgraph.diskstorage.BackendException;
2636
import org.janusgraph.diskstorage.Entry;
@@ -31,12 +41,6 @@
3141
import org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction;
3242
import org.janusgraph.diskstorage.locking.TemporaryLockingException;
3343

34-
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
35-
import com.amazonaws.services.dynamodbv2.model.GetItemRequest;
36-
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
37-
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
38-
import com.amazonaws.services.dynamodbv2.model.ScanRequest;
39-
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest;
4044
import com.google.common.cache.Cache;
4145
import com.google.common.cache.CacheBuilder;
4246
import com.google.common.cache.RemovalListener;
@@ -57,73 +61,82 @@
5761
@Slf4j
5862
public abstract class AbstractDynamoDbStore implements AwsStore {
5963
protected final Client client;
60-
protected final String tableName;
64+
@Getter
65+
private final String tableName;
6166
private final DynamoDBStoreManager manager;
62-
private final String storeName;
67+
@Getter
68+
private final String name;
6369
private final boolean forceConsistentRead;
6470
private final Cache<Pair<StaticBuffer, StaticBuffer>, DynamoDbStoreTransaction> keyColumnLocalLocks;
6571

66-
private static final class ReportingRemovalListener implements RemovalListener<Pair<StaticBuffer, StaticBuffer>, DynamoDbStoreTransaction> {
67-
private static final ReportingRemovalListener INSTANCE = new ReportingRemovalListener();
68-
private static ReportingRemovalListener theInstance() {
69-
return INSTANCE;
70-
}
71-
private ReportingRemovalListener() { }
72+
private enum ReportingRemovalListener implements RemovalListener<Pair<StaticBuffer, StaticBuffer>, DynamoDbStoreTransaction> {
73+
INSTANCE;
7274

7375
@Override
7476
public void onRemoval(final RemovalNotification<Pair<StaticBuffer, StaticBuffer>, DynamoDbStoreTransaction> notice) {
7577
log.trace("Expiring {} in tx {} because of {}", notice.getKey().toString(), notice.getValue().toString(), notice.getCause());
7678
}
7779
}
7880

79-
protected CreateTableRequest createTableRequest() {
80-
return new CreateTableRequest()
81-
.withTableName(tableName)
82-
.withProvisionedThroughput(new ProvisionedThroughput(client.readCapacity(tableName),
83-
client.writeCapacity(tableName)));
84-
}
85-
8681
protected void mutateOneKey(final StaticBuffer key, final KCVMutation mutation, final StoreTransaction txh) throws BackendException {
87-
manager.mutateMany(Collections.singletonMap(storeName, Collections.singletonMap(key, mutation)), txh);
88-
}
89-
90-
@Override
91-
public String getName() {
92-
return storeName;
82+
manager.mutateMany(Collections.singletonMap(name, Collections.singletonMap(key, mutation)), txh);
9383
}
9484

9585
protected UpdateItemRequest createUpdateItemRequest() {
96-
return new UpdateItemRequest().withTableName(tableName);
86+
return new UpdateItemRequest()
87+
.withTableName(tableName)
88+
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
9789
}
9890

9991
protected GetItemRequest createGetItemRequest() {
100-
return new GetItemRequest().withTableName(tableName).withConsistentRead(forceConsistentRead);
92+
return new GetItemRequest()
93+
.withTableName(tableName)
94+
.withConsistentRead(forceConsistentRead)
95+
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
96+
}
97+
98+
protected DeleteItemRequest createDeleteItemRequest() {
99+
return new DeleteItemRequest()
100+
.withTableName(tableName)
101+
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
101102
}
102103

103104
protected QueryRequest createQueryRequest() {
104-
return new QueryRequest().withTableName(tableName).withConsistentRead(forceConsistentRead);
105+
return new QueryRequest()
106+
.withTableName(tableName)
107+
.withConsistentRead(forceConsistentRead)
108+
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
105109
}
106110
protected ScanRequest createScanRequest() {
107-
return new ScanRequest().withTableName(tableName).withConsistentRead(forceConsistentRead);
111+
return new ScanRequest().withTableName(tableName)
112+
.withConsistentRead(forceConsistentRead)
113+
.withLimit(client.scanLimit(tableName))
114+
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
108115
}
109116
AbstractDynamoDbStore(final DynamoDBStoreManager manager, final String prefix, final String storeName) {
110117
this.manager = manager;
111118
this.client = this.manager.getClient();
112-
this.storeName = storeName;
119+
this.name = storeName;
113120
this.tableName = prefix + "_" + storeName;
114121
this.forceConsistentRead = client.isForceConsistentRead();
115122

116123
final CacheBuilder<Pair<StaticBuffer, StaticBuffer>, DynamoDbStoreTransaction> builder = CacheBuilder.newBuilder().concurrencyLevel(client.getDelegate().getMaxConcurrentUsers())
117124
.expireAfterWrite(manager.getLockExpiresDuration().toMillis(), TimeUnit.MILLISECONDS)
118-
.removalListener(ReportingRemovalListener.theInstance());
125+
.removalListener(ReportingRemovalListener.INSTANCE);
119126
this.keyColumnLocalLocks = builder.build();
120127
}
121128

122129
/**
123130
* Creates the schemata for the DynamoDB table or tables each store requires.
131+
* Implementations should override and reuse this logic
124132
* @return a create table request appropriate for the schema of the selected implementation.
125133
*/
126-
public abstract CreateTableRequest getTableSchema();
134+
public CreateTableRequest getTableSchema() {
135+
return new CreateTableRequest()
136+
.withTableName(tableName)
137+
.withProvisionedThroughput(new ProvisionedThroughput(client.readCapacity(tableName),
138+
client.writeCapacity(tableName)));
139+
}
127140

128141
@Override
129142
public final void ensureStore() throws BackendException {
@@ -133,7 +146,7 @@ public final void ensureStore() throws BackendException {
133146

134147
@Override
135148
public final void deleteStore() throws BackendException {
136-
log.debug("Entering deleteStore name:{}", storeName);
149+
log.debug("Entering deleteStore name:{}", name);
137150
client.getDelegate().deleteTable(getTableSchema().getTableName());
138151
//block until the tables are actually deleted
139152
client.getDelegate().ensureTableDeleted(getTableSchema().getTableName());
@@ -179,11 +192,6 @@ public void close() throws BackendException {
179192
log.debug("Closing table:{}", tableName);
180193
}
181194

182-
@Override
183-
public String getTableName() {
184-
return tableName;
185-
}
186-
187195
protected String encodeKeyForLog(final StaticBuffer key) {
188196
if (null == key) {
189197
return "";
@@ -209,6 +217,31 @@ String encodeForLog(final List<?> columns) {
209217
return result.append("]").toString();
210218
}
211219

220+
@Override
221+
public int hashCode() {
222+
return tableName.hashCode();
223+
}
224+
225+
@Override
226+
public boolean equals(final Object obj) {
227+
if (obj == null) {
228+
return false;
229+
}
230+
if (obj == this) {
231+
return true;
232+
}
233+
if (obj.getClass() != getClass()) {
234+
return false;
235+
}
236+
final AbstractDynamoDbStore rhs = (AbstractDynamoDbStore) obj;
237+
return new EqualsBuilder().append(tableName, rhs.tableName).isEquals();
238+
}
239+
240+
@Override
241+
public String toString() {
242+
return this.getClass().getName() + ":" + getTableName();
243+
}
244+
212245
protected String encodeForLog(final SliceQuery query) {
213246
return "slice[rk:" + encodeKeyForLog(query.getSliceStart()) + " -> " + encodeKeyForLog(query.getSliceEnd()) + " limit:" + query.getLimit() + "]";
214247
}

0 commit comments

Comments
 (0)