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_KEYVALUESTORE_H
16 #define OS_KEYVALUESTORE_H
21 #include "kv/KeyValueDB.h"
22 #include "common/hobject.h"
24 class SequencerPosition;
27 * Encapsulates the FileStore key value store
29 * Implementations of this interface will be used to implement TMAP
34 boost::scoped_ptr<KeyValueDB> db;
35 /// std::Set keys and values from specified map
37 const ghobject_t &oid, ///< [in] object containing map
38 const std::map<std::string, ceph::buffer::list> &set, ///< [in] key to value map to set
39 const SequencerPosition *spos=0 ///< [in] sequencer position
43 virtual int set_header(
44 const ghobject_t &oid, ///< [in] object containing map
45 const ceph::buffer::list &bl, ///< [in] header to set
46 const SequencerPosition *spos=0 ///< [in] sequencer position
50 virtual int get_header(
51 const ghobject_t &oid, ///< [in] object containing map
52 ceph::buffer::list *bl ///< [out] header to set
55 /// Clear all map keys and values from oid
57 const ghobject_t &oid, ///< [in] object containing map
58 const SequencerPosition *spos=0 ///< [in] sequencer position
61 /// Clear all map keys and values in to_clear from oid
63 const ghobject_t &oid, ///< [in] object containing map
64 const std::set<std::string> &to_clear, ///< [in] Keys to clear
65 const SequencerPosition *spos=0 ///< [in] sequencer position
68 /// Clear all omap keys and the header
69 virtual int clear_keys_header(
70 const ghobject_t &oid, ///< [in] oid to clear
71 const SequencerPosition *spos=0 ///< [in] sequencer position
74 /// Get all keys and values
76 const ghobject_t &oid, ///< [in] object containing map
77 ceph::buffer::list *header, ///< [out] Returned Header
78 std::map<std::string, ceph::buffer::list> *out ///< [out] Returned keys and values
81 /// Get values for supplied keys
83 const ghobject_t &oid, ///< [in] object containing map
84 std::set<std::string> *keys ///< [out] Keys defined on oid
87 /// Get values for supplied keys
88 virtual int get_values(
89 const ghobject_t &oid, ///< [in] object containing map
90 const std::set<std::string> &keys, ///< [in] Keys to get
91 std::map<std::string, ceph::buffer::list> *out ///< [out] Returned keys and values
94 /// Check key existence
95 virtual int check_keys(
96 const ghobject_t &oid, ///< [in] object containing map
97 const std::set<std::string> &keys, ///< [in] Keys to check
98 std::set<std::string> *out ///< [out] Subset of keys defined on oid
102 virtual int get_xattrs(
103 const ghobject_t &oid, ///< [in] object
104 const std::set<std::string> &to_get, ///< [in] keys to get
105 std::map<std::string, ceph::buffer::list> *out ///< [out] subset of attrs/vals defined
109 virtual int get_all_xattrs(
110 const ghobject_t &oid, ///< [in] object
111 std::set<std::string> *out ///< [out] attrs and values
114 /// std::set xattrs in to_set
115 virtual int set_xattrs(
116 const ghobject_t &oid, ///< [in] object
117 const std::map<std::string, ceph::buffer::list> &to_set,///< [in] attrs/values to set
118 const SequencerPosition *spos=0 ///< [in] sequencer position
121 /// remove xattrs in to_remove
122 virtual int remove_xattrs(
123 const ghobject_t &oid, ///< [in] object
124 const std::set<std::string> &to_remove, ///< [in] attrs to remove
125 const SequencerPosition *spos=0 ///< [in] sequencer position
129 /// Clone keys from oid map to target map
131 const ghobject_t &oid, ///< [in] object containing map
132 const ghobject_t &target, ///< [in] target of clone
133 const SequencerPosition *spos=0 ///< [in] sequencer position
136 /// Rename map because of name change
138 const ghobject_t &from, ///< [in] object containing map
139 const ghobject_t &to, ///< [in] new name
140 const SequencerPosition *spos=0 ///< [in] sequencer position
143 /// For testing clone keys from oid map to target map using faster but more complex method
144 virtual int legacy_clone(
145 const ghobject_t &oid, ///< [in] object containing map
146 const ghobject_t &target, ///< [in] target of clone
147 const SequencerPosition *spos=0 ///< [in] sequencer position
150 /// Ensure all previous writes are durable
152 const ghobject_t *oid=0, ///< [in] object
153 const SequencerPosition *spos=0 ///< [in] Sequencer
156 virtual int check(std::ostream &out, bool repair = false, bool force = false) { return 0; }
158 virtual void compact() {}
160 typedef KeyValueDB::SimplestIteratorImpl ObjectMapIteratorImpl;
161 typedef std::shared_ptr<ObjectMapIteratorImpl> ObjectMapIterator;
162 virtual ObjectMapIterator get_iterator(const ghobject_t &oid) {
163 return ObjectMapIterator();
166 virtual KeyValueDB *get_db() { return nullptr; }
168 ObjectMap(CephContext* cct, KeyValueDB *db) : cct(cct), db(db) {}
169 virtual ~ObjectMap() {}