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

Support for non-seastar managed strings #833

Closed
wants to merge 1 commit into from

Conversation

sumeetchhetri
Copy link
Contributor

Add support for sstring instances that refer to existing non-managed strings(std::string, std::string_view, const char*[size_t])
This is required if we already have a std::string or a c string which needs to work with seastar sstrings, instead of copying the entire string we just want seastar to use the same with zero copy. The lifecycle of the string would be managed by the caller application.

…strings(std::string, std::string_view, const char*[size_t])
@sumeetchhetri
Copy link
Contributor Author

@nyh do you see any issues here at first glance?

@sumeetchhetri
Copy link
Contributor Author

@nyh, @amnonh this is the integration piece that I was talking about, and the referenced sstring usage is here. Do let me know if anything is missing in this PR?

@nyh
Copy link
Contributor

nyh commented Dec 10, 2020

I don't understand the purpose of this patch. Besides seastar::sstring (and the almost identical std::string - see #634) which owns its content, we also have std::string_view which does not. Interfaces which should accept either should simply take std::string_view and require the caller to maintain this string's lifetime. Adding to seastar::string the possibility for both sounds dangerous to me - code which assumes it owns the content of an sstring may be surprised when it turns out that it doesn't.

In my experience, in the past we had less awareness of std::string_view so some Seastar or Seastar-application functions needlessly take const sstring& instead of std::string_view. We can and should change those functions, not sstring. We did this a lot in the Scylla application recently.

@@ -65,6 +65,7 @@ class basic_sstring {
struct external_type {
char_type* str;
Size size;
bool is_ref;//all non-managed non-copy string references should set this flag to true
Copy link
Contributor

@nyh nyh Dec 10, 2020

Choose a reason for hiding this comment

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

Regardless of whether this patch is needed at all (see my other comment) please note you shouldn't just add something to "external type" - it will make it longer, and longer than "internal_type", and waste space. What you can do is to replace the old "pad" with a single-byte flag. HOWEVER, this byte - in internal - is already used to for the internal size. So maybe you should pick a specific value (e.g., 255) which will say this is a ref. Should probably have a function (is_ref()) to abstract this check.

@@ -106,6 +107,7 @@ public:
struct initialized_later {};

basic_sstring() noexcept {
u.external.is_ref = false;
Copy link
Contributor

@nyh nyh Dec 10, 2020

Choose a reason for hiding this comment

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

No, "u" is a union, you need to set either external or internal, you can't set both... In this constructor, the string is internal, so you musn't set external. The only byte common to both union members is the last one (size or pad). In fact, the sstring code would have been better and clearer if this byte was outside the union.

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.

None yet

2 participants