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

DSS-client C API update #93

Closed
wants to merge 3 commits into from
Closed

DSS-client C API update #93

wants to merge 3 commits into from

Conversation

iso-p
Copy link

@iso-p iso-p commented Jan 11, 2024

Added C APIs & associated tests for DSS-client:

  1. PutObject
  2. ListObjects
  3. DeleteAll

@iso-p iso-p requested a review from grandsuri January 11, 2024 23:24
@iso-p iso-p self-assigned this Jan 11, 2024
@iso-p iso-p requested a review from a team as a code owner January 11, 2024 23:24
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions

5 Security Hotspots
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

idea Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

keys_concat += key + "\n"; // seperate each key by line assuming there is no "\n" in the object name or directory name or delimiter
}
if (keys_concat == "") return END_OF_LIST;
keys[keys_concat.length()] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any possibility to get length of the key during the for loop at line 1363 itself?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can accumulate and get the sum of key lengths.

}
if (keys_concat == "") return END_OF_LIST;
keys[keys_concat.length()] = '\0';
strncpy(keys, keys_concat.c_str(), keys_concat.length());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If above case doesn't work, you can store the keys_concat.length() in a variable and use that instead of computing length multiple times thereby introducing latency

if (keys_concat == "") return END_OF_LIST;
keys[keys_concat.length()] = '\0';
strncpy(keys, keys_concat.c_str(), keys_concat.length());
if (keys[keys_concat.length()] != '\0') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above for computing length
Is there any possibility to stop the keys_concat in the for loop itself if the memory allocation for keys is not sufficient

return END_OF_LIST;
}
std::string keys_concat = "";
for (std::string key: client->list_objs->GetPage()){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpp + operator is very expensive when you have lot of objects. Rather than that, you can fall back to standard and efficient C based code. But this requires key_buffer_size to be passed as a variable

len = 0
for (key: list_objs->GetPage()) {
    len += snprintf(&keys[len],  key_buffer_size - len, "%s", keys.c_str());
    if (len ==key_buffer_size) {
        //Check the last keys.length() size in the key buffer to make sure the key is completely copied.
        //otherwise return error
    }
}

return FAILURE;
}
uint32_t pg_size = DSS_PAGINATION_DEFAULT;
int max_key_len = 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to hash define this value (1024) as S3_MAX_KEY_SIZE_LIMIT at the top or in the header file for easy change in the future

// calculating the size of the file
long int fsize = ftell(fp);
if (dp->d_type == DT_REG && fsize > 0){ // PutObject does not support empty files
if (PutObject(c, (void*) path, strlen(path), path) < 0 ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fclose needs to be done

return -1;
}
}
if (putRecursive(c, path) < 0) return -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than going into the function putRecursive to check whether dir or not, you can add else case. Since you are already checking regular file in the top and you have dp->d_type handy.

int main(int argc, char* argv[]) {
DSSClient *c;
int fd = -1;
int ret = -1;
int size = 1024*1024;
unsigned char* buff;
unsigned char* buff1;
int cur_page = -1;
int max_key_len = 1024;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use hash-define variable as mentioned above

@@ -38,8 +81,9 @@ int main(int argc, char* argv[]) {
printf("Invalid endpoint URL\n");
return -1;
}
if (argc == 5)
if (argc >= 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why >= is required? If so, then the usage should be updated properly

goto out;
}
//test the LIST
keys_list = (char*) malloc(sizeof(char) * max_key_len * GetPageSize());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since sizeof(char) is 1, you can see if this is really required. This may be applicable at the top as well.

@velomatt
Copy link
Contributor

@iso-p @grandsuri Is this a new feature? If yes - this needs to go under patent verification review. If that is the case, immediately close this PR and delete your branch.

@iso-p
Copy link
Author

iso-p commented Feb 13, 2024

@iso-p @grandsuri Is this a new feature? If yes - this needs to go under patent verification review. If that is the case, immediately close this PR and delete your branch.

@velomatt @grandsuri I don't know the definition of "new feature" here. What we added was 3 extern C function to expose existing c++ code to C.

@grandsuri
Copy link
Contributor

@iso-p @grandsuri Is this a new feature? If yes - this needs to go under patent verification review. If that is the case, immediately close this PR and delete your branch.

@velomatt @grandsuri I don't know the definition of "new feature" here. What we added was 3 extern C function to expose existing c++ code to C.

As Mike mentioned, this is not a new feature. We are exposing the existing C++ interface functions through C code to consume in other components like .NET based.

@iso-p iso-p closed this Feb 13, 2024
@iso-p iso-p deleted the client_c_update branch February 13, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants