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

Fix xmdf lock #424

Merged
merged 4 commits into from
Sep 6, 2022
Merged

Fix xmdf lock #424

merged 4 commits into from
Sep 6, 2022

Conversation

vcloarec
Copy link
Collaborator

@vcloarec vcloarec commented Sep 2, 2022

For Xmdf format, when the mesh is closed (for example, removed from QGIS), the files is still locked as it is still open, and user is unable to rename or remove the file until QGIS is closed.

Indeed, the mesh is not closed properly because the file's handle is closed before the dataset's handle are closed, leading to keep the file open.

To close the mesh properly it necessary to close the file's handle once every other Hdf5 handles are closed. To achieve this, a "shared file's handle" is embeded in each HdFGroup and each HdfDataset. This member is declared before the group/dataset handle to be sure the shared handle is destroy once the group/dataset handle is effectively closed.
The destruction of the last shared handle leads to close the file.

To improve the encapsulation around HdfFile, some refactorization are also done.

Copy link
Contributor

@PeterPetrik PeterPetrik left a comment

Choose a reason for hiding this comment

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

Looks in general good, left some comments to discuss

@@ -66,6 +66,7 @@ class HdfFile
Create
};
typedef HdfH<H5I_FILE> Handle;
typedef std::shared_ptr<Handle> SharedHandle;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need new typedef personally for me it is easier to read the code when shared_ptrs are expanded everywhere.

std::string mPath;
};

typedef std::shared_ptr<HdfFile> HdfFileShared;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need new typedef personally for me it is easier to read the code when shared_ptrs are expanded everywhere.

HdfGroup( std::shared_ptr<Handle> handle, HdfFile::SharedHandle file );

private:
HdfFile::SharedHandle mFile; //must be the last destroyed
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the commend it misleading, I would remove it. If you want to add comment, I would say do not destroy from this class

Copy link
Collaborator Author

@vcloarec vcloarec Sep 2, 2022

Choose a reason for hiding this comment

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

yes, the comment should be "must be declared before std::shared_ptr<Handle> d to be sure it will be the last destroyed"

tests/test_xmdf.cpp Show resolved Hide resolved
@PeterPetrik PeterPetrik merged commit f5d6177 into lutraconsulting:master Sep 6, 2022
@vcloarec vcloarec deleted the fixXmdfLock branch October 7, 2022 12:37
vcloarec added a commit to vcloarec/MDAL that referenced this pull request Oct 11, 2022
vcloarec added a commit that referenced this pull request Oct 12, 2022
* retrieve exact behavior of FLO2D format before #424

* fix mingw build

* fix narrowing conversion

* ver++

* typo
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.

2 participants