Skip to content

Commit

Permalink
potential implementation of irods_resource_plugin_s3 issue irods#2196
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Edgin committed May 14, 2024
1 parent fa0c0ff commit fd0a855
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions s3/libirods_s3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const std::string s3_restoration_days{"S3_RESTORATION_DAYS"}; // numb
const std::string s3_restoration_tier{"S3_RESTORATION_TIER"}; // either "standard", "bulk", or "expedited"
const std::string s3_enable_copyobject{"S3_ENABLE_COPYOBJECT"}; // If set to 0 the CopyObject API will not be used. Default is to use CopyObject.
const std::string s3_non_data_transfer_timeout_seconds{"S3_NON_DATA_TRANSFER_TIMEOUT_SECONDS"};
const std::string ROOT_COLL{"ROOT_COLL"};

const std::string s3_number_of_threads{"S3_NUMBER_OF_THREADS"}; // to save number of threads
const std::size_t S3_DEFAULT_RETRY_WAIT_SECONDS = 2;
Expand Down
2 changes: 2 additions & 0 deletions s3/libirods_s3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define ARCHIVE_NAMING_POLICY_KW "ARCHIVE_NAMING_POLICY"
#define CONSISTENT_NAMING "consistent"
#define DECOUPLED_NAMING "decoupled"
#define CHROOT_NAMING "chroot"

// For s3PutCopyFile to identify the real source type
typedef enum { S3_PUTFILE, S3_COPYOBJECT } s3_putcopy;
Expand Down Expand Up @@ -47,6 +48,7 @@ extern const std::string s3_circular_buffer_size;
extern const std::string s3_circular_buffer_timeout_seconds; // timeout for read or write to circular buffer
extern const std::string s3_uri_request_style; // either "path" or "virtual_hosted" - default "path"
extern const std::string s3_number_of_threads; // to save number of threads
extern const std::string ROOT_COLL;
extern const std::size_t S3_DEFAULT_RETRY_WAIT_SECONDS;
extern const std::size_t S3_DEFAULT_MAX_RETRY_WAIT_SECONDS;
extern const std::size_t S3_DEFAULT_RETRY_COUNT;
Expand Down
61 changes: 61 additions & 0 deletions s3/s3_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ namespace irods_s3 {
// if archive naming policy is decoupled
// we use the object's reversed id as S3 key name prefix
if (archive_naming_policy == DECOUPLED_NAMING) {

// XXX: The following logic forgets that the base path in the bucket may be bucket
// folder object

// extract object name and bucket name from physical path
std::vector< std::string > tokens;
irods::string_tokenize(object->physical_path(), "/", tokens);
Expand Down Expand Up @@ -417,6 +421,63 @@ namespace irods_s3 {
L1desc[index].dataObjInfo->filePath[MAX_NAME_LEN - 1] = '\0';
}

} else if (archive_naming_policy == CHROOT_NAMING) {
// The user wants to map /iplant/home/tedgin/s3 to the bucket folder object
// /buck@id:tht13.html-preview-vscodeet/cyverse. If the logical path to a new data
// object is /iplant/home/tedgin/s3/file, then the suggested physical path will be
// /bucket/cyverse/home/tedgin/s3/file. We need to replace /home/tedgin/s3/ with /.

irods::error ret;

std::string root_coll;
ret = _ctx.prop_map().get<std::string>(ROOT_COLL, root_coll);
if (ret.ok()) { // TODO: Log warning if this parameter is missing?

// Only need to modify the vault path if root collection was provided

std::string vault_path_root;
ret = _ctx.prop_map().get<std::string>(irods::RESOURCE_PATH, vault_path_root);
if (!ret.ok()) {
logger::error(fmt::format(
"[{}] {}", get_resource_name(_ctx.prop_map()), ret.result()));

// TODO How do we propagate the error?
}

auto rel_vault_path = std::string_view(object->physical_path());
rel_vault_path.remove_prefix(std::min(
rel_vault_path.find_first_not_of(vault_path_root), rel_vault_path.size()));
rel_vault_path.remove_prefix(std::min(
rel_vault_path.find_first_not_of(root_coll), rel_vault_path.size()));

// TODO handle case where the rel_vault_path doesn't begin with root_coll

auto vault_path = vault_path_root + std::string(rel_vault_path);

// get data id from L1desc
int index = -1;
for (int i = 0; i < NUM_L1_DESC; ++i) {
if (L1desc[i].inuseFlag) {
if (L1desc[i].dataObjInp && L1desc[i].dataObjInfo &&
L1desc[i].dataObjInp->objPath == object->logical_path()
&& L1desc[i].dataObjInfo->filePath == object->physical_path()) {

index = i;
break;
}
}
}

if (index > 0) {
// update physical path
logger::debug("{}:{} ({}) [[{}]] updating physical_path to {}",
__FILE__, __LINE__, __FUNCTION__, thread_id, vault_path.c_str());

object->physical_path(vault_path);
strncpy(L1desc[index].dataObjInfo->filePath, vault_path.c_str(), MAX_NAME_LEN);
L1desc[index].dataObjInfo->filePath[MAX_NAME_LEN - 1] = '\0';
}
}
}
}

Expand Down

0 comments on commit fd0a855

Please sign in to comment.