Skip to content

Conversation

mseri
Copy link
Contributor

@mseri mseri commented Mar 6, 2018

I had an old experiment lying around, I've decided to resurrect it and polish it after a Slack discussion today. I've rewritten the commit history to reflect more it's evolution and avoid intermediate debugging commits.

I am going to test it on a private branch, this should not be merged until testing is done and we agree on what to do with the Bigbuffer story (look for Bigbuffer.to_string, it appears in a few places in the new code).

@mseri mseri requested a review from jonludlam March 6, 2018 16:57
@mseri
Copy link
Contributor Author

mseri commented Mar 6, 2018

I think originally the issue with Bigbuffer was that the maximum size of 32bits ocaml strings was 16Mb. The size of strings on 64 bit systems is on the order of 144 Petabytes (output of Sys.max_string_length, thanks @lindig)

@coveralls
Copy link

coveralls commented Mar 7, 2018

Coverage Status

Coverage increased (+0.3%) to 19.111% when pulling f8d1cd9 on mseri:no-legacy into 05def45 on xapi-project:master.

@gaborigloi
Copy link
Contributor

Hope this will be merged soon as it will make my work easier ^^

@mseri
Copy link
Contributor Author

mseri commented Mar 8, 2018

I'm running BVT and BST right now, if there are no further failures, and if somebody has the patience to review it in the meanwhile, we could proceed

@gaborigloi
Copy link
Contributor

gaborigloi commented Mar 8, 2018

Actually I only need the commits that remove the Legacy module and genOCaml.ml

@gaborigloi
Copy link
Contributor

Figured out how to solve my problem, so it's not that urgent now :)

@mseri
Copy link
Contributor Author

mseri commented Mar 8, 2018

The others are necessary to remove the Legacy module :P

@mseri
Copy link
Contributor Author

mseri commented Mar 8, 2018

For reference:

~/src/xen-api master $ cat _build/default/ocaml/xapi-types/aPI.ml | wc -l
6862

~/src/xen-api no-legacy $ cat _build/default/ocaml/xapi-types/aPI.ml | wc -l
3144

Marcello Seri added 21 commits March 8, 2018 17:25
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
This greatly simplifies the changes needed in import.ml

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Here we are performing an itermediate re-serialization to string.
It will be possible to simplify that further by implementing an
Xmlrpc.of_xml method in ocaml-rpc.

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
This removes the necessity to pass trough an intermediate re-stringification of
the various datastructures. There is still an open question about the need of
Bigbuffer. If we can cope with strings as done now, we could actually get rif
of Bigbuffer in all the rpc interaction, and maybe in xapi itself. If it is needed
it should not be hard to provide the necessary infrastructure in ocaml-rpc to
deal with it. We could also probably rely on Xmlrpc.from_a although I am a bit
wary of that call...

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Now (64bit) that strings can hold 144 Petabytes of data,
this module is no longer necessary.

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
…stead

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
…tive

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
… code that break the unmarshaller

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Marcello Seri added 2 commits March 8, 2018 17:25
… API generator

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
sprintf "%s = %s_of_rpc (List.assoc \"%s\" x)" (field fld) (OU.alias_of_ty fld.DT.ty)
(String.concat "_" fld.DT.full_name)
sprintf {|%s = %s_of_rpc (assocer "%s" x %s)|} (field fld) (OU.alias_of_ty fld.DT.ty)
(String.concat "_" fld.DT.full_name) (get_default fld)
Copy link
Contributor

@gaborigloi gaborigloi Mar 9, 2018

Choose a reason for hiding this comment

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

It is not necessary to generate these X_of_rpc, and rpc_of_X things, rpclib can do it for us. I have a set of working patches, one of which removes these custom functions and moves to ones generated by rpclib:
gaborigloi@2c4fc73

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in this case, we need to customise them and replace the autogenerated ones.

Copy link
Contributor Author

@mseri mseri Mar 9, 2018

Choose a reason for hiding this comment

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

Maybe we can use the new [@default ...] key to resolve the main issues, but it needs more work to serialize it correctly and it needs further testing. It is an improvement that can be added later and we should keep in mind to try it

in
match default_value with
None -> ""
| Some default -> sprintf "[@default (%s)]" (Datamodel_values.to_ocaml_string ~v2:true default)
Copy link
Contributor

