-
Notifications
You must be signed in to change notification settings - Fork 40
Add support for Cloud Storage #3179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,9 @@ dependencies { | |
| implementation("com.google.cloud:alloydb-jdbc-connector:${alloyDbJdbcConnectorVersion}") { | ||
| exclude group: 'org.slf4j', module: 'slf4j-api' | ||
| } | ||
| implementation("com.google.cloud:google-cloud-storage:${googleCloudStorageVersion}") { | ||
| exclude group: 'org.slf4j', module: 'slf4j-api' | ||
| } | ||
| implementation "org.apache.commons:commons-text:${commonsTextVersion}" | ||
| testImplementation platform("org.junit:junit-bom:${junitVersion}") | ||
| testImplementation 'org.junit.jupiter:junit-jupiter' | ||
|
|
@@ -226,7 +229,7 @@ task integrationTestCassandra(type: Test) { | |
| classpath = sourceSets.integrationTestCassandra.runtimeClasspath | ||
| outputs.upToDateWhen { false } // ensures integration tests are run every time when called | ||
| options { | ||
| systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")}) | ||
| systemProperties(System.getProperties().findAll { it.key.toString().startsWith("scalardb") }) | ||
|
Comment on lines
-229
to
+232
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatter adds white spaces. Since other tasks in this file also use this style, I've kept this change. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -237,7 +240,7 @@ task integrationTestCosmos(type: Test) { | |
| classpath = sourceSets.integrationTestCosmos.runtimeClasspath | ||
| outputs.upToDateWhen { false } // ensures integration tests are run every time when called | ||
| options { | ||
| systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")}) | ||
| systemProperties(System.getProperties().findAll { it.key.toString().startsWith("scalardb") }) | ||
| } | ||
| jvmArgs '-XX:MaxDirectMemorySize=4g', '-Xmx6g', | ||
| // INFO com.azure.cosmos.implementation.RxDocumentClientImpl - Initializing DocumentClient [3] with serviceEndpoint [https://localhost:8081/], ... | ||
|
|
@@ -255,7 +258,7 @@ task integrationTestDynamo(type: Test) { | |
| classpath = sourceSets.integrationTestDynamo.runtimeClasspath | ||
| outputs.upToDateWhen { false } // ensures integration tests are run every time when called | ||
| options { | ||
| systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")}) | ||
| systemProperties(System.getProperties().findAll { it.key.toString().startsWith("scalardb") }) | ||
| } | ||
| maxParallelForks = 10 | ||
| } | ||
|
|
@@ -267,7 +270,7 @@ task integrationTestJdbc(type: Test) { | |
| classpath = sourceSets.integrationTestJdbc.runtimeClasspath | ||
| outputs.upToDateWhen { false } // ensures integration tests are run every time when called | ||
| options { | ||
| systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")}) | ||
| systemProperties(System.getProperties().findAll { it.key.toString().startsWith("scalardb") }) | ||
| } | ||
| maxHeapSize = "4g" | ||
| } | ||
|
|
@@ -279,7 +282,7 @@ task integrationTestObjectStorage(type: Test) { | |
| classpath = sourceSets.integrationTestObjectStorage.runtimeClasspath | ||
| outputs.upToDateWhen { false } // ensures integration tests are run every time when called | ||
| options { | ||
| systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")}) | ||
| systemProperties(System.getProperties().findAll { it.key.toString().startsWith("scalardb") }) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -290,7 +293,7 @@ task integrationTestMultiStorage(type: Test) { | |
| classpath = sourceSets.integrationTestMultiStorage.runtimeClasspath | ||
| outputs.upToDateWhen { false } // ensures integration tests are run every time when called | ||
| options { | ||
| systemProperties(System.getProperties().findAll{it.key.toString().startsWith("scalardb")}) | ||
| systemProperties(System.getProperties().findAll { it.key.toString().startsWith("scalardb") }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,11 @@ public class ObjectStorageWrapperIntegrationTest { | |
| private static final String TEST_OBJECT2 = "test-object2"; | ||
| private static final String TEST_OBJECT3 = "test-object3"; | ||
| private static final int BLOB_STORAGE_LIST_MAX_KEYS = 5000; | ||
| private static final int CLOUD_STORAGE_LIST_MAX_KEYS = 1000; | ||
| private static final int S3_LIST_MAX_KEYS = 1000; | ||
|
|
||
| private ObjectStorageWrapper wrapper; | ||
| private int listMaxKeys; | ||
|
|
||
| @BeforeAll | ||
| public void beforeAll() throws ObjectStorageWrapperException { | ||
|
|
@@ -38,6 +41,16 @@ public void beforeAll() throws ObjectStorageWrapperException { | |
| ObjectStorageUtils.getObjectStorageConfig(new DatabaseConfig(properties)); | ||
| wrapper = ObjectStorageWrapperFactory.create(objectStorageConfig); | ||
| createObjects(); | ||
|
|
||
| if (ObjectStorageEnv.isBlobStorage()) { | ||
| listMaxKeys = BLOB_STORAGE_LIST_MAX_KEYS; | ||
| } else if (ObjectStorageEnv.isCloudStorage()) { | ||
| listMaxKeys = CLOUD_STORAGE_LIST_MAX_KEYS; | ||
| } else if (ObjectStorageEnv.isS3()) { | ||
| listMaxKeys = S3_LIST_MAX_KEYS; | ||
| } else { | ||
| throw new AssertionError(); | ||
| } | ||
| } | ||
|
|
||
| @AfterAll | ||
|
|
@@ -152,14 +165,14 @@ public void update_NonExistingObjectKeyGiven_ShouldThrowPreconditionFailedExcept | |
| String objectKey = "non-existing-key"; | ||
|
|
||
| // Act Assert | ||
| assertThatCode(() -> wrapper.update(objectKey, "some-object", "some-version")) | ||
| assertThatCode(() -> wrapper.update(objectKey, "some-object", "123456789")) | ||
|
Comment on lines
-155
to
+168
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Cloud Storage assumes |
||
| .isInstanceOf(PreconditionFailedException.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void update_WrongVersionGiven_ShouldThrowPreconditionFailedException() { | ||
| // Arrange | ||
| String wrongVersion = "wrong-version"; | ||
| String wrongVersion = "123456789"; | ||
|
|
||
| // Act Assert | ||
| assertThatCode(() -> wrapper.update(TEST_KEY2, "another-object", wrongVersion)) | ||
|
|
@@ -219,7 +232,7 @@ public void delete_ExistingObjectKeyWithWrongVersionGiven_ShouldThrowPreconditio | |
| // Arrange | ||
| Optional<ObjectStorageWrapperResponse> response1 = wrapper.get(TEST_KEY1); | ||
| assertThat(response1.isPresent()).isTrue(); | ||
| String wrongVersion = "wrong-version"; | ||
| String wrongVersion = "123456789"; | ||
|
|
||
| // Act Assert | ||
| assertThatCode(() -> wrapper.delete(TEST_KEY1, wrongVersion)) | ||
|
|
@@ -253,7 +266,7 @@ public void getKeys_WithNonExistingPrefix_ShouldReturnEmptySet() throws Exceptio | |
| public void getKeys_WithPrefixForTheNumberOfObjectsExceedingTheListLimit_ShouldReturnAllKeys() | ||
| throws Exception { | ||
| String prefix = "prefix-"; | ||
| int numberOfObjects = BLOB_STORAGE_LIST_MAX_KEYS + 1; | ||
| int numberOfObjects = listMaxKeys + 1; | ||
| try { | ||
| // Arrange | ||
| for (int i = 0; i < numberOfObjects; i++) { | ||
|
|
@@ -313,7 +326,7 @@ public void deleteByPrefix_WithNonExistingPrefix_ShouldDoNothing() throws Except | |
| deleteByPrefix_WithPrefixForTheNumberOfObjectsExceedingTheListLimit_ShouldDeleteAllObjects() | ||
| throws Exception { | ||
| String prefix = "prefix-"; | ||
| int numberOfObjects = BLOB_STORAGE_LIST_MAX_KEYS + 1; | ||
| int numberOfObjects = listMaxKeys + 1; | ||
| try { | ||
| // Arrange | ||
| for (int i = 0; i < numberOfObjects; i++) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| import com.scalar.db.config.DatabaseConfig; | ||
| import com.scalar.db.storage.objectstorage.blobstorage.BlobStorageConfig; | ||
| import com.scalar.db.storage.objectstorage.cloudstorage.CloudStorageConfig; | ||
| import com.scalar.db.storage.objectstorage.s3.S3Config; | ||
| import java.util.Arrays; | ||
| import java.util.Optional; | ||
|
|
@@ -47,6 +48,13 @@ public void beforeAll() throws ObjectStorageWrapperException { | |
| BlobStorageConfig.PARALLEL_UPLOAD_THRESHOLD_IN_BYTES, | ||
| String.valueOf(parallelUploadUnit * 2)); | ||
| parallelUploadThresholdInBytes = parallelUploadUnit * 2; | ||
| } else if (ObjectStorageEnv.isCloudStorage()) { | ||
| // Minimum block size must be greater than or equal to 256KB for Cloud Storage | ||
| Long parallelUploadUnit = 256 * 1024L; // 256KB | ||
| properties.setProperty( | ||
| CloudStorageConfig.PARALLEL_UPLOAD_BLOCK_SIZE_IN_BYTES, | ||
| String.valueOf(parallelUploadUnit)); | ||
| parallelUploadThresholdInBytes = parallelUploadUnit * 2; | ||
| } else if (ObjectStorageEnv.isS3()) { | ||
| // Minimum part size must be greater than or equal to 5MB for S3 | ||
| Long parallelUploadUnit = 5 * 1024 * 1024L; // 5MB | ||
|
|
@@ -59,7 +67,7 @@ public void beforeAll() throws ObjectStorageWrapperException { | |
| throw new AssertionError(); | ||
| } | ||
|
|
||
KodaiD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| char[] charArray = new char[(int) parallelUploadThresholdInBytes]; | ||
| char[] charArray = new char[(int) parallelUploadThresholdInBytes + 1]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The object size has been changed to ensure that the multipart upload was triggered. |
||
| Arrays.fill(charArray, 'a'); | ||
| testObject1 = new String(charArray); | ||
| Arrays.fill(charArray, 'b'); | ||
|
|
@@ -163,14 +171,14 @@ public void update_NonExistingObjectKeyGiven_ShouldThrowPreconditionFailedExcept | |
| String objectKey = "non-existing-key"; | ||
|
|
||
| // Act Assert | ||
| assertThatCode(() -> wrapper.update(objectKey, "some-object", "some-version")) | ||
| assertThatCode(() -> wrapper.update(objectKey, "some-object", "123456789")) | ||
| .isInstanceOf(PreconditionFailedException.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void update_WrongVersionGiven_ShouldThrowPreconditionFailedException() { | ||
| // Arrange | ||
| String wrongVersion = "wrong-version"; | ||
| String wrongVersion = "123456789"; | ||
|
|
||
| // Act Assert | ||
| assertThatCode(() -> wrapper.update(TEST_KEY2, "another-object", wrongVersion)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.