JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
StorageCollection.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 11/16/17.
3 //
4 
5 #ifndef JODA_STORAGECOLLECTION_H
6 #define JODA_STORAGECOLLECTION_H
7 
9 
10 #include <unordered_map>
11 
12 #include <joda/join/JoinManager.h>
13 #include <boost/functional/hash.hpp>
14 #include "../../../../../include/joda/storage/JSONStorage.h"
15 
16 #define JODA_TEMPORARY_STORAGE_NAME "TEMPORARY_RESULT"
17 #define JODA_STORE_SKIPPED_QUERY_ID 0
18 #define JODA_STORE_EXTERNAL_RS_ID 1
19 #define JODA_STORE_EMPTY_RS_ID 2
20 #define JODA_STORE_VALID_ID_START 3
21 
28  public:
33  static StorageCollection instance; // Guaranteed to be destroyed.
34  // Instantiated on first use.
35  return instance;
36  }
37 
39  void operator=(StorageCollection const &) = delete;
40 
41  virtual ~StorageCollection();
48  std::shared_ptr<JSONStorage> getStorage(const std::string &name);
54  bool storageExists(const std::string &name);
61  std::shared_ptr<JSONStorage> getOrAddStorage(const std::string &name);
66  void removeStorage(const std::string &name);
71  std::vector<std::shared_ptr<JSONStorage>> getStorages();
76  std::vector<std::shared_ptr<JSONStorage>> getTemporaryStorages();
82  std::vector<std::pair<unsigned long, std::shared_ptr<JSONStorage>>>
90  std::shared_ptr<JSONStorage> getStorage(unsigned long id);
96  unsigned long addTemporaryStorage(
97  const std::shared_ptr<JSONStorage> &storage);
102  unsigned long addTemporaryStorage();
107  void removeStorage(unsigned long id);
108 
115  std::shared_ptr<JoinManager> getOrStartJoin(
116  std::unique_ptr<joda::query::IValueProvider> &&valProv);
117 
122  void stopJoin(const joda::query::IValueProvider &valProv);
127  void stopJoin(const JoinManager &jm);
128 
138  void ensureSpace(
139  unsigned long long estimatedSize,
140  const std::shared_ptr<JSONStorage> &withoutDependency = nullptr);
141  void addDependency(const std::shared_ptr<JSONStorage> &store,
142  const std::shared_ptr<JSONStorage> &dependson);
143  size_t estimateHierarchySize(const std::shared_ptr<JSONStorage> &store) const;
144  long long estimatedStorageSize() const;
145  size_t parsedHierarchySize(const std::shared_ptr<JSONStorage> &store) const;
146  size_t estimatedSize() const;
147  size_t estimatedParsedSize() const;
148 
149  protected:
150  std::vector<JSONStorage *> getDependencies(
151  const std::shared_ptr<JSONStorage> &store) const;
152 
153  std::vector<std::pair<JSONStorage *, size_t>> chooseStoragesToRemove(
154  long long toFree, const std::vector<JSONStorage *> &except) const;
156  std::vector<std::pair<JSONStorage *, size_t>> &candidates) const;
157  void orderContainerByLRU(
158  std::vector<std::pair<JSONStorage *, size_t>> &candidates) const;
160  std::vector<std::pair<JSONStorage *, size_t>> &candidates) const;
162  std::vector<std::pair<JSONStorage *, size_t>> &candidates) const;
164  std::vector<std::pair<JSONStorage *, size_t>> &candidates) const;
165 
166  std::string getJoinName(const joda::query::IValueProvider &valProv);
167  std::unordered_map<std::string, std::shared_ptr<JSONStorage>> storages;
168  std::vector<std::string> storageInsertion;
169  std::unordered_map<unsigned long, std::shared_ptr<JSONStorage>> resultStorage;
170  std::unordered_map<std::string, std::shared_ptr<JoinManager>> runningJoins;
171  std::mutex mut;
172  std::atomic_ulong tmpRes{JODA_STORE_VALID_ID_START};
173 
174  std::unordered_set<
175  std::pair<std::shared_ptr<JSONStorage>, std::shared_ptr<JSONStorage>>,
176  boost::hash<std::pair<std::shared_ptr<JSONStorage>,
177  std::shared_ptr<JSONStorage>>>>
179 
181 
182  private:
183  friend class CollectionTest;
187 };
188 
189 #endif // JODA_STORAGECOLLECTION_H
#define JODA_STORE_VALID_ID_START
Definition: StorageCollection.h:20
Definition: CollectionTest.cpp:9
Definition: JoinManager.h:19
Definition: StorageCollection.h:27
void ensureSpace(unsigned long long estimatedSize, const std::shared_ptr< JSONStorage > &withoutDependency=nullptr)
Definition: StorageCollection.cpp:187
void orderContainerByDependencies(std::vector< std::pair< JSONStorage *, size_t >> &candidates) const
Definition: StorageCollection.cpp:327
size_t estimateHierarchySize(const std::shared_ptr< JSONStorage > &store) const
Definition: StorageCollection.cpp:371
std::vector< std::shared_ptr< JSONStorage > > getStorages()
Definition: StorageCollection.cpp:60
void orderContainerBySize(std::vector< std::pair< JSONStorage *, size_t >> &candidates) const
Definition: StorageCollection.cpp:294
void orderContainerByLRU(std::vector< std::pair< JSONStorage *, size_t >> &candidates) const
Definition: StorageCollection.cpp:303
std::shared_ptr< JSONStorage > getOrAddStorage(const std::string &name)
Definition: StorageCollection.cpp:49
virtual ~StorageCollection()
Definition: StorageCollection.cpp:167
long long estimatedStorageSize() const
Definition: StorageCollection.cpp:287
unsigned long addTemporaryStorage()
Definition: StorageCollection.cpp:88
std::string getJoinName(const joda::query::IValueProvider &valProv)
Definition: StorageCollection.cpp:151
std::shared_ptr< JSONStorage > getStorage(const std::string &name)
Definition: StorageCollection.cpp:18
size_t parsedHierarchySize(const std::shared_ptr< JSONStorage > &store) const
Definition: StorageCollection.cpp:393
void orderContainerByRandomExplorer(std::vector< std::pair< JSONStorage *, size_t >> &candidates) const
Definition: StorageCollection.cpp:431
bool storageExists(const std::string &name)
Definition: StorageCollection.cpp:93
size_t estimatedSize() const
Definition: StorageCollection.cpp:415
std::vector< std::string > storageInsertion
Definition: StorageCollection.h:168
void orderContainerByFIFO(std::vector< std::pair< JSONStorage *, size_t >> &candidates) const
Definition: StorageCollection.cpp:312
std::unordered_map< unsigned long, std::shared_ptr< JSONStorage > > resultStorage
Definition: StorageCollection.h:169
void operator=(StorageCollection const &)=delete
static StorageCollection & getInstance()
Definition: StorageCollection.h:32
friend class CollectionTest_DEPENDENCIES_Test
Definition: StorageCollection.h:186
void removeStorage(const std::string &name)
Definition: StorageCollection.cpp:27
size_t estimatedParsedSize() const
Definition: StorageCollection.cpp:423
std::shared_ptr< JoinManager > getOrStartJoin(std::unique_ptr< joda::query::IValueProvider > &&valProv)
Definition: StorageCollection.cpp:118
StorageCollection(StorageCollection const &)=delete
std::unordered_map< std::string, std::shared_ptr< JoinManager > > runningJoins
Definition: StorageCollection.h:170
std::atomic_ulong tmpRes
Definition: StorageCollection.h:172
std::vector< JSONStorage * > getDependencies(const std::shared_ptr< JSONStorage > &store) const
Definition: StorageCollection.cpp:353
std::unordered_set< std::pair< std::shared_ptr< JSONStorage >, std::shared_ptr< JSONStorage > >, boost::hash< std::pair< std::shared_ptr< JSONStorage >, std::shared_ptr< JSONStorage > > > > dependencies
Definition: StorageCollection.h:178
std::unordered_map< std::string, std::shared_ptr< JSONStorage > > storages
Definition: StorageCollection.h:167
friend class CollectionTest_LARGEST_Test
Definition: StorageCollection.h:185
friend class CollectionTest_FIFO_Test
Definition: StorageCollection.h:184
std::mutex mut
Definition: StorageCollection.h:171
void addDependency(const std::shared_ptr< JSONStorage > &store, const std::shared_ptr< JSONStorage > &dependson)
Definition: StorageCollection.cpp:346
StorageCollection()
Definition: StorageCollection.h:180
std::vector< std::pair< JSONStorage *, size_t > > chooseStoragesToRemove(long long toFree, const std::vector< JSONStorage * > &except) const
Definition: StorageCollection.cpp:243
std::vector< std::pair< unsigned long, std::shared_ptr< JSONStorage > > > getTemporaryIDStorages()
Definition: StorageCollection.cpp:109
std::vector< std::shared_ptr< JSONStorage > > getTemporaryStorages()
Definition: StorageCollection.cpp:99
void stopJoin(const joda::query::IValueProvider &valProv)
Definition: StorageCollection.cpp:144
Definition: IValueProvider.h:143