Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
eviction_policy.h
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #ifndef PLASMA_EVICTION_POLICY_H
19 #define PLASMA_EVICTION_POLICY_H
20 
21 #include <list>
22 #include <unordered_map>
23 #include <utility>
24 #include <vector>
25 
26 #include "plasma/common.h"
27 #include "plasma/plasma.h"
28 
29 namespace plasma {
30 
31 // ==== The eviction policy ====
32 //
33 // This file contains declaration for all functions and data structures that
34 // need to be provided if you want to implement a new eviction algorithm for the
35 // Plasma store.
36 
37 class LRUCache {
38  public:
39  LRUCache() {}
40 
41  void add(const ObjectID& key, int64_t size);
42 
43  void remove(const ObjectID& key);
44 
45  int64_t choose_objects_to_evict(int64_t num_bytes_required,
46  std::vector<ObjectID>* objects_to_evict);
47 
48  private:
51  typedef std::list<std::pair<ObjectID, int64_t>> ItemList;
52  ItemList item_list_;
55  std::unordered_map<ObjectID, ItemList::iterator, UniqueIDHasher> item_map_;
56 };
57 
60  public:
65  explicit EvictionPolicy(PlasmaStoreInfo* store_info);
66 
73  void object_created(const ObjectID& object_id);
74 
86  bool require_space(int64_t size, std::vector<ObjectID>* objects_to_evict);
87 
96  void begin_object_access(const ObjectID& object_id,
97  std::vector<ObjectID>* objects_to_evict);
98 
107  void end_object_access(const ObjectID& object_id,
108  std::vector<ObjectID>* objects_to_evict);
109 
121  int64_t choose_objects_to_evict(int64_t num_bytes_required,
122  std::vector<ObjectID>* objects_to_evict);
123 
124  private:
126  int64_t memory_used_;
128  PlasmaStoreInfo* store_info_;
130  LRUCache cache_;
131 };
132 
133 } // namespace plasma
134 
135 #endif // PLASMA_EVICTION_POLICY_H
Definition: eviction_policy.h:37
The plasma store information that is exposed to the eviction policy.
Definition: plasma.h:129
LRUCache()
Definition: eviction_policy.h:39
int64_t choose_objects_to_evict(int64_t num_bytes_required, std::vector< ObjectID > *objects_to_evict)
Definition: common.h:38
void add(const ObjectID &key, int64_t size)
Definition: client.h:35
The eviction policy.
Definition: eviction_policy.h:59