~ubuntu-branches/ubuntu/raring/ceph/raring

« back to all changes in this revision

Viewing changes to src/include/object.h

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2012-02-05 10:07:38 UTC
  • mfrom: (1.1.7) (0.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120205100738-00s0bxx93mamy8tk
Tags: 0.41-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "hash.h"
29
29
#include "encoding.h"
30
30
#include "ceph_hash.h"
 
31
#include "cmp.h"
31
32
 
32
33
/* Maximum supported object name length for Ceph, in bytes.
33
34
 *
43
44
  object_t() {}
44
45
  object_t(const char *s) : name(s) {}
45
46
  object_t(const string& s) : name(s) {}
 
47
 
46
48
  void swap(object_t& o) {
47
49
    name.swap(o.name);
48
50
  }
 
51
  void clear() {
 
52
    name.clear();
 
53
  }
49
54
  
50
55
  void encode(bufferlist &bl) const {
51
56
    ::encode(name, bl);
259
264
  };
260
265
}
261
266
 
 
267
typedef uint64_t filestore_hobject_key_t;
262
268
struct hobject_t {
263
269
  object_t oid;
264
270
  snapid_t snap;
265
271
  uint32_t hash;
 
272
  bool max;
266
273
 
267
274
private:
268
275
  string key;
271
278
  const string &get_key() const {
272
279
    return key;
273
280
  }
 
281
  
 
282
  hobject_t() : snap(0), hash(0), max(false) {}
274
283
 
275
 
  hobject_t() : snap(0), hash(0) {}
276
 
  hobject_t(object_t oid, const string &key, snapid_t snap, uint32_t hash) : 
277
 
    oid(oid), snap(snap), hash(hash), 
 
284
  hobject_t(object_t oid, const string& key, snapid_t snap, uint64_t hash) : 
 
285
    oid(oid), snap(snap), hash(hash), max(false),
278
286
    key(oid.name == key ? string() : key) {}
279
287
 
280
288
  hobject_t(const sobject_t &soid, const string &key, uint32_t hash) : 
281
 
    oid(soid.oid), snap(soid.snap), hash(hash),
 
289
    oid(soid.oid), snap(soid.snap), hash(hash), max(false),
282
290
    key(soid.oid.name == key ? string() : key) {}
283
291
 
284
292
  /* Do not use when a particular hash function is needed */
285
293
  explicit hobject_t(const sobject_t &o) :
286
 
    oid(o.oid), snap(o.snap) {
 
294
    oid(o.oid), snap(o.snap), max(false) {
287
295
    hash = __gnu_cxx::hash<sobject_t>()(o);
288
296
  }
289
297
 
 
298
  // maximum sorted value.
 
299
  static hobject_t get_max() {
 
300
    hobject_t h;
 
301
    h.max = true;
 
302
    return h;
 
303
  }
 
304
  bool is_max() const {
 
305
    return max;
 
306
  }
 
307
 
 
308
  static uint32_t _reverse_nibbles(uint32_t retval) {
 
309
    // reverse nibbles
 
310
    retval = ((retval & 0x0f0f0f0f) << 4) | ((retval & 0xf0f0f0f0) >> 4);
 
311
    retval = ((retval & 0x00ff00ff) << 8) | ((retval & 0xff00ff00) >> 8);
 
312
    retval = ((retval & 0x0000ffff) << 16) | ((retval & 0xffff0000) >> 16);
 
313
    return retval;
 
314
  }
 
315
 
 
316
  filestore_hobject_key_t get_filestore_key() const {
 
317
    if (max)
 
318
      return 0x100000000ull;
 
319
    else
 
320
      return _reverse_nibbles(hash);
 
321
  }
 
322
  void set_filestore_key(uint32_t v) {
 
323
    hash = _reverse_nibbles(v);
 
324
  }
 
325
 
 
326
  const string& get_effective_key() const {
 
327
    if (key.length())
 
328
      return key;
 
329
    return oid.name;
 
330
  }
 
331
 
 
332
  /**
 
333
   * back up hobject_t to beginning of hash bucket, if i am partway through one.
 
334
   */
 
335
  void back_up_to_bounding_key() {
 
336
    if (key.length()) {
 
337
      oid.clear();
 
338
    } else {
 
339
      key = oid.name;
 
340
      oid.clear();
 
341
    }
 
342
    snap = 0;
 
343
  }
 
344
 
290
345
  void swap(hobject_t &o) {
291
346
    hobject_t temp(o);
292
347
    o.oid = oid;
299
354
    hash = temp.hash;
300
355
  }
301
356
 
302
 
  operator sobject_t() const {
303
 
    return sobject_t(oid, snap);
304
 
  }
305
 
 
306
357
  void encode(bufferlist& bl) const {
307
 
    __u8 version = 1;
 
358
    __u8 version = 2;
308
359
    ::encode(version, bl);
309
360
    ::encode(key, bl);
310
361
    ::encode(oid, bl);
311
362
    ::encode(snap, bl);
312
363
    ::encode(hash, bl);
 
364
    ::encode(max, bl);
313
365
  }
314
366
  void decode(bufferlist::iterator& bl) {
315
367
    __u8 version;
319
371
    ::decode(oid, bl);
320
372
    ::decode(snap, bl);
321
373
    ::decode(hash, bl);
 
374
    if (version >= 2)
 
375
      ::decode(max, bl);
 
376
    else
 
377
      max = false;
322
378
  }
323
379
};
324
380
WRITE_CLASS_ENCODER(hobject_t)
 
381
 
325
382
namespace __gnu_cxx {
326
383
  template<> struct hash<hobject_t> {
327
 
    size_t operator()(const sobject_t &r) const {
 
384
    size_t operator()(const hobject_t &r) const {
328
385
      static hash<object_t> H;
329
386
      static rjhash<uint64_t> I;
330
387
      return H(r.oid) ^ I(r.snap);
332
389
  };
333
390
}
334
391
 
 
392
inline ostream& operator<<(ostream& out, const hobject_t& o)
 
393
{
 
394
  if (o.is_max())
 
395
    return out << "MAX";
 
396
  out << std::hex << o.hash << std::dec;
 
397
  if (o.get_key().length())
 
398
    out << "." << o.get_key();
 
399
  out << "/" << o.oid << "/" << o.snap;
 
400
  return out;
 
401
}
 
402
 
 
403
WRITE_EQ_OPERATORS_5(hobject_t, oid, get_key(), snap, hash, max)
 
404
// sort hobject_t's by <max, get_filestore_key(hash), key, oid, snapid>
 
405
WRITE_CMP_OPERATORS_5(hobject_t, max, get_filestore_key(), get_effective_key(), oid, snap)
 
406
 
 
407
 
335
408
// ---------------------------
336
409
 
337
410
#endif