]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/filestore/IndexManager.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / os / filestore / IndexManager.h
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 #ifndef OS_INDEXMANAGER_H
15 #define OS_INDEXMANAGER_H
16
17 #include "include/memory.h"
18 #include "include/unordered_map.h"
19
20 #include "common/Mutex.h"
21 #include "common/Cond.h"
22 #include "common/config.h"
23 #include "common/debug.h"
24
25 #include "CollectionIndex.h"
26 #include "HashIndex.h"
27
28
29 /// Public type for Index
30 struct Index {
31 CollectionIndex *index;
32
33 Index() : index(NULL) {}
34 explicit Index(CollectionIndex* index) : index(index) {}
35
36 CollectionIndex *operator->() { return index; }
37 CollectionIndex &operator*() { return *index; }
38 };
39
40
41 /**
42 * Encapsulates mutual exclusion for CollectionIndexes.
43 *
44 * Allowing a modification (removal or addition of an object) to occur
45 * while a read is occuring (lookup of an object's path and use of
46 * that path) may result in the path becoming invalid. Thus, during
47 * the lifetime of a CollectionIndex object and any paths returned
48 * by it, no other concurrent accesses may be allowed.
49 * This is enforced by using CollectionIndex::access_lock
50 */
51 class IndexManager {
52 CephContext* cct;
53 RWLock lock; ///< Lock for Index Manager
54 bool upgrade;
55 ceph::unordered_map<coll_t, CollectionIndex* > col_indices;
56
57 /**
58 * Index factory
59 *
60 * Encapsulates logic for handling legacy FileStore
61 * layouts
62 *
63 * @param [in] c Collection for which to get index
64 * @param [in] path Path to collection
65 * @param [out] index Index for c
66 * @return error code
67 */
68 int build_index(coll_t c, const char *path, CollectionIndex **index);
69 bool get_index_optimistic(coll_t c, Index *index);
70 public:
71 /// Constructor
72 explicit IndexManager(CephContext* cct,
73 bool upgrade) : cct(cct),
74 lock("IndexManager lock"),
75 upgrade(upgrade) {}
76
77 ~IndexManager();
78
79 /**
80 * Reserve and return index for c
81 *
82 * @param [in] c Collection for which to get index
83 * @param [in] baseDir base directory of collections
84 * @param [out] index Index for c
85 * @return error code
86 */
87 int get_index(coll_t c, const string& baseDir, Index *index);
88
89 /**
90 * Initialize index for collection c at path
91 *
92 * @param [in] c Collection for which to init Index
93 * @param [in] path Path to collection
94 * @param [in] filestore_version version of containing FileStore
95 * @return error code
96 */
97 int init_index(coll_t c, const char *path, uint32_t filestore_version);
98 };
99
100 #endif