]>
git.proxmox.com Git - ceph.git/blob - 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
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.
14 #ifndef OS_INDEXMANAGER_H
15 #define OS_INDEXMANAGER_H
17 #include "include/memory.h"
18 #include "include/unordered_map.h"
20 #include "common/Mutex.h"
21 #include "common/Cond.h"
22 #include "common/config.h"
23 #include "common/debug.h"
25 #include "CollectionIndex.h"
26 #include "HashIndex.h"
29 /// Public type for Index
31 CollectionIndex
*index
;
33 Index() : index(NULL
) {}
34 explicit Index(CollectionIndex
* index
) : index(index
) {}
36 CollectionIndex
*operator->() { return index
; }
37 CollectionIndex
&operator*() { return *index
; }
42 * Encapsulates mutual exclusion for CollectionIndexes.
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
53 RWLock lock
; ///< Lock for Index Manager
55 ceph::unordered_map
<coll_t
, CollectionIndex
* > col_indices
;
60 * Encapsulates logic for handling legacy FileStore
63 * @param [in] c Collection for which to get index
64 * @param [in] path Path to collection
65 * @param [out] index Index for c
68 int build_index(coll_t c
, const char *path
, CollectionIndex
**index
);
69 bool get_index_optimistic(coll_t c
, Index
*index
);
72 explicit IndexManager(CephContext
* cct
,
73 bool upgrade
) : cct(cct
),
74 lock("IndexManager lock"),
80 * Reserve and return index for c
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
87 int get_index(coll_t c
, const string
& baseDir
, Index
*index
);
90 * Initialize index for collection c at path
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
97 int init_index(coll_t c
, const char *path
, uint32_t filestore_version
);