Skip to content
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

fix: Store the resources in S3 buckets #611

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/sirix-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
api implLibraries.iouring
api implLibraries.lz4
api implLibraries.roaringbitmap
api implLibraries.amazonS3

implementation implLibraries.snappyJava
implementation implLibraries.browniesCollections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,23 @@

package org.sirix.access;

import com.google.common.base.MoreObjects;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.openhft.hashing.LongHashFunction;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.checkerframework.checker.index.qual.NonNegative;
import org.json.JSONObject;
import org.sirix.BinaryEncodingVersion;
import org.sirix.access.trx.node.HashType;
import org.sirix.exception.SirixIOException;
Expand All @@ -46,20 +58,11 @@
import org.sirix.settings.VersioningType;
import org.sirix.utils.OS;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import net.openhft.hashing.LongHashFunction;

/**
* Holds the settings for a resource which acts as a base for session that can not change. This
Expand Down Expand Up @@ -165,6 +168,36 @@ public static int compareStructure(final Path file) {
}
}

public static final class AWSStorageInformation {
private final String awsProfile;
private final String awsRegion;
private final String bucketName; //this should be same as the database name
private final boolean shouldCreateBucketIfNotExists;

public AWSStorageInformation(String awsProfile, String awsRegion, String bucketName,
boolean shouldCreateBucketIfNotExists) {
this.awsProfile = awsProfile;
this.awsRegion = awsRegion;
this.bucketName = bucketName;
this.shouldCreateBucketIfNotExists = shouldCreateBucketIfNotExists;
}

public String getAwsProfile() {
return awsProfile;
}

public String getAwsRegion() {
return awsRegion;
}

public String getBucketName() {
return bucketName;
}

public boolean shouldCreateBucketIfNotExists() {
return shouldCreateBucketIfNotExists;
}
}
// FIXED STANDARD FIELDS
/**
* Standard storage.
Expand Down Expand Up @@ -297,6 +330,14 @@ public static int compareStructure(final Path file) {

// END MEMBERS FOR FIXED FIELDS

/*
* Optional AWS Credentials
* */
/*
* This could be improved in future to make it more sophisticated in terms setting the credentials
* for creating the cloud client connection
* */
public final AWSStorageInformation awsStoreInfo;
/**
* Get a new builder instance.
*
Expand Down Expand Up @@ -330,6 +371,7 @@ private ResourceConfiguration(final ResourceConfiguration.Builder builder) {
customCommitTimestamps = builder.customCommitTimestamps;
storeNodeHistory = builder.storeNodeHistory;
binaryVersion = builder.binaryEncodingVersion;
awsStoreInfo = builder.awsStoreInfo;
}

public BinaryEncodingVersion getBinaryEncodingVersion() {
Expand Down Expand Up @@ -448,7 +490,8 @@ public boolean storeNodeHistory() {
private static final String[] JSONNAMES =
{ "binaryEncoding", "revisioning", "revisioningClass", "numbersOfRevisiontoRestore", "byteHandlerClasses",
"storageKind", "hashKind", "hashFunction", "compression", "pathSummary", "resourceID", "deweyIDsStored",
"persistenter", "storeDiffs", "customCommitTimestamps", "storeNodeHistory", "storeChildCount" };
"persistenter", "storeDiffs", "customCommitTimestamps", "storeNodeHistory", "storeChildCount", "awsStoreInfo",
"awsProfile","awsRegion","bucketName","shouldCreateBucketIfNotExists"};

/**
* Serialize the configuration.
Expand Down Expand Up @@ -500,6 +543,15 @@ public static void serialize(final ResourceConfiguration config) throws SirixIOE
jsonWriter.name(JSONNAMES[15]).value(config.storeNodeHistory);
// Child count.
jsonWriter.name(JSONNAMES[16]).value(config.storeChildCount);

jsonWriter.name(JSONNAMES[17]);
jsonWriter.beginObject();
sband marked this conversation as resolved.
Show resolved Hide resolved
jsonWriter.name(JSONNAMES[18]).value(config.awsStoreInfo.getAwsProfile());
jsonWriter.name(JSONNAMES[19]).value(config.awsStoreInfo.getAwsRegion());
jsonWriter.name(JSONNAMES[20]).value(config.awsStoreInfo.getBucketName());
jsonWriter.name(JSONNAMES[21]).value(config.awsStoreInfo.shouldCreateBucketIfNotExists());
jsonWriter.endObject();

jsonWriter.endObject();
} catch (final IOException e) {
throw new SirixIOException(e);
Expand Down Expand Up @@ -596,7 +648,21 @@ public static ResourceConfiguration deserialize(final Path file) throws SirixIOE
name = jsonReader.nextName();
assert name.equals(JSONNAMES[16]);
final boolean storeChildCount = jsonReader.nextBoolean();

name = jsonReader.nextName();
assert name.equals(JSONNAMES[17]);
/*Begin object to read the nested json properties required aws connection*/
jsonReader.beginObject();
AWSStorageInformation awsStoreInfo=null;
if(jsonReader.hasNext()) {
final String awsProfile=jsonReader.nextString();
final String awsRegion=jsonReader.nextString();
final String bucketName=jsonReader.nextString();
final boolean shouldCreateBucketIfNotExists=jsonReader.nextBoolean();
awsStoreInfo = new AWSStorageInformation(awsProfile,
awsRegion, bucketName, shouldCreateBucketIfNotExists);
}
jsonReader.endObject();
/*End object to end reading the nested json properties*/
jsonReader.endObject();
jsonReader.close();
fileReader.close();
Expand All @@ -619,7 +685,8 @@ public static ResourceConfiguration deserialize(final Path file) throws SirixIOE
.storeDiffs(storeDiffs)
.storeChildCount(storeChildCount)
.customCommitTimestamps(customCommitTimestamps)
.storeNodeHistory(storeNodeHistory);
.storeNodeHistory(storeNodeHistory)
.awsStoreInfo(awsStoreInfo);

