forked from vitalif/vitastor
Extract object_id and obj_ver_id to separate header
parent
3061b8cf51
commit
e60e6978ac
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
crc32c.o: crc32c.c
|
crc32c.o: crc32c.c
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
%.o: %.cpp allocator.h blockstore_flush.h blockstore.h blockstore_impl.h blockstore_init.h blockstore_journal.h crc32c.h ringloop.h xor.h timerfd_interval.h
|
%.o: %.cpp allocator.h blockstore_flush.h blockstore.h blockstore_impl.h blockstore_init.h blockstore_journal.h crc32c.h ringloop.h xor.h timerfd_interval.h object_id.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd: $(BLOCKSTORE_OBJS) osd_main.cpp osd.h osd_ops.h osd.o
|
osd: $(BLOCKSTORE_OBJS) osd_main.cpp osd.h osd_ops.h osd.o
|
||||||
g++ $(CXXFLAGS) -ltcmalloc_minimal -luring -o osd osd_main.cpp osd.o $(BLOCKSTORE_OBJS)
|
g++ $(CXXFLAGS) -ltcmalloc_minimal -luring -o osd osd_main.cpp osd.o $(BLOCKSTORE_OBJS)
|
||||||
|
|
51
blockstore.h
51
blockstore.h
|
@ -10,6 +10,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include "object_id.h"
|
||||||
#include "ringloop.h"
|
#include "ringloop.h"
|
||||||
|
|
||||||
// Default block size is 128 KB, current allowed range is 4K - 128M
|
// Default block size is 128 KB, current allowed range is 4K - 128M
|
||||||
|
@ -18,56 +19,6 @@
|
||||||
#define MAX_BLOCK_SIZE 128*1024*1024
|
#define MAX_BLOCK_SIZE 128*1024*1024
|
||||||
#define DISK_ALIGNMENT 512
|
#define DISK_ALIGNMENT 512
|
||||||
|
|
||||||
// 16 bytes per object/stripe id
|
|
||||||
// stripe includes replica number in 4 least significant bits
|
|
||||||
struct __attribute__((__packed__)) object_id
|
|
||||||
{
|
|
||||||
uint64_t inode;
|
|
||||||
uint64_t stripe;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator == (const object_id & a, const object_id & b)
|
|
||||||
{
|
|
||||||
return a.inode == b.inode && a.stripe == b.stripe;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator != (const object_id & a, const object_id & b)
|
|
||||||
{
|
|
||||||
return a.inode != b.inode || a.stripe != b.stripe;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator < (const object_id & a, const object_id & b)
|
|
||||||
{
|
|
||||||
return a.inode < b.inode || a.inode == b.inode && a.stripe < b.stripe;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 56 = 24 + 32 bytes per dirty entry in memory (obj_ver_id => dirty_entry)
|
|
||||||
struct __attribute__((__packed__)) obj_ver_id
|
|
||||||
{
|
|
||||||
object_id oid;
|
|
||||||
uint64_t version;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool operator < (const obj_ver_id & a, const obj_ver_id & b)
|
|
||||||
{
|
|
||||||
return a.oid < b.oid || a.oid == b.oid && a.version < b.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace std
|
|
||||||
{
|
|
||||||
template<> struct hash<object_id>
|
|
||||||
{
|
|
||||||
inline size_t operator()(const object_id &s) const
|
|
||||||
{
|
|
||||||
size_t seed = 0;
|
|
||||||
// Copy-pasted from spp::hash_combine()
|
|
||||||
seed ^= (s.inode + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
|
|
||||||
seed ^= (s.stripe + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#define OP_READ 1
|
#define OP_READ 1
|
||||||
#define OP_WRITE 2
|
#define OP_WRITE 2
|
||||||
#define OP_SYNC 3
|
#define OP_SYNC 3
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// 16 bytes per object/stripe id
|
||||||
|
// stripe includes replica number in 4 least significant bits
|
||||||
|
struct __attribute__((__packed__)) object_id
|
||||||
|
{
|
||||||
|
uint64_t inode;
|
||||||
|
uint64_t stripe;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator == (const object_id & a, const object_id & b)
|
||||||
|
{
|
||||||
|
return a.inode == b.inode && a.stripe == b.stripe;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator != (const object_id & a, const object_id & b)
|
||||||
|
{
|
||||||
|
return a.inode != b.inode || a.stripe != b.stripe;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator < (const object_id & a, const object_id & b)
|
||||||
|
{
|
||||||
|
return a.inode < b.inode || a.inode == b.inode && a.stripe < b.stripe;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 56 = 24 + 32 bytes per dirty entry in memory (obj_ver_id => dirty_entry)
|
||||||
|
struct __attribute__((__packed__)) obj_ver_id
|
||||||
|
{
|
||||||
|
object_id oid;
|
||||||
|
uint64_t version;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool operator < (const obj_ver_id & a, const obj_ver_id & b)
|
||||||
|
{
|
||||||
|
return a.oid < b.oid || a.oid == b.oid && a.version < b.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template<> struct hash<object_id>
|
||||||
|
{
|
||||||
|
inline size_t operator()(const object_id &s) const
|
||||||
|
{
|
||||||
|
size_t seed = 0;
|
||||||
|
// Copy-pasted from spp::hash_combine()
|
||||||
|
seed ^= (s.inode + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
|
||||||
|
seed ^= (s.stripe + 0xc6a4a7935bd1e995 + (seed << 6) + (seed >> 2));
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
1
osd.h
1
osd.h
|
@ -12,6 +12,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
|
#include "blockstore.h"
|
||||||
#include "ringloop.h"
|
#include "ringloop.h"
|
||||||
#include "osd_ops.h"
|
#include "osd_ops.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue