OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CachingForeignStorageMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "ForeignStorageCache.h"
20 #include "ForeignStorageMgr.h"
21 
22 namespace foreign_storage {
23 
24 /*
25  A version of the ForeignStorageMgr that incorporates disk caching.
26  */
28  public:
30 
31  void fetchBuffer(const ChunkKey& chunk_key,
32  AbstractBuffer* destination_buffer,
33  const size_t num_bytes) override;
34 
36  const ChunkKey& chunk_key_prefix) override;
37 
39  const ChunkKey& chunk_key_prefix);
40 
41  void removeTableRelatedDS(const int db_id, const int table_id) override;
42 
43  void refreshTable(const ChunkKey& table_key, const bool evict_cached_entries) override;
44 
45  bool createDataWrapperIfNotExists(const ChunkKey& chunk_key) override;
46 
47  bool hasStoredDataWrapper(int32_t db, int32_t tb) const;
48 
49  private:
50  void refreshTableInCache(const ChunkKey& table_key);
51 
52  int getHighestCachedFragId(const ChunkKey& table_key);
53 
54  void refreshAppendTableInCache(const ChunkKey& table_key,
55  const std::vector<ChunkKey>& old_chunk_keys);
56 
57  void refreshNonAppendTableInCache(const ChunkKey& table_key,
58  const std::vector<ChunkKey>& old_chunk_keys);
59 
60  void refreshChunksInCacheByFragment(const std::vector<ChunkKey>& old_chunk_keys,
61  int last_frag_id);
62 
64  ChunkToBufferMap& required_buffers,
65  ChunkToBufferMap& optional_buffers);
66 
67  void eraseDataWrapper(const ChunkKey& key) override;
68 
69  void clearTable(const ChunkKey& table_key);
70 
71  size_t maxFetchSize(int32_t db_id) const override;
72 
73  bool hasMaxFetchSize() const override;
74 
75  std::set<ChunkKey> getOptionalKeysWithinSizeLimit(
76  const ChunkKey& chunk_key,
77  const std::set<ChunkKey, decltype(set_comp)*>& same_fragment_keys,
78  const std::set<ChunkKey, decltype(set_comp)*>& diff_fragment_keys) const override;
79 
80  bool isChunkCached(const ChunkKey& chunk_key) const override;
81 
82  void evictChunkFromCache(const ChunkKey& chunk_key) override;
83 
84  size_t getBufferSize(const ChunkKey& key) const;
85 
86  size_t getRequiredBuffersSize(const ChunkKey& chunk_key) const;
87 
89 };
90 
91 } // namespace foreign_storage
bool set_comp(const ChunkKey &left, const ChunkKey &right)
void refreshAppendTableInCache(const ChunkKey &table_key, const std::vector< ChunkKey > &old_chunk_keys)
std::vector< int > ChunkKey
Definition: types.h:36
size_t getBufferSize(const ChunkKey &key) const
bool hasStoredDataWrapper(int32_t db, int32_t tb) const
size_t maxFetchSize(int32_t db_id) const override
std::map< ChunkKey, AbstractBuffer * > ChunkToBufferMap
This file includes the class specification for the cache used by the Foreign Storage Interface (FSI)...
void refreshTableInCache(const ChunkKey &table_key)
std::set< ChunkKey > getOptionalKeysWithinSizeLimit(const ChunkKey &chunk_key, const std::set< ChunkKey, decltype(set_comp)* > &same_fragment_keys, const std::set< ChunkKey, decltype(set_comp)* > &diff_fragment_keys) const override
void eraseDataWrapper(const ChunkKey &key) override
void getChunkMetadataVecFromDataWrapper(ChunkMetadataVector &chunk_metadata, const ChunkKey &chunk_key_prefix)
void refreshNonAppendTableInCache(const ChunkKey &table_key, const std::vector< ChunkKey > &old_chunk_keys)
void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector &chunk_metadata, const ChunkKey &chunk_key_prefix) override
void refreshChunksInCacheByFragment(const std::vector< ChunkKey > &old_chunk_keys, int last_frag_id)
bool createDataWrapperIfNotExists(const ChunkKey &chunk_key) override
void evictChunkFromCache(const ChunkKey &chunk_key) override
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
An AbstractBuffer is a unit of data management for a data manager.
void populateChunkBuffersSafely(ForeignDataWrapper &data_wrapper, ChunkToBufferMap &required_buffers, ChunkToBufferMap &optional_buffers)
void refreshTable(const ChunkKey &table_key, const bool evict_cached_entries) override
bool isChunkCached(const ChunkKey &chunk_key) const override
void fetchBuffer(const ChunkKey &chunk_key, AbstractBuffer *destination_buffer, const size_t num_bytes) override
void removeTableRelatedDS(const int db_id, const int table_id) override
size_t getRequiredBuffersSize(const ChunkKey &chunk_key) const
int getHighestCachedFragId(const ChunkKey &table_key)