// Deserialized instance.
final ResourceConfiguration config = new ResourceConfiguration(builder);
Expand Down Expand Up @@ -713,6 +780,8 @@ public static final class Builder {

private BinaryEncodingVersion binaryEncodingVersion = BINARY_ENCODING_VERSION;

private AWSStorageInformation awsStoreInfo;

/**
* Constructor, setting the mandatory fields.
*
Expand Down Expand Up @@ -880,6 +949,12 @@ public Builder binaryEncodingVersion(BinaryEncodingVersion binaryEncodingVersion
return this;
}

/*Since this is an optional config parameter, null check is not needed*/
public Builder awsStoreInfo(final AWSStorageInformation awsStoreInfo) {
this.awsStoreInfo = awsStoreInfo;
return this;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
11 changes: 11 additions & 0 deletions bundles/sirix-core/src/main/java/org/sirix/io/StorageType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import org.sirix.access.ResourceConfiguration;
import org.sirix.exception.SirixIOException;
import org.sirix.io.cloud.amazon.AmazonS3Storage;
import org.sirix.io.file.FileStorage;
import org.sirix.io.filechannel.FileChannelStorage;
import org.sirix.io.iouring.IOUringStorage;
Expand Down Expand Up @@ -113,6 +114,16 @@ public IOStorage getInstance(final ResourceConfiguration resourceConf) {
storage.loadRevisionFileDataIntoMemory(cache);
return storage;
}
},

CLOUD {
@Override
public IOStorage getInstance(final ResourceConfiguration resourceConf) {
final AsyncCache<Integer, RevisionFileData> cache =
getIntegerRevisionFileDataAsyncCache(resourceConf);
final var storage = new AmazonS3Storage(resourceConf, cache);
return storage;
}
};

public static final ConcurrentMap<Path, AsyncCache<Integer, RevisionFileData>> CACHE_REPOSITORY =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sirix.io.cloud;

public enum CloudPlatform {

AWS, GCP, AZURE

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sirix.io.cloud;

import org.sirix.io.IOStorage;

public interface ICloudStorage extends IOStorage {



}
Loading