Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Fix issue with extra versions #1732

Merged
merged 7 commits into from
May 29, 2020

Conversation

tst-lsavoie
Copy link
Collaborator

@tst-lsavoie tst-lsavoie commented May 4, 2020

This fixes two issues that cause extra versions to be produced unnecessarily during a build. The resulting database is correct, but the size of the database on disk is much larger than necessary.

The actual fixes are fairly small, but I did quite a bit of debugging and refactoring to track down the issue. Instead of throwing away the refactoring I am including it, so the changes are larger than one might expect. I tried to organize the changes into good commits, so it may be easier to review one commit at a time.

Here is a list of the major things I changed. I'll also provide comments on the PR to explain some of the changes.

  • Got rid of the "NoLongerNeeded" call that sometimes removed asset versions from the cache too early.
  • Re-copied the ReuseOrMakeAndUpdate and ReuseOrMakeAndUpdateSubasset code from previous versions into the Asset Factory. I'm not sure exactly what the difference is, but this fixes an issue that causes extra versions to be created.
  • Changed the template parameters for the functions in Asset Factory. The majority of lines changed relates to this. I created a new struct for every asset type that combines all the relevant related types for that asset and pass that as the template parameter to Asset Factory functions. This simplifies the code and makes it easier to get right, but it requires a lot of changes.
  • The above change required making significant changes to the unit tests. I also modified the tests to eliminate redundancies and achieve 100% coverage of Asset Factory.
  • Added some error checking to Storage Manager.
  • Changed how the Asset Serializer calculates filenames to match how the Storage Manager calculates filenames. I believe both methods were effectively identical, but this ensures there are no issues.

As a side effect of this fix, builds should be somewhat faster (due to building fewer versions of assets) and memory usage may be much less (due to extra versions of assets not hanging around in memory after they are removed from the cache). I've seen memory usage reductions of as much as 2/3 in system manager.

Fixes #1731

@googlebot googlebot added the cla: yes Manual verification that all contributors have signed the CLA. label May 4, 2020
@tst-lsavoie tst-lsavoie marked this pull request as draft May 4, 2020 20:13
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes Manual verification that all contributors have signed the CLA. labels May 5, 2020
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Manual verification that all contributors have signed the CLA. and removed cla: no labels May 5, 2020
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes Manual verification that all contributors have signed the CLA. labels May 5, 2020
@tst-lsavoie tst-lsavoie changed the base branch from master to release_5.3.4.1 May 5, 2020 20:25
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Manual verification that all contributors have signed the CLA. and removed cla: no labels May 5, 2020
@tst-lsavoie tst-lsavoie marked this pull request as ready for review May 5, 2020 20:28
@tst-lsavoie tst-lsavoie changed the title WIP: Fix issue with extra versions Fix issue with extra versions May 19, 2020

template <class MutableDerivedVersionHandleType,
class ConfigType, class VersionDType>
MutableDerivedVersionHandleType ReuseOrMakeAndUpdate(const std::string& ref_,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I copied over all the ReuseOrMakeAndUpdate* functions from earlier versions, which was the fix to one of the issues. Unfortunately it makes the diff hard to read.

}
else
{
version.NoLongerNeeded();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing the NoLongerNeeded calls was a fix to one of the bugs.

@@ -49,210 +55,181 @@ namespace AssetFactory
return nullptr;
}

template<class AssetType>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of the changes in this file are to use new template parameters that make the code clearer and make it easier to use the right template parameters. I also deleted a few functions that weren't used.

@@ -27,49 +28,13 @@
using namespace std;
using namespace AssetFactory;

// forward declare classes
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I essentially rewrote the MockAsset class hierarchy from scratch. I tried to keep parts from the original version but that probably won't show up in the diff. The tests themselves should be more similar, but I did make some changes, including getting rid of duplicate tests and adding new tests to get better coverage.

}

template<class VersionType>
template<class AssetType>
inline typename AssetType::VersionD FindVersion(const std::string & ref, const AssetDefs::Type & type) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Find function is a special case since it can find assets or asset versions, but the new template parameter includes both assets and versions in the same struct. I got around that by creating a FindVersion function so the regular Find function can always return an asset. The FindVersion function is only used below in this file.

@@ -283,6 +275,20 @@ ()

print $fh <<EOF;

// Convenience class that ties together related types
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This struct puts all the classes that relate to a specific asset type into one place where it's easy to reference several of them at once. It makes the Asset Factory functions much cleaner, but it requires a lot of changes to use it.

Copy link
Contributor

Choose a reason for hiding this comment

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

This makes the template parameters a LOT cleaner.

@tst-jlarocco
Copy link
Contributor

tst-jlarocco commented May 26, 2020

I didn't test, but the code looks good to me.

I don't see where the bug was in ReuseOrMakeAndUpdate, either... It looks nearly identical.

@tst-jkent tst-jkent merged commit 0852291 into google:release_5.3.4.1 May 29, 2020
@tst-lsavoie tst-lsavoie deleted the extra-versions branch June 25, 2020 15:57
tst-cjeffries pushed a commit to tst-cjeffries/earthenterprise that referenced this pull request Sep 14, 2020
* Move ReuseOrMakeAndUpdate out of the asset factory

* Don't remove assets from the cache unnecessarily

* Improved error handling in Storage Manager

* Simply asset factory templates and remove unused functions

* Move ReuseOrMakeAndUpdate back to the asset factory

* Clean up unnecessary namespace references

* Improve test coverage
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Manual verification that all contributors have signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Historical builds create extra versions of assets
4 participants