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