Choose a reason for hiding this comment

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

Jon said this is okay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it doesn't but we have a plan to fix ocaml-rpc and make it possible

@mseri
Copy link
Contributor Author

mseri commented Mar 9, 2018

As it is now, this code passed both the BVT and the BST (jobs 80812 and 80813) 🎉 😄

@mseri
Copy link
Contributor Author

mseri commented Mar 9, 2018

If it is fine for you, I'd suggest that we review and proceed with the current changes, and we keep working to improve them to use only ocaml-rpc instead of generating the modules by hand. In the meanwhile ths would be further tested

Copy link
Contributor

@gaborigloi gaborigloi left a comment

Choose a reason for hiding this comment

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

Nice! Just some minor comments - it's not important to change the code, good to merge IMO

type response =
| String of string
| Bigbuf of Xapi_stdext_bigbuffer.Bigbuffer.t
type response = String of string
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth to just say type response = string?

Copy link
Contributor Author

@mseri mseri Mar 9, 2018

Choose a reason for hiding this comment

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

Probably it is fine. I wanted to minimize the changes. I’ll have a look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's fine. Done

let xml_string = Bigbuffer.make () in
really_read_bigbuffer fd xml_string hdr.Tar_unix.Header.file_size;
Xml.parse_bigbuffer xml_string
Unixext.really_read_string fd (Int64.to_int hdr.Tar_unix.Header.file_size)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be renamed to read_next_file, or we could add a Xmlrpc.of_string to the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a reason I did not add the Xmlrpc.to_string but I think that woth the latest changes that reason is no longer there. I’ll fix it or let you know the reason :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found it. The old Xva module uses a direct approach manipulating and marshalling/unmarshalling the xml. The read_xml function is used both by our new Xmlrpc and that old Xml.parse_String |> Xva.from_xml. Changing that is invasive and out of scope for this pr

; xapi_vsn_minor = Rpc.int_of_rpc (find _xapi_minor)
; export_vsn = try Rpc.int_of_rpc (find _export_vsn) with _ -> 0
}
| rpc -> raise (Failure(Printf.sprintf "version_of_rpc: malformed RPC %s" (Jsonrpc.to_string rpc)))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a minor point, but I'd use Rpc.to_string here, because we're dealing with a generic Rpc structure here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Faor enough. I uesd json only because I find it more readable but it is more natural to use Rpc.to_string. I’ll change it

|> Xmlrpc.of_string
|> API.ref_VM_set_of_rpc
with
parse_error -> raise Api_errors.(Server_error (field_type_error, [Printexc.to_string parse_error]))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very minor point again, but the param of this error seems to the field:

  91   error Api_errors.field_type_error ["field"]                                                                                                                               
  92     ~doc:"The value specified is of the wrong type" ();

Copy link
Contributor Author

@mseri mseri Mar 9, 2018

Choose a reason for hiding this comment

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

The error is bogus. Before we were not even adding the field, and passing an empty string instead.

Using the printexc I am printing the real reason we cannot unmarshal the type. It is still a field type error, but with a useful string in the metadata. I think that even if is not what announced the errors with that content are way more readable and understandable. I agree that it is anstretch, but I will keep them as they are

|> Xmlrpc.of_string
|> API.ref_VDI_of_rpc
with
parse_error -> raise Api_errors.(Server_error (field_type_error, [Printexc.to_string parse_error]))
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.

@mseri
Copy link
Contributor Author

mseri commented Mar 9, 2018

Thanks for the review. I think it’s worth making some of the changes before merging

Marcello Seri added 2 commits March 12, 2018 10:04
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
@mseri mseri mentioned this pull request Mar 12, 2018
Marcello Seri added 2 commits March 12, 2018 16:47
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
This gets rid of a leftover of 0583a91

Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
@jonludlam
Copy link
Contributor

This looks really good!

@jonludlam jonludlam merged commit e14d893 into xapi-project:master Mar 13, 2018
@mseri mseri deleted the no-legacy branch March 13, 2018 09:30
@robhoes
Copy link
Member

robhoes commented Mar 13, 2018

Nice cleanup: +202 −477 👍

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.

5 participants