]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef OS_COLLECTIONINDEX_H | |
16 | #define OS_COLLECTIONINDEX_H | |
17 | ||
18 | #include <string> | |
19 | #include <vector> | |
7c673cae FG |
20 | |
21 | #include "osd/osd_types.h" | |
22 | #include "include/object.h" | |
7c673cae FG |
23 | |
24 | /** | |
25 | CollectionIndex provides an interface for manipulating indexed collections | |
26 | */ | |
27 | class CollectionIndex { | |
28 | public: | |
29 | CephContext* cct; | |
30 | protected: | |
31 | /** | |
32 | * Object encapsulating a returned path. | |
33 | * | |
34 | * A path to an object (existent or non-existent) becomes invalid | |
35 | * when a different object is created in the index. Path stores | |
36 | * a shared_ptr to the CollectionIndex to keep the index alive | |
37 | * during its lifetime. | |
38 | * @see IndexManager | |
39 | * @see self_ref | |
40 | * @see set_ref | |
41 | */ | |
42 | class Path { | |
43 | public: | |
44 | /// Returned path | |
f67539c2 | 45 | std::string full_path; |
7c673cae FG |
46 | /// Ref to parent Index |
47 | CollectionIndex* parent_ref; | |
48 | /// coll_t for parent Index | |
49 | coll_t parent_coll; | |
50 | ||
51 | /// Normal Constructor | |
52 | Path( | |
f67539c2 | 53 | std::string path, ///< [in] Path to return. |
7c673cae FG |
54 | CollectionIndex* ref) |
55 | : full_path(path), parent_ref(ref), parent_coll(parent_ref->coll()) {} | |
56 | ||
57 | /// Debugging Constructor | |
58 | Path( | |
f67539c2 | 59 | std::string path, ///< [in] Path to return. |
7c673cae FG |
60 | const coll_t& coll) ///< [in] collection |
61 | : full_path(path), parent_coll(coll) {} | |
62 | ||
63 | /// Getter for the stored path. | |
64 | const char *path() const { return full_path.c_str(); } | |
65 | ||
66 | /// Getter for collection | |
67 | const coll_t& coll() const { return parent_coll; } | |
68 | ||
69 | /// Getter for parent | |
70 | CollectionIndex* get_index() const { | |
71 | return parent_ref; | |
72 | } | |
73 | }; | |
74 | public: | |
75 | ||
9f95a23c TL |
76 | ceph::shared_mutex access_lock = |
77 | ceph::make_shared_mutex("CollectionIndex::access_lock", true, false); | |
7c673cae | 78 | /// Type of returned paths |
11fdf7f2 | 79 | typedef std::shared_ptr<Path> IndexedPath; |
7c673cae | 80 | |
f67539c2 | 81 | static IndexedPath get_testing_path(std::string path, coll_t collection) { |
7c673cae FG |
82 | return std::make_shared<Path>(path, collection); |
83 | } | |
84 | ||
85 | static const uint32_t FLAT_INDEX_TAG = 0; | |
86 | static const uint32_t HASH_INDEX_TAG = 1; | |
87 | static const uint32_t HASH_INDEX_TAG_2 = 2; | |
88 | static const uint32_t HOBJECT_WITH_POOL = 3; | |
89 | /** | |
90 | * For tracking Filestore collection versions. | |
91 | * | |
92 | * @return Collection version represented by the Index implementation | |
93 | */ | |
94 | virtual uint32_t collection_version() = 0; | |
95 | ||
96 | /** | |
97 | * Returns the collection managed by this CollectionIndex | |
98 | */ | |
99 | virtual coll_t coll() const = 0; | |
100 | ||
101 | ||
102 | /** | |
103 | * Initializes the index. | |
104 | * | |
105 | * @return Error Code, 0 for success | |
106 | */ | |
107 | virtual int init() = 0; | |
108 | ||
109 | /** | |
110 | * Cleanup before replaying journal | |
111 | * | |
11fdf7f2 TL |
112 | * Index implementations may need to perform compound operations |
113 | * which may leave the collection unstable if interrupted. cleanup | |
7c673cae FG |
114 | * is called on mount to allow the CollectionIndex implementation |
115 | * to stabilize. | |
116 | * | |
117 | * @see HashIndex | |
118 | * @return Error Code, 0 for success | |
119 | */ | |
120 | virtual int cleanup() = 0; | |
121 | ||
122 | /** | |
123 | * Call when a file is created using a path returned from lookup. | |
124 | * | |
125 | * @return Error Code, 0 for success | |
126 | */ | |
127 | virtual int created( | |
128 | const ghobject_t &oid, ///< [in] Created object. | |
129 | const char *path ///< [in] Path to created object. | |
130 | ) = 0; | |
131 | ||
132 | /** | |
133 | * Removes oid from the collection | |
134 | * | |
135 | * @return Error Code, 0 for success | |
136 | */ | |
137 | virtual int unlink( | |
138 | const ghobject_t &oid ///< [in] Object to remove | |
139 | ) = 0; | |
140 | ||
141 | /** | |
142 | * Gets the IndexedPath for oid. | |
143 | * | |
144 | * @return Error Code, 0 for success | |
145 | */ | |
146 | virtual int lookup( | |
147 | const ghobject_t &oid, ///< [in] Object to lookup | |
148 | IndexedPath *path, ///< [out] Path to object | |
149 | int *hardlink ///< [out] number of hard links of this object. *hardlink=0 mean object no-exist. | |
150 | ) = 0; | |
151 | ||
152 | /** | |
153 | * Moves objects matching @e match in the lsb @e bits | |
154 | * | |
155 | * dest and this must be the same subclass | |
156 | * | |
157 | * @return Error Code, 0 for success | |
158 | */ | |
159 | virtual int split( | |
160 | uint32_t match, //< [in] value to match | |
161 | uint32_t bits, //< [in] bits to check | |
162 | CollectionIndex* dest //< [in] destination index | |
163 | ) { ceph_abort(); return 0; } | |
164 | ||
11fdf7f2 TL |
165 | virtual int merge( |
166 | uint32_t bits, //< [in] common (target) bits | |
167 | CollectionIndex* dest //< [in] destination index | |
168 | ) { ceph_abort(); return 0; } | |
169 | ||
7c673cae FG |
170 | |
171 | /// List contents of collection by hash | |
172 | virtual int collection_list_partial( | |
173 | const ghobject_t &start, ///< [in] object at which to start | |
174 | const ghobject_t &end, ///< [in] list only objects < end | |
175 | int max_count, ///< [in] return at most max_count objects | |
f67539c2 | 176 | std::vector<ghobject_t> *ls, ///< [out] Listed objects |
7c673cae FG |
177 | ghobject_t *next ///< [out] Next object to list |
178 | ) = 0; | |
179 | ||
180 | /// Call prior to removing directory | |
181 | virtual int prep_delete() { return 0; } | |
182 | ||
183 | CollectionIndex(CephContext* cct, const coll_t& collection) | |
9f95a23c | 184 | : cct(cct) {} |
7c673cae FG |
185 | |
186 | /* | |
187 | * Pre-hash the collection, this collection should map to a PG folder. | |
188 | * | |
189 | * @param pg_num - pg number of the pool this collection belongs to. | |
190 | * @param expected_num_objs - expected number of objects in this collection. | |
191 | * @Return 0 on success, an error code otherwise. | |
192 | */ | |
193 | virtual int pre_hash_collection( | |
194 | uint32_t pg_num, ///< [in] pg number of the pool this collection belongs to | |
195 | uint64_t expected_num_objs ///< [in] expected number of objects this collection has | |
196 | ) { ceph_abort(); return 0; } | |
197 | ||
1adf2230 | 198 | virtual int apply_layout_settings(int target_level) { ceph_abort(); return 0; } |
7c673cae | 199 | |
224ce89b WB |
200 | /// Read index-wide settings (should be called after construction) |
201 | virtual int read_settings() { return 0; } | |
202 | ||
7c673cae FG |
203 | /// Virtual destructor |
204 | virtual ~CollectionIndex() {} | |
205 | }; | |
206 | ||
207 | #endif |