CXX-3236 add mongocxx v1 declarations #1482
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Resolves CXX-3236. Followup to #1462 and companion PR to #1469 and #1470. Contains cherry-pick of proposed changes in #1469 (the "cpx: cxx-abi-v1-instance" commit).
This is 5 out of an estimated 7 major PRs which in total are expected to resolve CXX-2745 and CXX-3320.
Related tickets affected by the changes in this PR (applicable only to the v1 API) include (not exhaustive, but tried my best):
document::view
instead ofdocument::view_or_value
from options getters"options::client::ssl_opts
without "ssl=true" in URI"pool::entry::operator->()
"bsoncxx::string::view_or_value
ingridfs::bucket
"#include
hygiene in header files"mongocxx::v_noabi::options::index::storage_options
"Relative Changelog (v_noabi -> v1)
is_open()
tov1::gridfs::downloader
andv1::gridfs::uploader
to extend behavior ofoperator bool()
.flush()
tov1::gridfs::uploader
(exposingv_noabi::gridfs::uploader::flush_chunks()
) + documenting the existence of underlying buffers for better control over its behavior.chunks_written()
tov1::gridfs::uploader
(useful information)..upserted_ids()
forv1::update_many_result
for consistency withv1::bulk_write::result
(vs.v1::update_one_result
which uses the old.upserted_id()
).k_unknown
tov1::write_concern
for symmetry withv1::read_concern
.v1::indexes
,v1::pipeline
,v1::bulk_write::single
, etc.v1::bulk_write::result::raw()
to allow access to the raw server response.v1::bulk_write::insert_one::value
is made public.v1::pool::entry::operator->
,v1::client::database()
, etc. (by removing deleted overloads and ref-qualifiers; premature pessimization).v_noabi::*::view_or_value
is replaced with eitherview
orvalue
(std::string
forv_noabi::string::view_or_value
).value
.view
.char const*
to allow avoiding forced allocations. (We could really use acstring_view
...)view
, with a few exceptions for "simple" classes wrapping the underlying value with no additional invariants (e.g.v1::bulk_write::insert_one
).Optional<view_or_value>
->Optional<View>
(view_or_value
implies internal ownership).T const&
orOptional<T> const&
: returnT
orOptional<T>
instead.Optional<T> const&
) which severely restrict implementation freedom.v1::client_session::client()
: return the associated client (must be a mongocxx reference).v1::bulk_write::single::get_*()
: straightforward union-like API.const
qualifier from member functions and parameters which are not logically const.v1::collection::list_indexes()
usesmongoc_collection_t*
.v1::database
parameters inv1::client_encryption
usemongoc_database_t*
.v1::client
database operations usemongoc_client_t*
.T&
for setters (method-chaining) where various functions used to returnvoid
.v1::server_error
mongocxx::v1::exception
with.code() == v1::source_errc::server
..code()
is always the server error code,.client_code()
is the optional client error code, for consistency with the.raw()
invariant).v1::event::*
void*
are labeled with a comment indicating the underlying type.v1::events::server_description
is the sole exception due tov1::events::topology_description::servers()
, see "Removed" entry below.server_heartbeat_failed::message()
return type:string
->string_view
.v1::read_concern
: ignore unsupported values instead of throwing an exception.v1::read_preference
: treat invalid read modes ask_primary
instead of an error (same behavior asmongoc_read_prefs_get_mode()
).v1::write_concern
.tag(nullptr)
ask_default
instead of an error..acknowledge_level()
errors by converting unsupported values tok_unknown
and document "notk_unknown
" as a precondition for.to_document()
(treat as if unset).v1::gridfs::uploader
flushes its buffer on destruction (it didn't already do this?!).T*
parameters are madeT&
instead for input/output streams tov1::gridfs::bucket
.T*
instead ofOptional<T*>
for.key_vault_*()
inv1::auto_encryption
andv1::client_encryption
.v1::search_indexes::create_index()
return type to be consistent withv1::indexes::create_one()
..comment()
with.comment_option()
inv1::find_options
for consistency with other option classes.v1::collection
's bulk write API.Int32
->Int64
for bulk write API result values and somev1::pipeline
fields.id_map
forv1::bulk_write::result
and related API:Size
->Int64
for keys ofid_map
(e.g.v1::bulk_write::result
) for better spec accuracy.document::element
totypes::view
to avoid unnecessary proxy type (element key is always"_id"
; useless info) + consistency with other "result" API.v1::bulk_write::*
operation single-argument constructors explicit.v1::client_session::options()
->.opts()
to avoid conflict with::options
.with_transaction_cb
parameter type fromT*
(unconditional not-null) toT&
.v_noabi::events::server_description::is_master()
(deprecated by CXX-2262, CXX-2263 #841).v_noabi::events::topology_description::server_descriptions
: move ownership of underlyingmongoc_server_description_t
objects tov1::events::server_description
and avoid the awkward intermediate class. The array itself (not its elements) is deallocated after thestd::vector<v1::events::server_description>
is fully constructed.v_noabi::gridfs::chunks_and_bytes_offset
: implementation detail not used by any public API.v_noabi::result::gridfs::upload
ctor is made internal forv1::gridfs::upload_result
.ordered()
forv1::insert_one_options
(specific tov1::insert_many_options
).v_noabi::options::index::base_storage_options
and related API.v_noabi::read_preference::hedge()
.v1::client
..ssl()
API.v_noabi::options::index::haystack*()
API.v_noabi::options::index::version()
. (Was this meant to be "textIndexVersion"?)v1::server_error
(e.g.WriteConcernError
,BulkWriteError
, etc.).v1::server_error::raw()
should continue to suffice as a workaround for obtaining error-specific fields manually.noexcept
) via template parameter constraints (e.g. likebsoncxx::v1::document::value
's deleter API).v1::events::*
:.duration()
and.round_trip_time()
: changing the return type fromstd::int64_t
tostd::chrono::microseconds
.v1::events::server_heartbeat_failed
: support returning or throwing amongocxx::v1::exception
for thebson_error_t
?v1::events::server_description
does not conform to specification forServerDescription
.v1::tls
underspecification and lack of support for allmongoc_ssl_opt_t
fields.v1::collection
: missing access to raw server response (e.g..rename()
), missing support for additional command options (e.g..rename()
), missing session overloads (e.g..estimated_document_count()
), awkward range templates, use of bulk write operations instead of dedicated database commands (e.g..insert_one()
using bulk write "insertMany" instead of theinsert
database command?).indexes
vs.search_indexes
API symmetry and specification compliance (exacerbated by themodel
vs. command-specific options vs. common index options situation;v1::search_indexes::model
should probably be split intoSearchIndexModel
andSearchIndexOptions
).collation && !is_acknowledged
condition for.find_and_modify()
and etc.).General Notes
\param
or\returns
when behavior is plainly obvious from the declaration (see: Slack). Only include when at least one parameter or the return value requires documentation of special values and behaviors that is not apparent from the types alone. Prefer\par Preconditions
for partial parameter documentation.Optional<T>
return type for a "field" is "obviously" empty when "unset".0
being equivalent to "unset" for anInt
field is not "obvious", thus it is documented.v1::client::start_session
documents: "The client session object MUST be passed as the first argument to all operations that are intended to be executed in the context of a session." -> avoid needing countless repetition of\param session
paragraphs. The overload complexity should be revisited and addressed at a later time... (CXX-1835)\copydoc
is not applicable.()
is omitted given\ref func_name
when more than one overload may apply.\{ ... \}
Doxygen groups when able (helped by absence of\param
).mongocxx::v1::exception
for all other runtime errors".ex.what()
; encourage programmatic inspection viav1::source_errc
andv1::type_errc
instead.errc
(as in bsoncxx), of which there are currently only 9 in total (all other errors are deferred to mongoc):instance
(multiple object detection: CXX-3320 migrate instance and logger to mongocxx::v1 #1469)server_api
(translatefalse
returned by mongoc API for invalid versions into an exception)uri
(server_selection_try_once()
setter throws instead of returning a boolean)pool
(wait queue timeout for.acquire()
)collection
(narrowing conversion fromstd::chrono::duration
Int64 into a UInt32 for mongoc API compatibility)indexes
(index name"*"
is not permitted for.drop_one()
, no relevant mongoc API to defer to)v1::gridfs::bucket
(GridFS file metadata validation + database commands)v1::gridfs::downloader
(runtime GridFS file metadata validation and underlying stream state)v1::gridfs::uploader
(runtime GridFS file metadata validation and underlying stream state)v1/database.hpp
no longer includesv1/collection.hpp
and all of its transitive dependencies. 🎉void fn(T)
andT fn()
do not requireT
to be a complete type (even whenT = Optional<U>
!).collection
member functions)...bsoncxx::v1::document::view
).iterator end() const
even wheniterator begin()
(not-const).T*
->T&
when unconditionally not-null, or by changingOptional<T*>
->T*
(double-null).Review Focus Items
filter
).client_encryption
) or the parameter (class) type (e.g.write_concern
).Questions for Review
std::unique_ptr<impl> _impl
be madevoid* _impl
instead (even when aclass impl
is used) to leave open the possibility of replacingimpl
with a mongoc equivalent or vise versa as an ABI compatible change? Or is this "premature optimization" and usingstd::unique_ptr<T>
is sufficient?mongoc_*_t
type usevoid* _impl; // mongoc_*_t
, e.g. to avoid double-indirection? (Initial changes propose that only the view-likev1::events::*
classes do this.)char const*
+std::string
+string_view
set of overloads premature optimization? Should they be simplified to just a singlestring_view
overload with an internalstd::string
allocation?v1::read_preference::hedge()
premature? (CXX-3241)v1::client
premature? (CXX-1939)v1::indexes
premature? (CXX-1978)mongoc_cursor_clone()
be implemented by mongocxx by making cursors copyable? Or shouldmongoc_cursor_clone()
be deprecated given its confusing behavior (re-execute the underlying query)?v1::change_stream::batch_size()
supportstd::uint32_t
for consistency withmongoc_cursor_set_batch_size()
? Or doesmongoc_cursor_set_batch_size()
need to be updated to supportstd::int64_t
instead?