]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/filestore/IndexManager.h
buildsys: change download over to reef release
[ceph.git] / ceph / src / os / filestore / IndexManager.h
CommitLineData
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#ifndef OS_INDEXMANAGER_H
15#define OS_INDEXMANAGER_H
16
7c673cae
FG
17#include "include/unordered_map.h"
18
9f95a23c 19#include "common/ceph_mutex.h"
7c673cae
FG
20#include "common/Cond.h"
21#include "common/config.h"
22#include "common/debug.h"
23
24#include "CollectionIndex.h"
25#include "HashIndex.h"
26
27
28/// Public type for Index
29struct Index {
30 CollectionIndex *index;
31
32 Index() : index(NULL) {}
33 explicit Index(CollectionIndex* index) : index(index) {}
34
35 CollectionIndex *operator->() { return index; }
36 CollectionIndex &operator*() { return *index; }
37};
38
39
40/**
41 * Encapsulates mutual exclusion for CollectionIndexes.
42 *
43 * Allowing a modification (removal or addition of an object) to occur
11fdf7f2 44 * while a read is occurring (lookup of an object's path and use of
7c673cae
FG
45 * that path) may result in the path becoming invalid. Thus, during
46 * the lifetime of a CollectionIndex object and any paths returned
47 * by it, no other concurrent accesses may be allowed.
48 * This is enforced by using CollectionIndex::access_lock
49 */
50class IndexManager {
51 CephContext* cct;
9f95a23c
TL
52 /// Lock for Index Manager
53 ceph::shared_mutex lock = ceph::make_shared_mutex("IndexManager lock");
7c673cae
FG
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);
70public:
71 /// Constructor
72 explicit IndexManager(CephContext* cct,
73 bool upgrade) : cct(cct),
7c673cae
FG
74 upgrade(upgrade) {}
75
76 ~IndexManager();
77
78 /**
79 * Reserve and return index for c
80 *
81 * @param [in] c Collection for which to get index
82 * @param [in] baseDir base directory of collections
83 * @param [out] index Index for c
84 * @return error code
85 */
f67539c2 86 int get_index(coll_t c, const std::string& baseDir, Index *index);
7c673cae
FG
87
88 /**
89 * Initialize index for collection c at path
90 *
91 * @param [in] c Collection for which to init Index
92 * @param [in] path Path to collection
93 * @param [in] filestore_version version of containing FileStore
94 * @return error code
95 */
96 int init_index(coll_t c, const char *path, uint32_t filestore_version);
97};
98
99#endif