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

Cache fixes #209

Merged
merged 3 commits into from Jun 16, 2017
Merged

Cache fixes #209

merged 3 commits into from Jun 16, 2017

Conversation

shaiguitar
Copy link
Contributor

Not important to merge/release at this point, as there might be some more iterations to go through. But logging this here so I don't forget.

There might be some more fixes of these sorts of things over time as usage increases.

model_klass.new(load_cache(path)[:attrs])
else
Fog::Logger.warning("Found corrupt items in the cache: #{path}. Expire all & refresh cache soon.\n\nData:#{File.read(path)}")
end
Copy link
Member

Choose a reason for hiding this comment

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

I wonder where this check should be done here or in the load_cache method instead.
This one is big enough already.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds reasonable.

@BigGillyStyle
Copy link

BigGillyStyle commented May 25, 2017

Just as an FYI...we've had to revert to fog-core 1.44.1 gem version. 1.44.2 breaks with the following error:

/usr/local/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.3/lib/bundler/runtime.rb:89:in rescue in block (2 levels) in require': There was an error while trying to load the gem 'fog'. (Bundler::GemRequireError) Gem Load Error is: couldn't find HOME environment -- expanding~'
Backtrace for gem load error is:
[release_directory]/vendor/bundle/ruby/2.3.0/gems/fog-core-1.44.2/lib/fog/core/cache.rb:94:in `expand_path'

Credit to @PashaLVWD for finding this for us. He led me to this PR, which may be a fix?

@geemus
Copy link
Member

geemus commented May 25, 2017

@BigGillyStyle Thanks for the heads up. I think this contains the fix (but also some other stuff which is still in progress). I'll see if I can't extract the relevant bit so we can cut that into a release.

@geemus
Copy link
Member

geemus commented May 25, 2017

@BigGillyStyle I think it should be fixed and released in v1.44.3, sorry for the breakage!

@BigGillyStyle
Copy link

@geemus No worries...I mostly wanted to just let you know about this. I just tested out 1.44.3 and we're all good. Awesome turnaround! 👍

@shaiguitar
Copy link
Contributor Author

Been running this fork for a while and seems to work w/out an issue.

  • Added Fog::Cache.metadata for a given namespace so you can create custom cache expiry policies, or whatever you'd like to do for a given cache namespace / cloud vendor account-region etc.

For example:

  def renew_cache?
    last_refreshed = Fog::Cache.metadata[:last_refreshed]

    if last_refreshed.nil?
      # no metadata
      return true
    end

    if (Time.now - last_refreshed) > EXPIRE_TIME
      return true
    else
      return false
    end
  end
end
  • Added Fog::Cache.clean! as a helper method to blow away all local cache not just a specific namespace.
  • Removed the $HOME env expand path fix that has since been merged.
  • Refactored some code out of the large method into a separate check.

FWIW, locally the tests pass:

$ ruby -v
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-darwin16]

$ bundle exec rake travis

# Running:

................................................................../users/shai/.fog-cache/for-service-user-region-foo/fog_subfogtestservice_mock/fog_subfogtestmodel
/users/shai/.fog-cache/for-service-user-region-foo
..[fog][WARNING] Found duplicate items in the cache. Expire all & refresh cache soon.
..................................................................................................S..........................................................

Finished in 7.095842s, 31.7087 runs/s, 38.6142 assertions/s.

225 runs, 274 assertions, 0 failures, 0 errors, 1 skips

You have skipped tests. Run with --verbose for details.

@geemus
Copy link
Member

geemus commented Jun 14, 2017

@shaiguitar there were some weird breaks on master, which I think are fixed now. Could you rebase? Hopefully that will get us back to a passing test suite here. Thanks!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 74.207% when pulling e008cd1 on shaiguitar:cache_fixes into 6f3844e on fog:master.

@shaiguitar
Copy link
Contributor Author

@geemus rebased. looks like travis is failing on https://stackoverflow.com/questions/3163641/get-a-class-by-name-in-ruby for 1.9.3 and 1.8.7 ... Are those deprecated or should I try to patch those?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 74.207% when pulling 6b71530 on shaiguitar:cache_fixes into 6f3844e on fog:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 74.263% when pulling a5613cc on shaiguitar:cache_fixes into 6f3844e on fog:master.

@shaiguitar
Copy link
Contributor Author

So fixed the const_get compat and running into a different 1.8.7 compat issue with Array#sample. Is 1.8.7 supported or is that planned to be removed from travis?

@geemus
Copy link
Member

geemus commented Jun 14, 2017

I think if you rebase off master it should help. I fixed the const_get issue there, as well as other dependency issues (and got master passing for everything). I think those fixes are pretty good/clean (and are apt to conflict with these changes). Does that help/make sense?

@shaiguitar
Copy link
Contributor Author

I thought I had rebased earlier but now I'm wondering if I screwed up the rebase - can you take a quick look at the branch's current state?

@geemus
Copy link
Member

geemus commented Jun 14, 2017

I see my changes in the - portion of the diffs, but it looks like post-rebase they have all been removed (ie things like the const_split_and_get method, which I added to deal with the const issue). So maybe the merge choices were off?

@shaiguitar
Copy link
Contributor Author

Yeah at this point git diff origin/master points to that const get compat method that you added being removed, which ironically I added a similar one after rebasing and not including that in. Right now the only thing broken on travis is a Array#sample method that should be Array#choice 1.8.7. I could add another compat method for that if 1.8.7 is still to be around on CI. Once that specific branch issue is cleared I imagine it should go green assuming there's nothing else wrong with the rebase.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 74.159% when pulling 7189f85 on shaiguitar:cache_fixes into 6f3844e on fog:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 74.306% when pulling 0cb7a0e on shaiguitar:cache_fixes into 6f3844e on fog:master.

@shaiguitar
Copy link
Contributor Author

shaiguitar commented Jun 15, 2017

@geemus Latest compat error was 1.8.7 does not take uniq with a block. After this latest method addition travis passes. Unless you think moving the various compatibility methods from the module into core_ext or some sort makes sense, this should be ready to merge.

Copy link
Member

@geemus geemus left a comment

Choose a reason for hiding this comment

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

Having all those changes dropped is kind of frustrating, makes me feel like I wasted some effort. Anyway, some small other feedback here. Thanks!

load_cache(path)[:attrs]
loaded = cache_files.map do |path|
if valid_for_load?(path)
model_klass = const_get_compat(load_cache(path)[:model_klass])
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be repeated? Shouldn't it be the same as the passed-in model_klass value that is already set in the method scope?

end
end.compact

path = pick_random(cache_files)
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't clear on this, why does this use a random file?

@@ -35,9 +35,63 @@ def initialize(opts = {})
example_cache = File.expand_path(Fog::Cache.namespace(Fog::SubFogTestModel, @service)).downcase
expected_namespace = File.expand_path("~/.fog-cache/for-service-user-region-foo").downcase

puts example_cache
Copy link
Member

Choose a reason for hiding this comment

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

Could you remove these puts? I think I pulled them on master, as I presume they were just accidentally left behind?

@@ -101,7 +173,7 @@ def initialize(opts = {})

id = SecureRandom.hex

# security groups on aws for eg can have the same identity group name 'default'.
# security gruops on aws for eg can have the same identity group name 'default'.
Copy link
Member

Choose a reason for hiding this comment

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

I think I fixed this typo in my master also, looks like that change also was dropped.

Metadata can be used to implement cahce expiry policies.
For example, you have a cache expirey policy per-day.

Fog::Cache.metadata = {:last_dumped => "Tuesday"}

then next day, you re-run, check and expire the cache based
on the data that exists for that specific cache store.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 74.392% when pulling 882037a on shaiguitar:cache_fixes into 6f3844e on fog:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 74.392% when pulling 9e8191e on shaiguitar:cache_fixes into 6f3844e on fog:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 74.392% when pulling 9e8191e on shaiguitar:cache_fixes into 6f3844e on fog:master.

@shaiguitar
Copy link
Contributor Author

@geemus Understood. Rebase went off due to many commits I hadn't squashed so I opt'ed to skip some and just fill in the differences manually, it was my mistake.

I fixed the recent comments - removed random sampling by simply finding the first cache entry that is valid and the puts/comment typo. I also moved model/collection detection out of the loop. Let me know if there's anything left outstanding.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 74.445% when pulling 665b3d9 on shaiguitar:cache_fixes into 6f3844e on fog:master.

@geemus
Copy link
Member

geemus commented Jun 16, 2017

Thanks for working through that with me, looks good.

@geemus geemus merged commit 71513c5 into fog:master Jun 16, 2017
@shaiguitar shaiguitar deleted the cache_fixes branch June 18, 2017 14:51
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.

None yet

5 participants