-
Notifications
You must be signed in to change notification settings - Fork 8
Try3 - Cache FDB #46
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
Open
ApusDT
wants to merge
9
commits into
ohhmm:main
Choose a base branch
from
ApusDT:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Try3 - Cache FDB #46
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
47b9e08
Add files via upload
ApusDT 0c8cdbe
Update Cachefdb.cpp
ApusDT 90fe286
Add files via upload
ApusDT 8e91403
Add files via upload
ApusDT 3beb7aa
Delete Cachefdb.cpp
ApusDT aedd341
Delete Cacheefdb.h
ApusDT f61719d
Add files via upload
ApusDT 93e7b74
Delete CachefdbTRY2.cpp
ApusDT 9d10624
Add files via upload
ApusDT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| #pragma once | ||
|
|
||
|
|
||
|
|
||
| #ifdef OPENMIND_MATH_USE_FOUNDATIONDB_CACHE | ||
|
|
||
| #include <foundationdb/fdb_c.h> | ||
|
|
||
| #include <free_fdb/ffdb.h> | ||
|
|
||
| #else | ||
|
|
||
| namespace fdb_cli{ | ||
| class FDB; | ||
| } | ||
| #endif | ||
|
|
||
|
|
||
| //#include <filesystem> | ||
| //#include <future> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include <boost/filesystem.hpp> | ||
| #include "Variable.h" | ||
|
|
||
| namespace omnn::math { | ||
|
|
||
| namespace bi = boost::intrusive; | ||
|
|
||
| class EvictablePage | ||
| { | ||
| public: | ||
| using path_str_t = bi::path | ||
| using CheckCacheResult = std::pair<bool,Valuable>; | ||
|
|
||
| template < typename pageCache> | ||
|
|
||
| class Reference : public EvictablePageCache ::future<pageCache> { | ||
| using base = std::future<pageCache>;//creo que lo de abajo es lo mismo | ||
|
Owner
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. public: |
||
| virtual bool evict() = 0; // evic=extracted | ||
|
|
||
|
|
||
| //EvictablePage(Reference<EvictablePageCache> pageCache) : pageCache(pageCache) {} | ||
| // virtual ~EvictablePage(); | ||
| } | ||
|
|
||
|
|
||
| protected: | ||
| pageCache& Get() { | ||
| evict()//Extract(); | ||
| return pageCache; | ||
| } | ||
|
|
||
|
|
||
| public: | ||
| using bi::bi; | ||
|
|
||
| Reference (bi&& b) : bi(std::move(b)) | ||
| {} | ||
|
|
||
| operator bool(){ | ||
| return (evict || | ||
| ( bi::valid() | ||
| && bi::wait_for(std::chrono::seconds(0)) == std::future_status::ready | ||
| )) && Get().first | ||
| ; | ||
| } | ||
|
|
||
| bool NotInCache(){ | ||
| return (evict || | ||
| ( bi::valid() | ||
| && bi::wait_for(std::chrono::seconds(0)) == std::future_status::ready | ||
| )) && !Get().first; | ||
| } | ||
| }; | ||
|
|
||
| class EvictablePageCache : public ReferenceCounted<EvictablePageCache> | ||
| { | ||
| using List = | ||
| bi::list<EvictablePage, bi::path<EvictablePage, bi::future<>, &EvictablePage::path>>; | ||
|
|
||
| public: | ||
| using bi::bi; | ||
| using bi::operator bool; | ||
| // EvictablePageCache (bi&& b); | ||
| operator Valuable(); | ||
| }; | ||
|
|
||
| using val_set_t = Valuable::solutions_t; | ||
| using CheckCachedSet = std::pair<bool,val_set_t>; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| class CachedSet : public ReferenceCounted <CheckCachedSet> { | ||
| using base = ReferenceCounted <CheckCachedSet>; | ||
| public: | ||
| using bi::bi; | ||
| using bi::operator bool; | ||
| // CachedSet(bi&& b); | ||
| operator val_set_t(); | ||
| }; | ||
|
|
||
| private: | ||
| fdb_cli::FDB* fdb_c = nullptr; | ||
| path_str_t path; | ||
|
|
||
|
|
||
|
|
||
| // Opens a file that uses the FDB in-memory page cache | ||
| static Future<Reference<IAsyncFile>> open(std::string filename, int flags, int mode) { | ||
| //TraceEvent("AsyncFileCachedOpen").detail("Filename", filename); | ||
| auto itr = openFiles.find(filename); | ||
| if (itr == openFiles.end()) { | ||
| auto f = open_impl(filename, flags, mode); | ||
| if (f.isReady() && f.isError()) | ||
| return f; | ||
|
|
||
| auto result = openFiles.try_emplace(filename, f); | ||
|
|
||
| // This should be inserting a new entry | ||
| ASSERT(result.second); | ||
| itr = result.first; | ||
|
|
||
| // We return here instead of falling through to the outer scope so that we don't delete all references to | ||
| // the underlying file before returning | ||
| return itr->second.get(); | ||
| } | ||
| return itr->second.get(); | ||
| } | ||
|
|
||
|
|
||
| void DbOpen(); | ||
| protected: | ||
| std::string Value(const std::string& key); | ||
|
|
||
| public: | ||
| Cachefdb(const path_str_t& path); | ||
| ~Cachefdb(); | ||
|
|
||
| public: | ||
| Cachefdb(const path_str_t& path); | ||
| ~Cachefdb(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #pragma once | ||
| //pragma says include the file once | ||
|
|
||
|
|
||
| #ifdef OPENMIND_MATH_USE_FOUNDATIONDB_CACHE | ||
| //check the following function is defined | ||
|
|
||
|
|
||
| #include <foundationdb/fdb_c.h> | ||
|
|
||
| #include <free_fdb/ffdb.hh> | ||
| //copy and paste files into other files | ||
|
|
||
| #else | ||
|
|
||
| namespace fdb_cli{ | ||
| class FDB; | ||
| } | ||
| #endif | ||
|
|
||
|
|
||
|
|
||
| //#include <filesystem> | ||
| #include <future> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include <boost/filesystem.hpp> | ||
| //definition and implementation are in the same file, .hpp calls a class | ||
|
|
||
| #include "Variable.h" | ||
|
|
||
| namespace omnn::math { | ||
|
|
||
| namespace fs = boost::filesystem; | ||
|
|
||
| class Cachefdb | ||
| { | ||
| public: | ||
| using path_str_t_fdb = fs::path; | ||
|
|
||
| using CheckCache_fdb_Result = std::pair<bool,Valuable>; | ||
|
|
||
| template <typename ResultT_fdb> | ||
|
|
||
| class Cached_fdb_ValueBase : public std::future<ResultT_fdb> { | ||
| using base_fdb = std::future<ResultT_fdb>; | ||
| ResultT_fdb result_fdb = {}; | ||
| bool extracted_fdb = {}; | ||
| void Extract_fdb() { | ||
| if(!extracted_fdb){ | ||
| extracted_fdb = true; | ||
| result_fdb = base::get(); //class base method get | ||
| } | ||
| } | ||
| protected: //once it's gotten the value becomes protected i.e. only member of class' functions can access to it | ||
| //but it cannot be accesed from other classes | ||
| ResultT_fdb& Get() { | ||
| Extract_fdb(); | ||
| return result_fdb; | ||
| } | ||
| public: | ||
| using base::base; | ||
|
|
||
| Cached_fdb_ValueBase(base&& b) : base(std::move(b)) | ||
| {} | ||
|
|
||
| operator bool(){ | ||
| return (extracted_fdb || | ||
| ( base::valid_fdb() | ||
| && base::wait_for(std::chrono::seconds(0)) == std::future_status::ready | ||
| )) && Get().first | ||
| ; | ||
| } | ||
|
|
||
| bool NotInCache_fdb(){ | ||
| return (extracted_fdb || | ||
| ( base::valid_fdb() | ||
| && base::wait_for(std::chrono::seconds(0)) == std::future_status::ready | ||
| )) && !Get().first; | ||
| } | ||
| }; | ||
|
|
||
| class Cached_fdb : public Cached_fdb_ValueBase<CheckCache_fdb_Result> { | ||
| using base = Cached_fdb_ValueBase<CheckCache_fdb_Result>; | ||
| public: | ||
| using base::base; | ||
| using base::operator bool; | ||
| // Cached_fdb(base&& b); | ||
| operator Valuable_fdb(); | ||
| }; | ||
|
|
||
| using val_set_t_fdb = Valuable::solutions_t; | ||
| using CheckCached_fdb_Set = std::pair<bool,val_set_t>; | ||
|
|
||
| class Cached_fdb_Set : public Cached_fdb_ValueBase<CheckCached_fdb_Set> { | ||
| using base = Cached_fdb_ValueBase<CheckCached_fdb_Set>; | ||
| public: | ||
| using base::base; | ||
| using base::operator bool; | ||
| // CachedSet_fdb(base&& b); | ||
| operator val_set_t(); | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this lib function declares new library project with dependencies enumerated in params (${DEPENDENCIES})