Skip to content

[r,c++] Use SOMA Context object throughout#2997

Merged
eddelbuettel merged 10 commits intomainfrom
de/sc-55146/use_somacontext
Sep 16, 2024
Merged

[r,c++] Use SOMA Context object throughout#2997
eddelbuettel merged 10 commits intomainfrom
de/sc-55146/use_somacontext

Conversation

@eddelbuettel
Copy link
Copy Markdown
Contributor

@eddelbuettel eddelbuettel commented Sep 16, 2024

Issue and/or context:

SOMA Context objects are used throughout the C++ library part of SOMA. Where we previously serialized context and configuration to vector, maps or lists of key-value pairs, we now hold on to an allocated object for longer.

Changes:

This PR changes how we provide such a context from the R package by allocating one as a shared pointer and passing it around as an external pointer throuch which the SOMA context object can be accessed. Where needed, the SOMA context also contains a (core) TileDB context object.

We currently cache the most-recently created object at the package level and provide it if no new one is demanded. This scheme is exactly what tiledb-r does, and acts reliably and robust via a single access point soma_context(). One unit test show how to create a different configuration without caching, using it and then reverting to the default.

SOMA classes can obtain their initial default object via the instantiating factory methods. Access is then provided via a member function, allowing both for simple re-use as well variations (object by object) as needed. How to split the core object values off the platform_config object is left for a subsequent PR that will refine the interface.

All tests pass.

Notes for Reviewer:

SC 55146 #2899

Copy link
Copy Markdown
Contributor

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

This is awesome! Just a few minor notes at this point.

Comment thread apis/r/R/SOMADataFrame.R Outdated
Comment thread apis/r/R/SOMADataFrame.R Outdated
Comment thread apis/r/R/SOMASparseNDArray.R Outdated
Comment thread apis/r/R/ephemeral.R Outdated
Comment thread apis/r/src/riterator.cpp Outdated
Comment thread apis/r/R/SOMADenseNDArray.R Outdated
Also minor cleanup from code review for one indentation and a few comments,
and one spurious extra call
Comment thread apis/r/R/SOMANDArrayBase.R Outdated
Comment thread apis/r/R/TileDBObject.R
Comment on lines +18 to +19
tiledb_timestamp = NULL, internal_use_only = NULL,
soma_context = NULL) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought we had agreed on not exposing soma_context() via $new() at this point in time #2988 (comment)

Copy link
Copy Markdown
Contributor Author

@eddelbuettel eddelbuettel Sep 16, 2024

Choose a reason for hiding this comment

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

Yes. This gives the object the option to also set one here but it is not a requirement. Having the entry point is good for testing, methinks. See the comment a few lines futher down as well as the need to rework / let go of tiledbsoma_ctx. I think this is all best addressed in a next PR.

# Set context
tiledbsoma_ctx <- tiledbsoma_ctx %||% SOMATileDBContext$new()
if (!inherits(x = tiledbsoma_ctx, what = 'SOMATileDBContext')) {
stop("'tiledbsoma_ctx' must be a SOMATileDBContext object", call. = FALSE)
}
private$.tiledbsoma_ctx <- tiledbsoma_ctx
private$.tiledb_ctx <- self$tiledbsoma_ctx$context()
# TODO: re-enable once new UX is worked out
# soma_context <- soma_context %||% soma_context()
# stopifnot(
# "'soma_context' must be a pointer" = inherits(x = soma_context, what = 'externalptr')
# )
if (is.null(soma_context)) {
private$.soma_context <- soma_context() # FIXME via factory and paramater_config
} else {
private$.soma_context <- soma_context
}

Comment thread apis/r/R/utils.R
sr <- sr_setup(
uri = x$uri,
config = as.character(tiledb::config(x$tiledbsoma_ctx$context())),
soma_context(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note for future work: this should be replaced with fetching the context from x; currently available with

Suggested change
soma_context(),
x$.__enclos_env__$private$.soma_context

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point but not urgent and on the fence as whether we should use opaque internals. "Future work", as you say.

@eddelbuettel eddelbuettel merged commit d55c40d into main Sep 16, 2024
@eddelbuettel eddelbuettel deleted the de/sc-55146/use_somacontext branch September 16, 2024 16:09
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