7 #ifndef CVMFS_COMPAT_H_
8 #define CVMFS_COMPAT_H_
10 #include <google/sparse_hash_map>
43 template<
unsigned digest_size_, Algorithms algorithm_>
55 memset(
digest, 0, digest_size_);
59 const unsigned char *digest_buffer,
const unsigned buffer_size)
62 assert(buffer_size <= digest_size_);
63 memcpy(
digest, digest_buffer, buffer_size);
68 std::string result(string_length, 0);
72 char dgt1 = (unsigned)
digest[i] / 16;
73 char dgt2 = (unsigned)
digest[i] % 16;
74 dgt1 += (dgt1 <= 9) ?
'0' :
'a' - 10;
75 dgt2 += (dgt2 <= 9) ?
'0' :
'a' - 10;
104 return !(*
this == other);
107 bool operator <(const Digest<digest_size_, algorithm_> &other)
const {
109 return (this->
algorithm < other.algorithm);
111 if (this->
digest[i] > other.digest[i])
113 if (this->
digest[i] < other.digest[i])
134 Md5(
const char *chars,
const unsigned length);
171 template<
unsigned digest_size_, Algorithms algorithm_>
185 memset(
digest, 0, digest_size_);
189 const unsigned char *digest_buffer,
const unsigned buffer_size,
193 assert(buffer_size <= digest_size_);
194 memcpy(
digest, digest_buffer, buffer_size);
210 namespace inode_tracker {
227 typedef google::sparse_hash_map<uint64_t,
Dirent,
234 bool Add(
const uint64_t inode,
const uint64_t parent_inode,
237 assert(
false);
return false;
239 bool Get(
const uint64_t inode,
const uint64_t parent_inode,
242 assert(
false);
return false;
244 uint32_t
Put(
const uint64_t inode,
const uint32_t by) {
245 assert(
false);
return false;
249 return map_.find(inode) !=
map_.end();
283 bool VfsGet(
const uint64_t inode,
const uint64_t parent_inode,
286 assert(
false);
return false;
288 bool VfsAdd(
const uint64_t inode,
const uint64_t parent_inode,
291 assert(
false);
return false;
293 void VfsPut(
const uint64_t inode,
const uint32_t by) {
assert(
false); }
322 namespace inode_tracker_v2 {
324 template<
class Key,
class Value,
class Derived>
336 void Init(uint32_t expected_size, Key empty,
337 uint32_t (*hasher)(
const Key &key))
341 bool Lookup(
const Key &key, Value *value)
const {
344 const bool found =
DoLookup(key, &bucket, &collisions);
352 const bool found =
DoLookup(key, &bucket, &collisions);
355 void Insert(
const Key &key,
const Value &value) {
365 uint32_t *max_collisions)
const
373 double((uint32_t)(-1)));
378 const bool count_collisions)
382 bool DoLookup(
const Key &key, uint32_t *bucket, uint32_t *collisions)
const {
386 if (
keys_[*bucket] == key)
415 template<
class Key,
class Value>
417 public SmallHashBase< Key, Value, SmallHashDynamic<Key, Value> >
469 bool found =
map_.Lookup(md5path, &value);
477 if (found)
return value.
inode;
524 bool Get(
const uint64_t inode,
const uint32_t by) {
527 bool Put(
const uint64_t inode,
const uint32_t by) {
553 pthread_mutex_destroy(
lock_);
563 void VfsPut(
const uint64_t inode,
const uint32_t by) {
608 namespace inode_tracker_v3 {
616 return sizeof(uint16_t) + length;
618 char *
data()
const {
return reinterpret_cast<char *
>(
length_ + 1); }
635 for (
unsigned i = 0; i <
bins_.
size(); ++i) {
673 bool retval =
map_.Lookup(md5path, &info);
754 bool Get(
const uint64_t inode,
const uint32_t by) {
757 bool Put(
const uint64_t inode,
const uint32_t by) {
783 pthread_mutex_destroy(
lock_);
793 void VfsPut(
const uint64_t inode,
const uint32_t by) {
838 namespace chunk_tables {
897 namespace chunk_tables_v2 {
956 namespace chunk_tables_v3 {
989 #endif // CVMFS_COMPAT_H_
void CopyFrom(const ChunkTables &other)
SmallHashDynamic< shash_v1::Md5, PathInfo > map_
void Insert(const uint64_t inode, const shash_v1::Md5 &md5path)
google::sparse_hash_map< uint64_t, Dirent, hash_murmur< uint64_t > > InodeMap
void RemoveString(const StringRef str_ref)
void GetCollisionStats(uint64_t *num_collisions, uint32_t *max_collisions) const
SmallHashDynamic< uint64_t, shash_v1::Md5 > map_
SmallHashDynamic< uint64_t, FileChunkReflist > inode2chunks
uint32_t Put(const uint64_t inode, const uint32_t by)
atomic_int64 num_hits_path
SmallHashDynamic< uint64_t, FileChunkReflist > inode2chunks
Item At(const size_t index) const
static const double kThresholdShrink
bool Lookup(const Key &key, Value *value) const
SmallHashDynamic< uint64_t,::ChunkFd > handle2fd
void Migrate(ChunkTables *old_tables,::ChunkTables *new_tables)
uint32_t capacity() const
unsigned GetDigestSize() const
SmallHashDynamic< shash_v1::Md5, PathInfo > map_
static const double kLoadFactor
void Assign(const char *chars, const unsigned length)
BigVector< FileChunk > * list
InodeTracker(const InodeTracker &other)
const unsigned kAlgorithmIdSizes[]
void Insert(const shash_v1::Md5 &md5path, const PathString &path)
const unsigned kMaxDigestSize
bool Get(const uint64_t inode, const uint32_t by)
bool Contains(const uint64_t inode)
uint64_t LookupInode(const PathString &path)
void DoClear(const bool reset_capacity)
atomic_int64 num_references
std::string ToString() const
const unsigned kDigestSizes[]
uint32_t(* hasher_)(const Key &key)
ChunkTables(const ChunkTables &other)
atomic_int64 num_dangling_try
unsigned GetHexSize() const
uint32_t threshold_shrink_
static StringRef Place(const uint16_t length, const char *str, void *addr)
StringHeap(const uint32_t minimum_size)
shash_v1::Md5 Insert(const PathString &path, const uint64_t inode)
void Erase(const shash_v1::Md5 &md5path)
unsigned GetHexSize() const
Statistics GetStatistics()
assert((mem||(size==0))&&"Out Of Memory")
static const unsigned kNumHandleLocks
void VfsPut(const uint64_t inode, const uint32_t by)
atomic_int64 num_references
SmallHashDynamic(const SmallHashDynamic< Key, Value > &other)
Digest(const Algorithms a, const unsigned char *digest_buffer, const unsigned buffer_size)
void VfsGetBy(const uint64_t inode, const uint32_t by, const PathString &path)
bool LookupPath(const shash_v1::Md5 &md5path, PathString *path)
SmallHashDynamic< uint64_t,::ChunkFd > handle2fd
unsigned char digest[digest_size_]
StringHeap * string_heap_
bool ConstructPath(const uint64_t inode, PathString *path)
Dirent(const uint64_t p, const NameString &n)
const unsigned kMaxDigestSize
uint64_t FindInode(const PathString &path)
void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker)
static const double kThresholdGrow
uint32_t ScaleHash(const Key &key) const
SmallHashDynamic< shash_v1::Md5, uint64_t > map_
ChunkTables & operator=(const ChunkTables &other)
static const unsigned kVersion
SmallHashDynamic< uint64_t, uint32_t > map_
atomic_int64 num_ancient_hits
BigVector< FileChunk > * list
bool LookupMd5Path(const uint64_t inode, shash_v1::Md5 *md5path)
bool LookupMd5Path(const uint64_t inode, shash_v1::Md5 *md5path)
atomic_int64 num_misses_path
bool Get(const uint64_t inode, const uint64_t parent_inode, const NameString &name)
atomic_int64 num_double_add
void CopyFrom(const ChunkTables &other)
bool operator>(const Digest< digest_size_, algorithm_ > &other) const
bool operator==(const Digest< digest_size_, algorithm_ > &other) const
InodeReferences inode_references_
const unsigned kMaxSuffixLength
uint32_t initial_capacity_
static const unsigned kVersion
InodeTracker(const InodeTracker &other)
const unsigned kDigestSizes[]
static uint16_t size(const uint16_t length)
bool FindPath(const uint64_t inode, PathString *path)
const shash_v1::Any & content_hash() const
bool Put(const uint64_t inode, const uint32_t by)
InodeTracker(const InodeTracker &other)
pthread_mutex_t * Handle2Lock(const uint64_t handle) const
FileChunkReflist(BigVector< FileChunk > *l, const PathString &p)
ChunkTables(const ChunkTables &other)
BigVector< void * > bins_
ChunkTables(const ChunkTables &other)
const unsigned kMaxAlgorithmIdentifierSize
BigVector< pthread_mutex_t * > handle_locks
InodeTracker & operator=(const InodeTracker &other)
bool DoLookup(const Key &key, uint32_t *bucket, uint32_t *collisions) const
BigVector< pthread_mutex_t * > handle_locks
void Erase(const shash_v1::Md5 &md5path)
const char kSuffixHistory
shash_v2::Any content_hash_
content hash of the compressed file chunk
SmallHashDynamic< uint64_t, uint32_t > inode2references
void Init(uint32_t expected_size, Key empty, uint32_t(*hasher)(const Key &key))
void Insert(const Key &key, const Value &value)
static const unsigned kNumHandleLocks
bool Lookup(const shash_v1::Md5 &md5path, PathString *path)
SmallHashDynamic< uint64_t, shash_v1::Md5 > map_
static const double kThresholdShrink
bool LookupPath(const shash_v1::Md5 &md5path, PathString *path)
uint64_t bytes_allocated() const
void Init(const uint32_t minimum_size)
void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker)
SmallHashDynamic< uint64_t, uint32_t > inode2references
void MigrateAny(const Any *old_hash, shash::Any *new_hash)
void VfsPut(const uint64_t inode, const uint32_t by)
pthread_mutex_t * Handle2Lock(const uint64_t handle) const
size_t size_
uncompressed size of the data chunk
bool VfsAdd(const uint64_t inode, const uint64_t parent_inode, const NameString &name)
void Append(const char *chars, const unsigned length)
void VfsPut(const uint64_t inode, const uint32_t by)
const char kSuffixMicroCatalog
PathStore & operator=(const PathStore &other)
static const unsigned kNumHandleLocks
size_t size_
uncompressed size of the data chunk
void CopyFrom(const ChunkTables &other)
void Migrate(const uint32_t new_capacity)
SmallHashDynamic< uint64_t, uint32_t > map_
const shash_v2::Any & content_hash() const
SmallHashDynamic< Key, Value > & operator=(const SmallHashDynamic< Key, Value > &other)
StringRef AddString(const uint16_t length, const char *str)
InodeTracker & operator=(const InodeTracker &other)
const char * kAlgorithmIds[]
static const unsigned kVersion
void Erase(const uint64_t inode)
ChunkTables & operator=(const ChunkTables &other)
InodeReferences inode_references_
Digest(const Algorithms a, const unsigned char *digest_buffer, const unsigned buffer_size, const Suffix s=kSuffixNone)
shash_v1::Any content_hash_
content hash of the compressed file chunk
void Insert(const uint64_t inode, const shash_v1::Md5 &md5path)
PathStore(const PathStore &other)
Statistics GetStatistics()
shash_v1::Md5 Insert(const PathString &path, const uint64_t inode)
atomic_int64 num_hits_path
void Migrate(ChunkTables *old_tables,::ChunkTables *new_tables)
void VfsGetBy(const uint64_t inode, const uint32_t by, const PathString &path)
void Erase(const shash_v1::Md5 &md5path)
SmallHashDynamic< uint64_t, uint32_t > inode2references
bool Put(const uint64_t inode, const uint32_t by)
uint64_t bytes_allocated_
void VfsGet(const uint64_t inode, const PathString &path)
void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker)
const char kSuffixPartial
atomic_int64 num_hits_inode
bool Add(const uint64_t inode, const uint64_t parent_inode, const NameString &name)
FileChunkReflist(BigVector< FileChunk > *l, const PathString &p)
BigVector< pthread_mutex_t * > handle_locks
static const double kThresholdGrow
bool FindPath(const uint64_t inode, PathString *path)
unsigned GetDigestSize() const
pthread_mutex_t * Handle2Lock(const uint64_t handle) const
bool DoInsert(const Key &key, const Value &value, const bool count_collisions)
void CopyFrom(const PathStore &other)
bool Get(const uint64_t inode, const uint32_t by)
SmallHashDynamic< uint64_t,::ChunkFd > handle2fd
void MigrateAny(const Any *old_hash, shash::Any *new_hash)
atomic_int64 num_references
void Erase(const uint64_t inode)
off_t offset_
byte offset in the uncompressed input file
atomic_int64 num_hits_inode
InodeContainer inode2path_
atomic_int64 num_ancient_misses
bool Contains(const Key &key) const
uint64_t FindInode(const PathString &path)
InodeTracker & operator=(const InodeTracker &other)
FileChunk(const shash_v1::Any &hash, const off_t offset, const size_t size)
unsigned GetLength() const
atomic_int64 num_misses_path
FileChunk(const shash_v2::Any &hash, const off_t offset, const size_t size)
bool Lookup(const Key &key, Value *value) const
void CopyFrom(const SmallHashDynamic< Key, Value > &other)
bool operator!=(const Digest< digest_size_, algorithm_ > &other) const
SmallHashBase< Key, Value, SmallHashDynamic< Key, Value > > Base
off_t offset_
byte offset in the uncompressed input file
bool VfsGet(const uint64_t inode, const uint64_t parent_inode, const NameString &name)
const char kSuffixCatalog
const unsigned kSuffixLengths[]
const char * GetChars() const
void CopyFrom(const InodeTracker &other)
const char kSuffixTemporary
ChunkTables & operator=(const ChunkTables &other)
void Erase(const Key &key)
void CopyFrom(const InodeTracker &other)
bool Find(const uint64_t inode, PathString *path)
SmallHashDynamic< uint64_t, FileChunkReflist > inode2chunks
uint32_t num_migrates() const
void VfsGet(const uint64_t inode, const PathString &path)
void Migrate(ChunkTables *old_tables,::ChunkTables *new_tables)
void AddBin(const uint64_t size)
Statistics GetStatistics()
void CopyFrom(const InodeTracker &other)
PathInfo(const uint64_t i, const PathString &p)
const char kSuffixCertificate
unsigned char digest[digest_size_]
uint64_t LookupInode(const PathString &path)
static double GetEntrySize()