]>
git.proxmox.com Git - ceph.git/blob - ceph/src/os/filestore/CollectionIndex.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef OS_COLLECTIONINDEX_H
16 #define OS_COLLECTIONINDEX_H
21 #include "osd/osd_types.h"
22 #include "include/object.h"
25 CollectionIndex provides an interface for manipulating indexed collections
27 class CollectionIndex
{
32 * Object encapsulating a returned path.
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.
45 std::string full_path
;
46 /// Ref to parent Index
47 CollectionIndex
* parent_ref
;
48 /// coll_t for parent Index
51 /// Normal Constructor
53 std::string path
, ///< [in] Path to return.
55 : full_path(path
), parent_ref(ref
), parent_coll(parent_ref
->coll()) {}
57 /// Debugging Constructor
59 std::string path
, ///< [in] Path to return.
60 const coll_t
& coll
) ///< [in] collection
61 : full_path(path
), parent_coll(coll
) {}
63 /// Getter for the stored path.
64 const char *path() const { return full_path
.c_str(); }
66 /// Getter for collection
67 const coll_t
& coll() const { return parent_coll
; }
70 CollectionIndex
* get_index() const {
76 ceph::shared_mutex access_lock
=
77 ceph::make_shared_mutex("CollectionIndex::access_lock", true, false);
78 /// Type of returned paths
79 typedef std::shared_ptr
<Path
> IndexedPath
;
81 static IndexedPath
get_testing_path(std::string path
, coll_t collection
) {
82 return std::make_shared
<Path
>(path
, collection
);
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;
90 * For tracking Filestore collection versions.
92 * @return Collection version represented by the Index implementation
94 virtual uint32_t collection_version() = 0;
97 * Returns the collection managed by this CollectionIndex
99 virtual coll_t
coll() const = 0;
103 * Initializes the index.
105 * @return Error Code, 0 for success
107 virtual int init() = 0;
110 * Cleanup before replaying journal
112 * Index implementations may need to perform compound operations
113 * which may leave the collection unstable if interrupted. cleanup
114 * is called on mount to allow the CollectionIndex implementation
118 * @return Error Code, 0 for success
120 virtual int cleanup() = 0;
123 * Call when a file is created using a path returned from lookup.
125 * @return Error Code, 0 for success
128 const ghobject_t
&oid
, ///< [in] Created object.
129 const char *path
///< [in] Path to created object.
133 * Removes oid from the collection
135 * @return Error Code, 0 for success
138 const ghobject_t
&oid
///< [in] Object to remove
142 * Gets the IndexedPath for oid.
144 * @return Error Code, 0 for success
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.
153 * Moves objects matching @e match in the lsb @e bits
155 * dest and this must be the same subclass
157 * @return Error Code, 0 for success
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; }
166 uint32_t bits
, //< [in] common (target) bits
167 CollectionIndex
* dest
//< [in] destination index
168 ) { ceph_abort(); return 0; }
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
176 std::vector
<ghobject_t
> *ls
, ///< [out] Listed objects
177 ghobject_t
*next
///< [out] Next object to list
180 /// Call prior to removing directory
181 virtual int prep_delete() { return 0; }
183 CollectionIndex(CephContext
* cct
, const coll_t
& collection
)
187 * Pre-hash the collection, this collection should map to a PG folder.
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.
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; }
198 virtual int apply_layout_settings(int target_level
) { ceph_abort(); return 0; }
200 /// Read index-wide settings (should be called after construction)
201 virtual int read_settings() { return 0; }
203 /// Virtual destructor
204 virtual ~CollectionIndex() {}