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
20 #include "include/memory.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 /// Set keys and values from specified map
36 const ghobject_t &oid, ///< [in] object containing map
37 const map<string, bufferlist> &set, ///< [in] key to value map to set
38 const SequencerPosition *spos=0 ///< [in] sequencer position
42 virtual int set_header(
43 const ghobject_t &oid, ///< [in] object containing map
44 const bufferlist &bl, ///< [in] header to set
45 const SequencerPosition *spos=0 ///< [in] sequencer position
49 virtual int get_header(
50 const ghobject_t &oid, ///< [in] object containing map
51 bufferlist *bl ///< [out] header to set
54 /// Clear all map keys and values from oid
56 const ghobject_t &oid, ///< [in] object containing map
57 const SequencerPosition *spos=0 ///< [in] sequencer position
60 /// Clear all map keys and values in to_clear from oid
62 const ghobject_t &oid, ///< [in] object containing map
63 const set<string> &to_clear, ///< [in] Keys to clear
64 const SequencerPosition *spos=0 ///< [in] sequencer position
67 /// Clear all omap keys and the header
68 virtual int clear_keys_header(
69 const ghobject_t &oid, ///< [in] oid to clear
70 const SequencerPosition *spos=0 ///< [in] sequencer position
73 /// Get all keys and values
75 const ghobject_t &oid, ///< [in] object containing map
76 bufferlist *header, ///< [out] Returned Header
77 map<string, bufferlist> *out ///< [out] Returned keys and values
80 /// Get values for supplied keys
82 const ghobject_t &oid, ///< [in] object containing map
83 set<string> *keys ///< [out] Keys defined on oid
86 /// Get values for supplied keys
87 virtual int get_values(
88 const ghobject_t &oid, ///< [in] object containing map
89 const set<string> &keys, ///< [in] Keys to get
90 map<string, bufferlist> *out ///< [out] Returned keys and values
93 /// Check key existence
94 virtual int check_keys(
95 const ghobject_t &oid, ///< [in] object containing map
96 const set<string> &keys, ///< [in] Keys to check
97 set<string> *out ///< [out] Subset of keys defined on oid
101 virtual int get_xattrs(
102 const ghobject_t &oid, ///< [in] object
103 const set<string> &to_get, ///< [in] keys to get
104 map<string, bufferlist> *out ///< [out] subset of attrs/vals defined
108 virtual int get_all_xattrs(
109 const ghobject_t &oid, ///< [in] object
110 set<string> *out ///< [out] attrs and values
113 /// set xattrs in to_set
114 virtual int set_xattrs(
115 const ghobject_t &oid, ///< [in] object
116 const map<string, bufferlist> &to_set,///< [in] attrs/values to set
117 const SequencerPosition *spos=0 ///< [in] sequencer position
120 /// remove xattrs in to_remove
121 virtual int remove_xattrs(
122 const ghobject_t &oid, ///< [in] object
123 const set<string> &to_remove, ///< [in] attrs to remove
124 const SequencerPosition *spos=0 ///< [in] sequencer position
128 /// Clone keys from oid map to target map
130 const ghobject_t &oid, ///< [in] object containing map
131 const ghobject_t &target, ///< [in] target of clone
132 const SequencerPosition *spos=0 ///< [in] sequencer position
135 /// Rename map because of name change
137 const ghobject_t &from, ///< [in] object containing map
138 const ghobject_t &to, ///< [in] new name
139 const SequencerPosition *spos=0 ///< [in] sequencer position
142 /// For testing clone keys from oid map to target map using faster but more complex method
143 virtual int legacy_clone(
144 const ghobject_t &oid, ///< [in] object containing map
145 const ghobject_t &target, ///< [in] target of clone
146 const SequencerPosition *spos=0 ///< [in] sequencer position
149 /// Ensure all previous writes are durable
151 const ghobject_t *oid=0, ///< [in] object
152 const SequencerPosition *spos=0 ///< [in] Sequencer
155 virtual int check(std::ostream &out, bool repair = false, bool force = false) { return 0; }
157 virtual void compact() {}
159 typedef KeyValueDB::GenericIteratorImpl ObjectMapIteratorImpl;
160 typedef ceph::shared_ptr<ObjectMapIteratorImpl> ObjectMapIterator;
161 virtual ObjectMapIterator get_iterator(const ghobject_t &oid) {
162 return ObjectMapIterator();
166 ObjectMap(CephContext* cct) : cct(cct) {}
167 virtual ~ObjectMap() {}