-
Notifications
You must be signed in to change notification settings - Fork 26
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
Implement MDArray API #433
base: master
Are you sure you want to change the base?
Changes from all commits
203f923
fbc79a6
85ba9d6
4fbf316
b85b5d5
6b0721f
4c107fb
a8e15a0
2292bdd
5e39807
2b353f3
b57e23a
55b25b1
42685aa
2287f9f
77d22bf
36640fa
4744e94
9324fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1013,9 +1013,23 @@ function buildoverviews!( | |
return dataset | ||
end | ||
|
||
function destroy(dataset::AbstractDataset)::Nothing | ||
GDAL.gdalclose(dataset) | ||
# TODO: Wrap `GDAL.CPLErr` | ||
function close(dataset::AbstractDataset)::GDAL.CPLErr | ||
dataset.ptr == C_NULL && return GDAL.CE_Failure | ||
if !isnothing(dataset.children) | ||
for child in dataset.children | ||
value = child.value | ||
!isnothing(value) && destroy(value) | ||
end | ||
Base.empty!(dataset.children) | ||
end | ||
err = GDAL.gdalclose(dataset) | ||
dataset.ptr = C_NULL | ||
return err | ||
end | ||
|
||
function destroy(dataset::AbstractDataset)::Nothing | ||
close(dataset) | ||
Comment on lines
+1031
to
+1032
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I would prefer to not change the behavior of We can keep it scoped to |
||
return nothing | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of OGR, a dataset might have features (from e.g.
ArchGDAL.jl/src/ogr/featurelayer.jl
Lines 29 to 41 in 4b40fe8
.ownedby
(so that Julia's GC wouldn't finalize the dataset while there are references to it) and have an implicit convention that users shouldn't be callingdestroy
themselves (and either rely on Julia's GC, or the do-block approach for managing context).That said, if you feel strongly about it, I'm sympathetic to the argument for being able to "force close" a dataset that resulted in the
.children
attribute being introduced. To avoid https://gdal.org/api/python_gotchas.html#python-crashes-or-throws-an-exception-if-you-use-an-object-after-deleting-a-related-object, should we introduce a new type for datasets that tracks their children, and restrict this function to only accept those datasets?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is this OSGeo/gdal#10490 . When writing a dataset, there is no reliable way to ensure it has been written since one has to wait until all GDAL objects pointing into the dataset have been garbage collected and finalized.
One way out would be not provide an interactive API, and to handle all lifetimes manually or via context managers. That's quite inconvenient in many cases.
Thus I decided to implement a
close
function that (by default) hard-closes a dataset when the dataset is writable. For this, the dataset needs to hold references that need to be released when the dataset is force-closed.This has nothing to do with lifetime management. You can open datasets with a
hard_close=false
option, and no such tracking happens. However, it's then unclear when a dataset will actually be written to disk.I now think that the dataset should hold weak references (not strong ones) to the objects that should be released. I'll update the code.
If you have a different suggestion for reliably closing or flushing a dataset I'd be happy to change things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is inconvenient. I'd still recommend it for this PR though -- to keep the PR scoped to the introduction of the MDArray API and to introduce the hard close option in a separate PR.
Even if that were implemented correctly, it still doesn't address the resulting complexity of making all GDAL objects suspect of potentially corresponding to resources that might have already been released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to think about how to proceed without creating very unexpected behaviour.
There is already a function
isnull
that checks whether a reference is valid. References become invalid when they are released.