diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/os/filestore/IndexManager.h | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/os/filestore/IndexManager.h')
-rw-r--r-- | src/os/filestore/IndexManager.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/os/filestore/IndexManager.h b/src/os/filestore/IndexManager.h new file mode 100644 index 00000000..19cd2926 --- /dev/null +++ b/src/os/filestore/IndexManager.h @@ -0,0 +1,99 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ +#ifndef OS_INDEXMANAGER_H +#define OS_INDEXMANAGER_H + +#include "include/unordered_map.h" + +#include "common/Mutex.h" +#include "common/Cond.h" +#include "common/config.h" +#include "common/debug.h" + +#include "CollectionIndex.h" +#include "HashIndex.h" + + +/// Public type for Index +struct Index { + CollectionIndex *index; + + Index() : index(NULL) {} + explicit Index(CollectionIndex* index) : index(index) {} + + CollectionIndex *operator->() { return index; } + CollectionIndex &operator*() { return *index; } +}; + + +/** + * Encapsulates mutual exclusion for CollectionIndexes. + * + * Allowing a modification (removal or addition of an object) to occur + * while a read is occurring (lookup of an object's path and use of + * that path) may result in the path becoming invalid. Thus, during + * the lifetime of a CollectionIndex object and any paths returned + * by it, no other concurrent accesses may be allowed. + * This is enforced by using CollectionIndex::access_lock + */ +class IndexManager { + CephContext* cct; + RWLock lock; ///< Lock for Index Manager + bool upgrade; + ceph::unordered_map<coll_t, CollectionIndex* > col_indices; + + /** + * Index factory + * + * Encapsulates logic for handling legacy FileStore + * layouts + * + * @param [in] c Collection for which to get index + * @param [in] path Path to collection + * @param [out] index Index for c + * @return error code + */ + int build_index(coll_t c, const char *path, CollectionIndex **index); + bool get_index_optimistic(coll_t c, Index *index); +public: + /// Constructor + explicit IndexManager(CephContext* cct, + bool upgrade) : cct(cct), + lock("IndexManager lock"), + upgrade(upgrade) {} + + ~IndexManager(); + + /** + * Reserve and return index for c + * + * @param [in] c Collection for which to get index + * @param [in] baseDir base directory of collections + * @param [out] index Index for c + * @return error code + */ + int get_index(coll_t c, const string& baseDir, Index *index); + + /** + * Initialize index for collection c at path + * + * @param [in] c Collection for which to init Index + * @param [in] path Path to collection + * @param [in] filestore_version version of containing FileStore + * @return error code + */ + int init_index(coll_t c, const char *path, uint32_t filestore_version); +}; + +#endif |